fix(adapter): handle Anthropic-compat gateways without /v1/ in base URL - #7
Merged
AlexMikhalev merged 3 commits intoAug 11, 2026
Conversation
added 3 commits
August 11, 2026 12:02
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` (71/71 pass).
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.
The previous fix used `format!("{base_url}messages")` when base_url ended
in `/v1`, which produces `https://api.minimax.io/anthropic/v1messages` —
no slash separator, 404.
Real-world gateways like the terraphim-llm-proxy MiniMax provider use
`https://api.minimax.io/anthropic/v1` as the base URL, and the actual
upstream endpoint is `/anthropic/v1/messages`. Split the `/v1` arm
into two:
- base_url ends with `/v1/` → legacy Anthropic shape, append `messages`
- base_url ends with `/v1` → insert `/`, append `messages`
Update the regression test to assert `/v1/messages` for the no-trailing-slash case.
This is a follow-up to PR #7 (#7) — the streaming
build I tested locally produced 404 because of this. All 13 anthropic
unit tests pass.
Clippy 1.96 added the `clippy::collapsible_match` lint which flags
`match arm { if cond { body } }` and suggests converting to
`match arm if cond => { body }`.
Apply to two arms in `src/webc/web_stream.rs` (`'['` and `']'`)
that both contain `if depth == 0`. No behavior change.
Required to keep CI passing under `-D warnings` once stable Rust
ships 1.96. PR #7 (anthropic endpoint URL normalization) hits this
lint and fails the Lint/Build/Test job without this fix.
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 new unit tests covering all three shapes + the streaming-vs-chat equivalence. 71/71 lib tests 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 71 tests (6 new + 65 existing)Out of scope
The Anthropic adapter also has a separate bug (terraphim-llm-proxy#18) where
tools: []payloads get forwarded to OpenAI-compat upstreams and rejected withtools[0].type:type cannot be empty. That's a request-shape adapter issue into_web_request_data, not a URL construction issue, and needs a separate fix.