feat: OpenAI-to-Anthropic bridge for Claude models via /v1/chat/completions#8
Merged
Merged
Conversation
…validation Add model aliases for recently released Claude models: - Claude Opus 4.6, 4.7, 4.8 (no @Date suffix) - Claude Sonnet 4.6 (no @Date suffix) - Claude Sonnet 4 (claude-sonnet-4-20250514) Fix model validation in _handle_anthropic(): the previous check `if "@" not in vertex_model` rejects models without a @Date suffix. Replace with a lookup against known aliases so both formats work.
OpenAI-compatible clients expect 'created' and 'owned_by' fields in model listings. Set owned_by to the actual provider (anthropic, google, or the MaaS publisher name).
Clients that set base_url to /anthropic or /gemini now get model listings from their respective prefix: GET /anthropic/v1/models → anthropic models only GET /gemini/v1/models → gemini models only GET /gemini/v1beta/models → gemini models only This fixes Hermes showing '0 models' for vertex-anthropic provider.
…etions Add translation layer so OpenAI Chat Completions clients can call Claude models through the /v1 endpoint. Requests are converted to Anthropic Messages format, sent to Vertex AI, and responses translated back to OpenAI format. Supports both streaming (SSE) and non-streaming modes. New module: openai_anthropic_bridge.py handles all format conversions.
71bd493 to
ccd7c45
Compare
Owner
|
Thanks a lot for these, @gnodet - really appreciate it. Merged, with a few maintainer follow-ups on top: corrected the Vertex model IDs (the 4.6-gen ones are dateless, and I fixed a couple of pre-existing @Date mistakes on Opus/Haiku 4.5 that were 404'ing), dropped Sonnet 4 since it retires on the 15th, mapped Claude tool_use back to OpenAI tool_calls on the response side, and added tests + README/CHANGELOG. Your commits are on main with author + co-author credit. Thanks again! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a translation layer that allows OpenAI Chat Completions clients to call Claude models through the
/v1/chat/completionsendpoint. Requests are automatically converted from OpenAI format to Anthropic Messages format, routed to Vertex AI, and responses are translated back to OpenAI format.Motivation
Many tools and frameworks only support the OpenAI Chat Completions API format (e.g. LangChain, AutoGen, Cursor, Continue, various AI coding assistants). This bridge lets them use Claude models on Vertex AI without any client-side changes — just point them at
http://proxy:8787/v1and request a Claude model name.Previously, Claude was only accessible via the
/anthropicendpoint using Anthropic-native message format. Now both paths work:/anthropic/v1/messages— native Anthropic format (unchanged)/v1/chat/completions— OpenAI format with automatic translationHow it works
When
/v1/chat/completionsreceives a request for a Claude model:Request translation (
openai_to_anthropic_body):systemfieldtoolrole messages to Anthropictool_resultblocksmax_tokens/max_completion_tokens,stop→stop_sequences, etc.Routing: Calls Vertex AI Anthropic endpoint (
rawPredict/streamRawPredict)Response translation (
anthropic_to_openai_response):choices[].message.contentstop_reason→finish_reasoninput_tokens/output_tokens→prompt_tokens/completion_tokensStreaming: SSE events are translated line-by-line from Anthropic format to OpenAI format
New files
vertex_proxy/openai_anthropic_bridge.py— all format conversion functions (pure, stateless, well-separated)Testing
Tested with:
openaiclient (streaming + non-streaming)curlwith SSE streamingAll Claude model aliases work through both the
/anthropicand/v1endpoints.