Skip to content

feat: add Vertex AI Anthropic provider for Claude on GCP#5994

Closed
markbooch wants to merge 3 commits intoopenclaw:mainfrom
markbooch:feat/vertex-anthropic-provider
Closed

feat: add Vertex AI Anthropic provider for Claude on GCP#5994
markbooch wants to merge 3 commits intoopenclaw:mainfrom
markbooch:feat/vertex-anthropic-provider

Conversation

@markbooch
Copy link

@markbooch markbooch commented Feb 1, 2026

Summary

Adds support for Claude models hosted on Google Cloud Vertex AI, allowing users to leverage their GCP credits directly without routing through intermediaries like OpenRouter (which charges 5% on all requests).

Motivation

Users with GCP credits want to use Claude models directly on Vertex AI without paying intermediary fees. This PR adds a new vertex-anthropic provider that:

  • Uses gcloud Application Default Credentials for authentication
  • Auto-discovers when GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION are set
  • Provides full feature parity with the direct Anthropic API

Changes

File Description
src/agents/vertex-anthropic-models.ts Model catalog and provider builder
src/agents/vertex-anthropic-models.test.ts Unit tests
src/agents/models-config.providers.ts Import and auto-discovery integration
src/agents/model-auth.ts Add gcloud ADC auth support
src/commands/models/list.status-command.ts Add to env probe list
docs/vertex-anthropic.md Setup and usage documentation
CHANGELOG.md Changelog entry

Usage

# Configure GCP credentials
gcloud auth application-default login
export GOOGLE_CLOUD_PROJECT=my-project
export GOOGLE_CLOUD_LOCATION=us-east5

# Verify
openclaw models list | grep vertex-anthropic

# Use in config
# agents.defaults.model.primary: vertex-anthropic/claude-opus-4-5@20251101

Testing

  • Tested locally on GCP VM with real Vertex AI Claude calls
  • Unit tests for helper functions
  • CI validation pending

AI Disclosure

This PR was developed with AI assistance (Claude). The implementation was tested on a live GCP instance with actual Vertex AI API calls confirming functionality.


cc @steipete

Greptile Overview

Greptile Summary

Adds a new vertex-anthropic model provider that targets Claude models hosted on Google Cloud Vertex AI, including a static model catalog, env-based auto-discovery when GCP project/location are set, and wiring into models list/status so users can see the provider and credential state. Also extends env auth resolution so vertex-anthropic reuses the existing google-vertex gcloud ADC token flow.

Main integration points are provider auto-discovery (src/agents/models-config.providers.ts) and env credential resolution (src/agents/model-auth.ts), with supporting docs and tests for the new helper module.

Confidence Score: 3/5

  • Moderately safe to merge, but a couple auth/discovery edge cases can misreport availability or auth mode.
  • Core changes are additive and well-scoped (new provider module + wiring), but current auto-discovery can enable the provider without real ADC credentials, and env-based auth resolution reports the wrong auth mode for gcloud ADC sources. These are likely to cause confusing UX and some runtime failures for users relying on implicit discovery.
  • src/agents/models-config.providers.ts, src/agents/model-auth.ts, src/agents/vertex-anthropic-models.ts

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Adds support for Claude models hosted on Google Cloud Vertex AI,
allowing users to leverage their GCP credits directly without
routing through intermediaries like OpenRouter.

Features:
- Auto-discovery when GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION are set
- Uses gcloud Application Default Credentials for authentication
- Supports all Claude models available on Vertex AI (Opus, Sonnet, Haiku)
- Full feature parity: streaming, tools, thinking/reasoning, vision

Configuration:
- Set GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION env vars
- Run 'gcloud auth application-default login' for authentication
- Models appear as vertex-anthropic/claude-opus-4-5@20251101 etc.

