doAnthropicRequest is the Anthropic counterpart of doOpenAIRequest. applyAuthHeader sets x-api-key and anthropic-version when provider is anthropic, so this method doesn't need to duplicate that.
(ctx context.Context, cfg *proxyConfig, body []byte)
| 338 | // applyAuthHeader sets x-api-key and anthropic-version when provider |
| 339 | // is anthropic, so this method doesn't need to duplicate that. |
| 340 | func (c *CloudProxy) doAnthropicRequest(ctx context.Context, cfg *proxyConfig, body []byte) (*http.Response, error) { |
| 341 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.upstreamURL, bytes.NewReader(body)) |
| 342 | if err != nil { |
| 343 | return nil, fmt.Errorf("cloud-proxy: build request: %w", err) |
| 344 | } |
| 345 | req.Header.Set("Content-Type", "application/json") |
| 346 | req.Header.Set("Accept", "*/*") |
| 347 | if cfg.apiKey != "" { |
| 348 | applyAuthHeader(req, cfg.provider, cfg.apiKey) |
| 349 | } |
| 350 | resp, err := c.client.Do(req) |
| 351 | if err != nil { |
| 352 | return nil, fmt.Errorf("cloud-proxy: upstream request: %w", err) |
| 353 | } |
| 354 | return resp, nil |
| 355 | } |
| 356 | |
| 357 | // predictAnthropicRich returns the full Reply: joined text from all |
| 358 | // text blocks, tool_use blocks mapped to ToolCallDelta, and usage |
no test coverage detected