( ctx context.Context, httpClient *http.Client, method string, url string, headers map[string]string, body []byte, )
| 948 | case "usage": |
| 949 | response.InputTokens = getInt(event, "input_tokens") |
| 950 | response.CacheReadInputTokens = getInt(event, "cache_read_input_tokens") |
| 951 | response.CacheCreationInputTokens = getInt(event, "cache_creation_input_tokens") |
| 952 | response.OutputTokens = getInt(event, "output_tokens") |
| 953 | case "stop_reason": |
| 954 | response.StopReason = getString(event, "stop_reason") |
| 955 | case "error": |
| 956 | return Response{}, completionStreamError(event) |
| 957 | } |
| 958 | } |
| 959 | response.Text = text.String() |
| 960 | return response, nil |
| 961 | } |
| 962 | |
| 963 | func completionStreamError(event map[string]any) error { |
| 964 | message := strings.TrimSpace(getString(event, "message")) |
| 965 | if message == "" { |
| 966 | message = "streaming completion failed" |
| 967 | } |
| 968 | statusCode := getInt(event, "status_code") |
| 969 | if statusCode > 0 { |
| 970 | statusErr := NewAPIStatusError(getString(event, "provider"), statusCode, |
| 971 | getString(event, "status"), []byte(getString(event, "raw_error"))) |
no test coverage detected