feat(ai): add Anthropic Vertex AI provider#1157
feat(ai): add Anthropic Vertex AI provider#1157michaelpersonal wants to merge 3 commits intobadlogic:mainfrom
Conversation
|
Thanks for the PR! The approach looks solid. Few things to address before merge: Must fix:
Code duplication issue: The shared utilities approach was the right call, but Note: Tests: The provider-specific tests look good. Per AGENTS.md, new providers should also be added to Questions:
Also add |
|
Thanks for the thorough review! Answers to your questions:
Addressed feedback:
All 6 provider-specific tests pass. Cross-provider handoff tests pass between |
|
The provider extension works well for this since the api is similar to existing anthropic provider unlike bedrock - Here is something my clanker wrote which i'm using quite sometime - https://github.com/isaacraja/pi-vertex-claude. But yeah in the core is also useful. |
|
Great work @michaelpersonal! I built a similar extension
Happy to fork your PR and add these if you'd like. Let me know! |
- PR_COMMENT.md: Comment posted to badlogic/pi-mono#1157 - FORK_WORKFLOW.md: Guide for forking and contributing - Offering to fork their PR and add OAuth/global region/models - Link to our repo: https://github.com/skyfallsin/pi-vertex-anthropic Comment posted: badlogic/pi-mono#1157 (comment)
|
+1 for this feature! I've tested Claude on Vertex AI (Opus 4.5 & 4.6, global region) locally using @anthropic-ai/vertex-sdk and confirmed it works great with ADC auth. Currently using a local proxy workaround with OpenClaw, but native pi-ai support would be much cleaner. Happy to help test if the conflicts get resolved! 🙏 |
a7d2526 to
bf06172
Compare
Add support for Anthropic Claude models hosted on Google Cloud Vertex AI. - New `anthropic-vertex` API type and provider - New files: - `anthropic-shared.ts`: Shared utilities (mapStopReason, convertTools, etc.) - `anthropic-vertex.ts`: Vertex AI provider using raw fetch + GoogleAuth - `anthropic-vertex.test.ts`: Comprehensive test suite - Registered 4 models: Opus 4.5, Sonnet 4, 3.5 Sonnet v2, 3.5 Haiku - Added `google-auth-library` dependency for Application Default Credentials The Anthropic SDK doesn't support Vertex AI's URL structure: - Direct API: `https://api.anthropic.com/v1/messages` - Vertex AI: `https://{region}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredict` All tests verified with `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION=global`: - ✓ Basic text generation - ✓ Tool calling with streaming - ✓ Streaming events (start, text_delta, done) - ✓ Multi-turn conversation - ✓ Token usage reporting - ✓ Thinking blocks (extended reasoning with Opus 4.5) Additionally tested end-to-end by integrating with Pi coding agent as a custom extension. The provider successfully powered interactive coding sessions using Claude Opus 4.5 via Vertex AI with the global region. This PR was reviewed using quiz-based comprehension verification rather than diff scanning alone. The human reviewer correctly answered 6/6 questions about: runtime behavior, auth failure modes, request body differences, conditional logic, dependency relationships, and edge case handling. Ref: https://michaelguoblog.vercel.app/posts/man-in-the-loop-agent-coding/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add changelog entry under [Unreleased] -> Added - Add anthropic-vertex to getEnvApiKey() ADC detection - Add defaultModelPerProvider entry for anthropic-vertex - Add Anthropic Vertex AI setup docs to providers.md - Refactor anthropic.ts to import shared utils from anthropic-shared.ts (mapStopReason, convertContentBlocks, normalizeToolCallId) - Add optional nameMapper param to shared convertTools() for OAuth compatibility - Add anthropic-vertex to cross-provider-handoff.test.ts - Change default region from us-east5 to global Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Run generate-models to include anthropic-vertex provider model definitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
592e230 to
9b003fb
Compare
|
@badlogic This PR is ready for review. The merge conflict has been resolved and rebased onto main. |
|
+1 for this. Would be great to support different regions and projects, but I know vertex ai is painful, as they keep changing their docs and naming |
|
Sorry, took me a while to get to this. This PR has multiple issues:
I'm afraid I have to close this out. Since this barely reuses anything from anthropic.ts, this is better implemented as an extension. |
understandable, also google keeps changing their SDKs and model names like underwear, so would need a lot of maintenance |
Summary
Add support for Anthropic Claude models hosted on Google Cloud Vertex AI.
anthropic-vertexAPI type and provider using raw fetch + GoogleAuth (ADC)anthropic-shared.tsRelated to #1155
Why a separate provider?
The Anthropic SDK doesn't support Vertex AI's URL structure:
https://api.anthropic.com/v1/messageshttps://{region}-aiplatform.googleapis.com/v1/projects/{project}/locations/{location}/publishers/anthropic/models/{model}:streamRawPredictTest plan
Code review methodology
This PR was reviewed using quiz-based comprehension verification rather than diff scanning alone. The human reviewer correctly answered 6/6 questions covering runtime behavior, auth failure modes, request body differences, conditional logic, dependency relationships, and edge case handling.
🤖 Generated with Claude Code