feat: add Google Vertex AI as a first-class Claude provider - #6491
feat: add Google Vertex AI as a first-class Claude provider#6491elbertwang wants to merge 1 commit into
Conversation
Add support for running Claude models on Google Vertex AI, using the
Anthropic Python SDK's `AnthropicVertex` client which shares the same
`.messages.create()` / `.messages.stream()` interface as the regular
`Anthropic` client — making it a near drop-in replacement.
Configuration is fully compatible with Claude Code's Vertex AI setup:
export CLAUDE_CODE_USE_VERTEX=1
export ANTHROPIC_VERTEX_PROJECT_ID=<project-id>
export CLOUD_ML_REGION=us-east5 # or "global"
Key changes:
- `agent/anthropic_adapter.py`: new `build_vertex_client()` function
- `hermes_cli/auth.py`: register `vertex` provider with `gcloud_adc`
auth type, aliases, and auto-detection via CLAUDE_CODE_USE_VERTEX
- `hermes_cli/providers.py`: HermesOverlay, aliases, display label
- `hermes_cli/runtime_provider.py`: vertex resolution (skips credential
pooling since Vertex uses Google ADC)
- `hermes_cli/main.py`: add Vertex AI to the top-level provider menu
in `hermes model` / `hermes setup` with interactive project/region
configuration
- `run_agent.py`: vertex-aware client construction in AIAgent init,
switch_model, error recovery, and fallback paths via new
`_build_anthropic_client_for_provider()` helper
- `cli.py`: skip api_key/base_url validation for vertex provider;
pass project_id/region through to AIAgent
- `gateway/run.py`: forward project_id/region in runtime kwargs
- `agent/auxiliary_client.py`: `_try_vertex()` for sub-tasks
- `agent/model_metadata.py`: add vertex to provider prefixes
- `agent/models_dev.py`: map vertex → anthropic in models.dev registry
- `pyproject.toml`: `anthropic` → `anthropic[vertex]` (adds google-auth)
Tests: 16 new tests (6 client + 10 provider), 192 total passing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Likely duplicate of #3569 |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the Claude-on-Vertex implementation. The requested Claude behavior remains absent on current main, but this April branch predates the established Vertex/Gemini provider and needs a targeted salvage.
Problems
- Current main already maps
vertexandvertex-aito Gemini's OpenAI-compatiblechat_completionsroute athermes_cli/runtime_provider.py:1573-1604. This PR instead unconditionally routesvertextoanthropic_messagesathermes_cli/runtime_provider.py:754-772, so it would replace Gemini rather than add a Claude path. - The Vertex fallback block at
run_agent.py:4957cannot run: the preceding mode selection only marks Anthropic or/anthropicendpoints asanthropic_messages(run_agent.py:4938-4955). hermes_cli/main.py:2655-2660writes project, region, and an enable flag to.env; current main places non-secret Vertex routing settings invertex:config (hermes_cli/config.py:3287-3303).
Suggested changes
- Add model-based dual routing within the existing
vertexprovider, preserving the Gemini route and choosing AnthropicVertex for Claude IDs. - Reuse the current config/profile-safe credential path and add Gemini-regression plus Vertex-fallback coverage.
This is an automated hermes-sweeper review.
| } | ||
|
|
||
| # Google Vertex AI (Claude via Anthropic Messages API) | ||
| if provider == "vertex": |
There was a problem hiding this comment.
Current main already uses vertex/vertex-ai for Gemini through the OAuth2 OpenAI-compatible path. This unconditional route must become model-based so Claude selects AnthropicVertex without replacing the existing Gemini behavior.
| self._anthropic_base_url = fb_base_url | ||
| self._anthropic_client = build_anthropic_client(effective_key, self._anthropic_base_url) | ||
| self._is_anthropic_oauth = _is_oauth_token(effective_key) | ||
| if fb_provider == "vertex": |
There was a problem hiding this comment.
This branch is unreachable for a Vertex fallback: above, fb_api_mode becomes anthropic_messages only for anthropic or a base URL ending in /anthropic; Vertex falls through as chat_completions and never enters this block.
| region = new_region or default_region | ||
|
|
||
| # Save env values | ||
| save_env_value("ANTHROPIC_VERTEX_PROJECT_ID", project_id) |
There was a problem hiding this comment.
Project ID and region are non-secret routing settings. Persist them under the existing vertex: config section rather than .env, matching the repository configuration policy and current Vertex provider.
Add native support for running Claude models on Google Vertex AI using
Anthropic's AnthropicVertex SDK adapter. The provider is named 'vertex'
(following the Bedrock pattern) with model-based routing: Claude models
use the AnthropicVertex SDK for full feature parity (prompt caching,
thinking budgets), while non-Claude models raise a clear error noting
that Gemini/other model support is planned.
Configuration uses Google Application Default Credentials (ADC):
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global # optional, defaults to 'global'
gcloud auth application-default login
Provider registration:
- plugins/model-providers/vertex/ — ProviderProfile with gcp_adc auth
- hermes_cli/auth.py — ProviderConfig, auth status, credential resolver
- hermes_cli/runtime_provider.py — model-based routing with
_is_anthropic_vertex_model() (mirrors is_anthropic_bedrock_model)
- hermes_cli/models.py — ProviderEntry, aliases, static model catalog
- hermes_cli/main.py + model_setup_flows.py — 'hermes model' wizard
Runtime wiring:
- agent/anthropic_adapter.py — build_anthropic_vertex_client()
- agent/agent_init.py — Vertex client construction branch
- run_agent.py — _rebuild_anthropic_client Vertex dispatch
- agent/agent_runtime_helpers.py — runtime recovery + switch_model
- agent/chat_completion_helpers.py — fallback activation
- agent/auxiliary_client.py — vision backend + auxiliary resolution
Dependencies:
- pyproject.toml — anthropic-vertex optional extra
- tools/lazy_deps.py — lazy install entry
Tests: 7 new tests covering adapter, runtime resolution, client init.
Docs: vertex-ai.md guide + providers table entry.
Aliases: google-vertex, gcp-vertex, vertex-ai, vertex-anthropic.
Closes NousResearch#13484, closes NousResearch#12639.
Related: NousResearch#3569, NousResearch#6491 (prior attempts, smaller scope).
Add support for running Claude models on Google Vertex AI, using the Anthropic Python SDK's
AnthropicVertexclient which shares the same.messages.create()/.messages.stream()interface as the regularAnthropicclient — making it a near drop-in replacement.Configuration is fully compatible with Claude Code's Vertex AI setup:
Key changes:
agent/anthropic_adapter.py: newbuild_vertex_client()functionhermes_cli/auth.py: registervertexprovider withgcloud_adcauth type, aliases, and auto-detection via CLAUDE_CODE_USE_VERTEXhermes_cli/providers.py: HermesOverlay, aliases, display labelhermes_cli/runtime_provider.py: vertex resolution (skips credential pooling since Vertex uses Google ADC)hermes_cli/main.py: add Vertex AI to the top-level provider menu inhermes model/hermes setupwith interactive project/region configurationrun_agent.py: vertex-aware client construction in AIAgent init, switch_model, error recovery, and fallback paths via new_build_anthropic_client_for_provider()helpercli.py: skip api_key/base_url validation for vertex provider; pass project_id/region through to AIAgentgateway/run.py: forward project_id/region in runtime kwargsagent/auxiliary_client.py:_try_vertex()for sub-tasksagent/model_metadata.py: add vertex to provider prefixesagent/models_dev.py: map vertex → anthropic in models.dev registrypyproject.toml:anthropic→anthropic[vertex](adds google-auth)Tests: 16 new tests (6 client + 10 provider), 192 total passing.
What does this PR do?
Related Issue
Fixes #
Type of Change
Changes Made
How to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
hermes --toolsets skills -q "Use the X skill to do Y"Screenshots / Logs