Add Anthropic Messages bridge for OpenAI-compatible chat providers - #26
Merged
OnlyTerp merged 4 commits intoJun 8, 2026
Merged
Conversation
…s, add bridge tests - Fix content: None → empty string in _anthropic_assistant_message_to_chat for tool-only assistant messages (some providers reject null content) - Deduplicate _chat_stream_finish_to_anthropic_stop and _anthropic_usage_from_normalized from server.py; import canonical versions from translate.py instead - Add 4 new tests: tool call streaming, reasoning streaming, Anthropic-shaped error responses, and Anthropic pass-through streaming - Add 2 new translate tests: tool-only content and reasoning blocks
…ames - Use uuid4() for Anthropic message_id instead of timestamp (collision risk) - Rewrite model field in pass-through SSE message_start events - Preserve original tool names in _anthropic_tools_to_chat_tools and _anthropic_tool_choice_to_chat (remove _sanitize_tool_name mangling)
eafire15
marked this pull request as ready for review
June 2, 2026 14:35
# Conflicts: # codex_shim/server.py
Samuel86-star
added a commit
to Samuel86-star/codex-shim
that referenced
this pull request
Jun 10, 2026
Upstream's Anthropic Messages bridge PR (sybil-solutions#26) replaced server.py and dropped the [route] diagnostic prints that were added during the smart-vision-routing branch's merge conflict resolution. Re-add them to _post_openai_chat and _post_anthropic. Also fixes a merge regression where the old vision_router _route signature (returning tuple[ShimModel, dict]) leaked back into the merged file, causing two test failures.
jomangbp
pushed a commit
to jomangbp/codex-shim
that referenced
this pull request
Jul 6, 2026
…ybil-solutions#26) * feat: add Anthropic Messages bridge * fix: empty string for tool-only assistant content, deduplicate helpers, add bridge tests - Fix content: None → empty string in _anthropic_assistant_message_to_chat for tool-only assistant messages (some providers reject null content) - Deduplicate _chat_stream_finish_to_anthropic_stop and _anthropic_usage_from_normalized from server.py; import canonical versions from translate.py instead - Add 4 new tests: tool call streaming, reasoning streaming, Anthropic-shaped error responses, and Anthropic pass-through streaming - Add 2 new translate tests: tool-only content and reasoning blocks * fix: uuid message ids, model slug in passthrough SSE, preserve tool names - Use uuid4() for Anthropic message_id instead of timestamp (collision risk) - Rewrite model field in pass-through SSE message_start events - Preserve original tool names in _anthropic_tools_to_chat_tools and _anthropic_tool_choice_to_chat (remove _sanitize_tool_name mangling) --------- Co-authored-by: codex <codex@openai.com> Co-authored-by: test <test@local>
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
This adds an Anthropic Messages bridge for OpenAI-compatible providers:
Why
Some providers, including OpenCode Go, expose useful models across OpenAI-compatible and Anthropic-compatible surfaces. codex-shim already translates Codex Responses requests to both OpenAI-shaped chat completions and Anthropic Messages upstreams. This adds the reverse client-facing side: Anthropic-speaking clients can point at codex-shim and use configured OpenAI-compatible providers.
That makes OpenCode Go integration easier without adding a provider-specific dependency.
Changes
POST /v1/messages.provider: "anthropic"models.Supported bridge surface:
Deferred provider-specific surfaces:
cache_controlModel-assisted revision notes
/v1/messages, Anthropic-to-chat request conversion, chat-to-Anthropic response/stream conversion, pass-through behavior, docs, tests, and live smoke validation.content: nulltocontent: "", deduplicated helper logic, and expanded stream/error tests.Testing
Result:
Local smoke:
127.0.0.1:8786with an OpenAI-compatible upstream route.messagecontent./v1/messagesemits Anthropic SSE ending withmessage_stopand no OpenAI[DONE]sentinel.tool_usewithstop_reason: "tool_use".