fix: route anthropic-messages models to /v1/messages instead of /chat/completions - #19
Open
gitawego wants to merge 1 commit into
Open
fix: route anthropic-messages models to /v1/messages instead of /chat/completions#19gitawego wants to merge 1 commit into
gitawego wants to merge 1 commit into
Conversation
…/completions
The delegate hard-coded the OpenAI-compatible POST {baseUrl}/chat/completions
for every vision model, ignoring the model's registered api type. Models
registered as "anthropic-messages" (e.g. MiniMax M3 at
api.minimaxi.com/anthropic) 404 with "404 page not found" because that
base URL has no /chat/completions route.
Now the request is API-aware:
- api=anthropic-messages -> POST {baseUrl}/v1/messages with the Messages
schema: image as source.base64 blocks, system prompt as a top-level
"system" field, response parsed from content[] text blocks (with a
thinking-block fallback for reasoning-only replies).
- everything else -> unchanged OpenAI /chat/completions path (including
reasoning_effort for reasoning models).
Adds 6 delegate tests covering URL, body shape, system field placement,
response parsing, error surfacing, and reasoning_effort omission.
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.
Problem
The vision delegate hard-codes the OpenAI-compatible endpoint
POST {baseUrl}/chat/completionsfor every vision model (lib/delegate.ts→callVisionModel), ignoring the model's registeredapitype.For models registered as
api: "anthropic-messages"— e.g.minimax-cn/MiniMax-M3withbaseUrl: https://api.minimaxi.com/anthropic— the resulting URLhttps://api.minimaxi.com/anthropic/chat/completionsdoesn't exist. The request fails with:Reproduced live:
api.minimaxi.com/anthropic/chat/completions(what the delegate builds)api.minimaxi.com/anthropic/v1/messages(correct Anthropic Messages route)This also means any Anthropic-Messages-family vision model (MiniMax, Claude, Qwen Anthropic-compat endpoints, …) can never be used as the vision model, regardless of config correctness.
Fix
Make the request API-aware:
api: "anthropic-messages"→POST {baseUrl}/v1/messageswith the Messages schema:source.base64content block (media_type+data)systemPromptas a top-levelsystemfield (not a messages entry)temperature/reasoning_effort(not part of the Messages schema)content[]array — firsttextblock, with athinking-block fallback for reasoning-only replies/chat/completionspath (data-URL image, system message,reasoning_effortfor reasoning models)Tests
6 new tests in
tests/delegate.test.tscovering: endpoint URL, Anthropic body shape, system-field placement,content[]response parsing (text + thinking fallback), error surfacing, andreasoning_effortomission.Also verified end-to-end against the real
minimax-cn/MiniMax-M3endpoint (200 OK with a live request to.../anthropic/v1/messages).Notes
openai-responses/openai-codex-responsesmodels still use the/chat/completionscompat path — this PR deliberately scopes to the Anthropic-Messages fix; the OpenAI-responses shape can be a follow-up if needed.