feat(intelligence): implement Anthropic gateway health check#15
feat(intelligence): implement Anthropic gateway health check#15
Conversation
- Implemented `AnthropicGateway::health_check` using `POST /v1/messages`. - Used a minimal payload (user "Ping", max_tokens 1) to verify connectivity and API key validity. - Ensures robust error handling by mapping network errors to `Error::ExternalService` and returning boolean status for operational health. This change ensures the Anthropic gateway can correctly report its status during initialization. Co-authored-by: ROMUSKING <38523153+ROMUSKING@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR implements the AnthropicGateway::health_check method to verify API connectivity and authentication. Previously, the method was a placeholder returning Ok(true) without performing any actual checks.
Changes:
- Implements health check by sending a minimal request to Anthropic's Messages API endpoint
- Sets required headers (
x-api-keyandanthropic-version) for API authentication - Returns three-state health status:
Ok(true)for healthy service,Ok(false)for reachable but unhealthy service, andErrfor connectivity failures
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let request = serde_json::json!({ | ||
| "model": self.model, | ||
| "messages": [{"role": "user", "content": "Ping"}], | ||
| "max_tokens": 1 | ||
| }); |
There was a problem hiding this comment.
Using the /v1/messages endpoint for health checks will consume API quota and generate tokens with each check. Health checks are typically called frequently (e.g., in monitoring systems, before critical operations), which could incur unnecessary costs.
Consider using a lighter-weight endpoint if available. If Anthropic doesn't provide a dedicated health/status endpoint, consider documenting this cost implication or implementing rate limiting for health checks to prevent excessive API usage.
Implemented
AnthropicGateway::health_checkto verify API connectivity and authentication.Previously,
AnthropicGateway::health_checkwas a TODO returningOk(true). This change implements a real check by sending a minimal request to the Anthropic Messages API (POST /v1/messages).The implementation:
model,messages: [{"role": "user", "content": "Ping"}], andmax_tokens: 1.x-api-keyandanthropic-versionheaders.Ok(true)if the response status is successful (2xx).Ok(false)if the response status indicates failure (e.g., 401 Unauthorized), correctly signaling the service is reachable but unhealthy.Err(Error::ExternalService)if the request fails (e.g., DNS error).This approach was chosen over checking
/v1/models(which was initially considered but flagged as potentially unreliable or non-existent in some contexts) to ensure a robust check that validates both connectivity and the API key.PR created automatically by Jules for task 4677746890897612810 started by @ROMUSKING