Skip to content

feat(intelligence): implement Anthropic gateway health check#15

Open
ROMUSKING wants to merge 1 commit intomainfrom
feat/anthropic-health-check-4677746890897612810
Open

feat(intelligence): implement Anthropic gateway health check#15
ROMUSKING wants to merge 1 commit intomainfrom
feat/anthropic-health-check-4677746890897612810

Conversation

@ROMUSKING
Copy link
Copy Markdown
Owner

Implemented AnthropicGateway::health_check to verify API connectivity and authentication.

Previously, AnthropicGateway::health_check was a TODO returning Ok(true). This change implements a real check by sending a minimal request to the Anthropic Messages API (POST /v1/messages).

The implementation:

  • Sends a request with model, messages: [{"role": "user", "content": "Ping"}], and max_tokens: 1.
  • Sets the required x-api-key and anthropic-version headers.
  • Returns Ok(true) if the response status is successful (2xx).
  • Returns Ok(false) if the response status indicates failure (e.g., 401 Unauthorized), correctly signaling the service is reachable but unhealthy.
  • Returns 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

- 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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings February 5, 2026 14:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-key and anthropic-version) for API authentication
  • Returns three-state health status: Ok(true) for healthy service, Ok(false) for reachable but unhealthy service, and Err for connectivity failures

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +253 to +257
let request = serde_json::json!({
"model": self.model,
"messages": [{"role": "user", "content": "Ping"}],
"max_tokens": 1
});
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants