fix(runtime): strip trailing /v1 from anthropic_messages custom provider base_url#44195
Open
AIalliAI wants to merge 1 commit into
Open
fix(runtime): strip trailing /v1 from anthropic_messages custom provider base_url#44195AIalliAI wants to merge 1 commit into
AIalliAI wants to merge 1 commit into
Conversation
…der base_url The Anthropic SDK appends /v1/messages to base_url itself, so a custom provider configured with api_mode: anthropic_messages and a gateway URL like http://host:3001/v1 sent requests to /v1/v1/messages — a 404 that surfaced only as an opaque auth/model-detection failure. The opencode-zen/go and azure-foundry resolvers already normalise this exact case; this extends the same strip to the three custom-provider return paths (named custom_providers/providers entries, the custom credential-pool path, and bare provider: custom with model.api_mode), so entries sharing a multi-protocol gateway can all use the same /v1 base_url. Fixes NousResearch#44181 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
✅ Verified — anthropic_messages Reviewed the diff for correctness across all three custom-provider return paths.
Clean, well-scoped fix. No issues found. |
Contributor
Author
|
Requesting maintainer review — this is ready to land from my side. Standalone fork CI is pending first-run approval here; the rollup branch in #44061 carrying this session's batch is fully green on upstream CI (all test shards, typecheck, e2e). |
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
A
custom_providers/providers:entry withapi_mode: anthropic_messagesand a base URL ending in/v1(the natural choice when several entries share one multi-protocol gateway) fails silently: the Anthropic SDK appends/v1/messagesto the base_url itself, so requests go tohttp://host:3001/v1/v1/messages— a 404 that surfaces only as an opaque auth / model-detection failure.The opencode-zen/go resolver (
runtime_provider.py~L406) and the azure-foundry resolver (~L369, ~L1001) already strip the trailing/v1for exactly this reason — custom providers were the remaining gap.Fix
Adds a
_strip_anthropic_v1_suffix()helper and applies it on the three custom-provider return paths whereapi_modecan be explicitly configured:custom_providers/providers:entries (_resolve_named_custom_runtime)_try_resolve_from_custom_pool)provider: customwithmodel.api_mode(openrouter/custom fallback resolver)The strip is gated on
api_mode == "anthropic_messages"— OpenAI-wire entries keep their/v1untouched. A debug log records the rewrite. This is Option B from the issue (auto-normalize), matching the existing in-repo precedent rather than a docs-only fix.Also documents the behavior in the custom-providers section of
website/docs/integrations/providers.md.Note on the issue's repro: the reported config uses a
protocol:key, which isn't part of the schema (the recognized field isapi_mode/transport; unknown keys are ignored with a logged warning). The underlying double-/v1failure mode is real forapi_mode: anthropic_messages, which this PR fixes.Tests
4 new regression tests in
tests/hermes_cli/test_runtime_provider_resolution.py(named entry strips, chat_completions keeps/v1, bare-custom strips, pool path strips). Full file: 133 passed.Fixes #44181
🤖 Generated with Claude Code