fix(adapter): handle Anthropic-compat gateways without /v1/ in base URL - #6
Closed
AlexMikhalev wants to merge 3 commits into
Closed
fix(adapter): handle Anthropic-compat gateways without /v1/ in base URL#6AlexMikhalev wants to merge 3 commits into
AlexMikhalev wants to merge 3 commits into
Conversation
Resolved conflicts in Z.AI adapter implementation: - Consolidated duplicate Zai/ZAi adapters into single Zai adapter - Updated model routing logic for Z.AI models - Removed obsolete zhipu adapter references - Added cerebras module to adapters - Preserved dual endpoint support for Z.AI coding plans 🤖 Generated with [terraphim.ai](https://terraphim.ai) Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed import paths for adapters after module reorganization - Removed remaining duplicate ZAi adapter references - Added missing openrouter module export - Ensured consistent adapter import structure 🤖 Generated with [terraphim.ai](https://terraphim.ai) Co-Authored-By: Claude <noreply@anthropic.com>
The Anthropic adapter's get_service_url used `format!("{base_url}messages")`,
which concatenates the base URL with `messages` without any slash separator.
This works for the default Anthropic base URL (`https://api.anthropic.com/v1/`)
because the trailing slash happens to align with the message path. It produces
malformed URLs for Anthropic-compat gateways whose base URL doesn't end in
/v1/ — e.g. terraphim-llm-proxy's MiniMax provider at
`https://api.minimax.io/anthropic` was producing
`https://api.minimax.io/anthropicmessages` (404).
This affects both Chat and ChatStream service types in the same way, so
streaming requests to MiniMax (and any other non-Anthropic-but-compat
provider) fail with 404 today.
Fix the URL construction to handle three shapes:
- base_url ends in `messages` → pass through unchanged
- base_url ends in `/v1/` or `/v1` → append `messages` (legacy Anthropic behavior)
- base_url is anything else → append `/v1/messages` with proper slash
Add 6 unit tests covering all shapes and confirming streaming == chat
URL construction. Verified locally via `cargo test --lib`.
Discovered while validating terraphim-llm-proxy's MiniMax highspeed
offerings on 2026-08-11; see terraphim-llm-proxy#18 (Anthropic route) and
the gitea jeremychone#19 config PR for related context. Streaming was the remaining
gap after PR jeremychone#19 landed.
Author
|
Closing in favor of PR #7 — same fix rebased onto current main (v0.6.0-beta.8-fork). The original branch was 9 commits behind main. |
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 Anthropic adapter's
get_service_urlusedformat!("{base_url}messages"), which concatenates the base URL withmessageswithout any slash separator. This works for the default Anthropic base URL (https://api.anthropic.com/v1/) because the trailing slash happens to align with the message path. It produces malformed URLs for Anthropic-compat gateways whose base URL doesn't end in/v1/— e.g. terraphim-llm-proxy's MiniMax provider athttps://api.minimax.io/anthropicwas producinghttps://api.minimax.io/anthropicmessages(404).This affects both
ChatandChatStreamservice types in the same way, so streaming requests to MiniMax (and any other non-Anthropic-but-compat provider) fail with 404 today.Fix
Three-way URL construction:
Tests
6 unit tests covering all three shapes + the streaming-vs-chat equivalence. Verified via
cargo test --lib— all pass.Context
Discovered while validating terraphim-llm-proxy's MiniMax highspeed offerings on 2026-08-11. PR terraphim/terraphim-llm-proxy#19 fixed the config side; this PR fixes the genai adapter side. With both landed, MiniMax highspeed models route correctly under all conditions:
minimax_client::send_request✅ (working today)Acceptance criteria
https://api.anthropic.com/v1/messages/v1suffix without trailing slash works (preserves legacy behavior)/v1/messagesappended with proper slash/v1/messagesappended after slash trimmessagespasses through unchangedcargo test --libpasses all 6 new testsOut of scope
The Anthropic adapter also has a separate bug (#5 in terraphim-llm-proxy#18) where
tools: []payloads get forwarded to OpenAI-compat upstreams and rejected. That's an SDK → Anthropic-shape adapter issue, not a URL construction issue, and needs a separate fix into_web_request_data.