(&self, request: ChatRequest)
| 164 | } |
| 165 | |
| 166 | async fn chat(&self, request: ChatRequest) -> Result<ChatResponse, ProviderError> { |
| 167 | let anthropic_request = self.convert_request(request); |
| 168 | |
| 169 | let url = self.config.base_url.as_deref().unwrap_or(ANTHROPIC_API_URL); |
| 170 | |
| 171 | let response = self |
| 172 | .client |
| 173 | .post(url) |
| 174 | .header("x-api-key", &self.config.api_key) |
| 175 | .header("anthropic-version", "2023-06-01") |
| 176 | .header("anthropic-beta", "claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14") |
| 177 | .header("content-type", "application/json") |
| 178 | .json(&anthropic_request) |
| 179 | .send() |
| 180 | .await |
| 181 | .map_err(|e| ProviderError::NetworkError(e.to_string()))?; |
| 182 | |
| 183 | if !response.status().is_success() { |
| 184 | let status = response.status(); |
| 185 | let body = response.text().await.unwrap_or_default(); |
| 186 | return Err(ProviderError::ApiError(format!("{}: {}", status, body))); |
| 187 | } |
| 188 | |
| 189 | let anthropic_response: AnthropicResponse = response |
| 190 | .json() |
| 191 | .await |
| 192 | .map_err(|e| ProviderError::ApiError(e.to_string()))?; |
| 193 | |
| 194 | Ok(convert_response(anthropic_response)) |
| 195 | } |
| 196 | |
| 197 | async fn chat_stream(&self, request: ChatRequest) -> Result<StreamResult, ProviderError> { |
| 198 | let mut anthropic_request = self.convert_request(request); |
nothing calls this directly
no test coverage detected