Files:
- src/agents/vertex-anthropic-models.ts: Model catalog and provider builder
- src/agents/vertex-anthropic-models.test.ts: Unit tests
- src/agents/models-config.providers.ts: Import and auto-discovery
- src/agents/model-auth.ts: Add gcloud ADC auth support
- src/commands/models/list.status-command.ts: Add to env probe list
- docs/vertex-anthropic.md: Setup and usage documentation
- CHANGELOG.md: Add changelog entry
@openclaw-barnacle openclaw-barnacle bot added docs Improvements or additions to documentation commands Command implementations agents Agent runtime and tooling labels Feb 1, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +470 to +477
// Vertex Anthropic provider - auto-discover if GCP credentials are available
const gcpProject = resolveGcpProject();
const gcpLocation = resolveGcpLocation();
if (gcpProject && gcpLocation && hasGcloudAdc()) {
providers["vertex-anthropic"] = {
...buildVertexAnthropicProvider({ project: gcpProject, location: gcpLocation }),
apiKey: "gcloud-adc", // Placeholder; actual auth uses gcloud ADC
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Auto-discovery for vertex-anthropic only triggers when hasGcloudAdc() is true, but hasGcloudAdc currently returns true if GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT are set. Those env vars are not credentials, so this can cause the provider to be auto-added even when no ADC/service account is available, leading to runtime auth failures after the model appears “available”.

Representative occurrence: src/agents/models-config.providers.ts:470-477 (root cause in src/agents/vertex-anthropic-models.ts:181-187).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/models-config.providers.ts
Line: 470:477

Comment:
Auto-discovery for `vertex-anthropic` only triggers when `hasGcloudAdc()` is true, but `hasGcloudAdc` currently returns true if `GOOGLE_CLOUD_PROJECT`/`GCLOUD_PROJECT` are set. Those env vars are not credentials, so this can cause the provider to be auto-added even when no ADC/service account is available, leading to runtime auth failures after the model appears “available”.

Representative occurrence: `src/agents/models-config.providers.ts:470-477` (root cause in `src/agents/vertex-anthropic-models.ts:181-187`).

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +210 to +214
export async function resolveImplicitVertexAnthropicProvider(params: {
agentDir: string;
env?: NodeJS.ProcessEnv;
}): Promise<ProviderConfig | null> {
const env = params.env ?? process.env;
Copy link
Contributor

Choose a reason for hiding this comment

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

resolveImplicitVertexAnthropicProvider is declared async and takes agentDir, but it doesn’t await anything and agentDir is unused. This looks like leftover scaffolding and can be simplified to avoid dead params/API surface area.

Suggested change
export async function resolveImplicitVertexAnthropicProvider(params: {
agentDir: string;
env?: NodeJS.ProcessEnv;
}): Promise<ProviderConfig | null> {
const env = params.env ?? process.env;
export function resolveImplicitVertexAnthropicProvider(params: {
env?: NodeJS.ProcessEnv;
}): ProviderConfig | null {

(Or remove the function entirely if resolveImplicitProviders is the only call site.)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/vertex-anthropic-models.ts
Line: 210:214

Comment:
`resolveImplicitVertexAnthropicProvider` is declared `async` and takes `agentDir`, but it doesn’t await anything and `agentDir` is unused. This looks like leftover scaffolding and can be simplified to avoid dead params/API surface area.

```suggestion
export function resolveImplicitVertexAnthropicProvider(params: {
  env?: NodeJS.ProcessEnv;
}): ProviderConfig | null {
```
(Or remove the function entirely if `resolveImplicitProviders` is the only call site.)

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 1, 2026

Additional Comments (1)

src/agents/model-auth.ts
resolveApiKeyForProvider sets mode based on envResolved.source.includes("OAUTH_TOKEN"), but for vertex-anthropic/google-vertex the env resolver returns source: "gcloud adc". That makes the mode default to "api-key" even though the provider is configured with auth: "token", which can cause confusing status output and potentially incorrect downstream behavior if anything branches on auth.mode.

Also affects google-vertex via the same source: "gcloud adc" path.

Files/lines: src/agents/model-auth.ts:193-200, env source set at src/agents/model-auth.ts:263-277

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/model-auth.ts
Line: 193:200

Comment:
`resolveApiKeyForProvider` sets `mode` based on `envResolved.source.includes("OAUTH_TOKEN")`, but for `vertex-anthropic`/`google-vertex` the env resolver returns `source: "gcloud adc"`. That makes the mode default to `"api-key"` even though the provider is configured with `auth: "token"`, which can cause confusing status output and potentially incorrect downstream behavior if anything branches on `auth.mode`.

Also affects `google-vertex` via the same `source: "gcloud adc"` path.

Files/lines: `src/agents/model-auth.ts:193-200`, env source set at `src/agents/model-auth.ts:263-277`

How can I resolve this? If you propose a fix, please make it concise.

- hasGcloudAdc() now only returns true when GOOGLE_APPLICATION_CREDENTIALS
  is set, not just project env vars (prevents false positive auto-discovery)
- resolveApiKeyForProvider() correctly sets mode='token' for gcloud ADC
  (was defaulting to 'api-key' due to source string mismatch)
- Removed unused async/agentDir from resolveImplicitVertexAnthropicProvider
@markbooch
Copy link
Author

Thanks for the review feedback! Pushed a fix (9583edd) addressing all three issues:

  1. hasGcloudAdc() false positives - Now only returns true when GOOGLE_APPLICATION_CREDENTIALS is set, not just project env vars
  2. auth.mode detection - Fixed to set mode="token" when source is "gcloud adc"
  3. Dead code cleanup - Removed unused async and agentDir param from resolveImplicitVertexAnthropicProvider

- Fix hasGcloudAdc to only check GOOGLE_APPLICATION_CREDENTIALS (actual credentials)
- Remove unused async/agentDir from resolveImplicitVertexAnthropicProvider
- Fix markdown table formatting in docs
@clawdinator
Copy link
Contributor

clawdinator bot commented Feb 1, 2026

CLAWDINATOR FIELD REPORT // PR Closure

I am CLAWDINATOR — cybernetic crustacean, maintainer triage bot for OpenClaw. I was sent from the future to keep this repo shipping clean code.

Context: OpenClaw serves ~1M users. Provider integrations and platform additions are not being accepted without prior discussion. The queue is too large to review unsolicited features.

If this integration is critical for users, open a GitHub issue first to discuss with maintainers.

TERMINATED.

🤖 This is an automated message from CLAWDINATOR, the OpenClaw maintainer bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant