feat(ai): add Anthropic Vertex provider - #5262
Conversation
c19f328 to
3fe8014
Compare
| options?.project, | ||
| process.env.GOOGLE_CLOUD_PROJECT, | ||
| process.env.GCLOUD_PROJECT, | ||
| process.env.ANTHROPIC_VERTEX_PROJECT_ID, |
There was a problem hiding this comment.
Consider placing ANTHROPIC_VERTEX_PROJECT_ID first in precedence, for users that want both Gemini and Anthropic models via Vertex AI but with different projects.
There was a problem hiding this comment.
Thanks for the feedback, what you propose does make sense, however this precedence order was taken from Anthropic's docs describing the precedence of these env vars Claude Code:
Claude Code uses
ANTHROPIC_VERTEX_PROJECT_IDas the project ID for Vertex AI requests. TheGCLOUD_PROJECTandGOOGLE_CLOUD_PROJECTenvironment variables and the credential file referenced byGOOGLE_APPLICATION_CREDENTIALStake precedence over it. If none of these are set, the project ID is resolved from your gcloud configuration or the attached service account.
Of course, we don't have to follow Claude Code's precedence, but then there's the edge case where users that have both env vars set to different values will get different GCP projects being used between Pi and Claude Code.
|
I also worked on this as it is a gating item preventing Pi from being used at my company. I asked Sonnet to compare the two implementation and this one is strictly better, with the one possible exception being the precedence of ANTHROPIC_VERTEX_PROJECT_ID noted above. I look forward to this PR being approved and merged. |
I also believe sonnet-4-6 is the better default. Sonnet also says:
|
|
I tried testing this PR. I pulled the branch and ran it but I hit the following error: I mainly ran the |
3fe8014 to
ae703df
Compare
|
@kannon92 Good catch, thanks for testing. I had verified this with I’ve pushed a fix that mirrors the existing Bedrock binary shim: the Bun binary now pre-registers Anthropic Vertex instead of resolving the lazy relative import at runtime. I also built the binary and tested it with Vertex, and it appears to work now. Please try again when you get a chance and let me know if you hit any other issues. |
ae703df to
10d7633
Compare
|
I tested the Vertex path locally and the direct one-shot flow works end to end: A couple of things from working through a similar implementation here:
Overall this looks like the right direction 👍 thanks for working on it :) |
|
@drpaneas Thanks for testing and providing feedback! On your points:
|
a470eed to
5ce9163
Compare
|
@badlogic Sorry for the tag, but this PR has been sitting for 3 weeks, with frequent changes to main causing conflicts that require resolving and retesting each time. Would love to move it forward if possible, let me know if you need anything from my side :) |
|
For what it's worth, I stacked this PR on origin/main (0.80.3) with some heavy rebasing and it's chugging along just fine with various anthropic models via vertex AI using creds from a JSON file. 👏 Context windows look right and I'm able to set the thinking modes just as I can in opencode. |
|
@MichaelYochpaz needs another rebase 🙈 @badlogic would be great to have this, then I can drop my extension which copies many of your internals to work properly. Appreciate it 👍 |
…rtex AI Add a built-in anthropic-vertex provider that constructs an AnthropicVertex SDK client and delegates request conversion and streaming to the existing Anthropic Messages implementation. - Use Google Application Default Credentials with scoped project, location, and base URL resolution - Lazy-load the Node-only SDK and embed it in standalone Bun builds - Generate current Vertex Claude models from models.dev with a bounded Fable fallback - Forward per-request fetch injection and use Opus 5 as the provider default - Document setup, ADC behavior, endpoint precedence, and catalog provenance Resolves earendil-works#5082
5ce9163 to
85449f8
Compare
|
I've rebased this onto the latest Changes since the previous version:
The PR should now be ready for review again. |
|
I just gave it a try and seems to work fine for me. Thanks @MichaelYochpaz 👍 |
Summary
Adds a built-in
anthropic-vertexprovider for Claude on Google Cloud Vertex AI.The provider is a thin adapter: it constructs an
AnthropicVertexSDK client, injects it into the existing Anthropic Messages streaming path, and reuses the shared Anthropic request/stream/tool/thinking/error handling.Notes
@anthropic-ai/vertex-sdkis lazy-loaded through the built-in provider registry so root imports do not load the Vertex SDK or its nestedgoogle-auth-library@9.x. For compiled Bun binaries, Anthropic Vertex is pre-registered through a Bun shim, matching the Bedrock pattern, so the binary embeds the provider instead of resolving the lazy relative import at runtime.@YYYYMMDDsnapshot conversion.claude-opus-4-8to align with the default for the Anthropic provider.However, I think
claude-sonnet-4-6should be a better default (for both Anthropic and Vertex providers) as it's cheaper while still very capable, serving as a good default. Happy to switch if agreed.Vertex AI (Gemini)(the same pre-existing vertex provider) andVertex AI (Anthropic)(new addition) so that the two Vertex-backed providers are easier to distinguish.anthropic-messages.tsstill contains an older workaround for Anthropic SDK effort typing.The current SDK type already accepts
"xhigh"and"max"inoutput_config.effort, so the special"xhigh"cast branch could likely be simplified toparams.output_config = { effort: options.effort }.I left that out of this PR to keep the Vertex provider scoped and avoid changes to
anthropic.ts, but it's something that's worth removing on a separate commit / PR.moonshotai/kimi-k2.6:freewas removed upstream) and a corresponding one-line test update.Resolves #5082