fix(custom-provider): preserve base URL for anthropic_messages api_mode - #30232
fix(custom-provider): preserve base URL for anthropic_messages api_mode#30232terlanks wants to merge 1 commit into
Conversation
When a custom provider is configured with api_mode=anthropic_messages, the existing code unconditionally rewrote the base URL via _to_openai_base_url(), converting e.g. http://host/anthropic to http://host/v1. The Anthropic SDK then appended /v1/messages, resulting in a request to /v1/v1/messages which returns 404. The named-custom-provider branch (around line 3380) already handled this correctly by skipping the URL rewrite for anthropic_messages. Apply the same guard to the generic custom-provider branch. Fix: when api_mode == 'anthropic_messages', keep the original base URL as-is and only strip a trailing slash. For all other api_modes the existing _to_openai_base_url() rewrite is preserved.
|
Thanks for isolating the generic custom-provider path. The premise still holds on current main: Problems
Suggested changes
The target has moved to |
|
This bug is now fixed on main via #85466 (salvage of #64891). Credit correction: your PR was submitted May 22 — the second-earliest fix for this branch (after #29624 on May 21), months before the version that merged, and your diff is nearly line-identical to what landed for the wrapper path. The pre-merge duplicate sweep missed it, which is our miss. The merged variant additionally kept the |
Problem
When a custom provider is configured with
api_mode: anthropic_messages, the code inresolve_provider_client()unconditionally rewrites the base URL via_to_openai_base_url(), converting e.g.http://host/anthropic→http://host/v1.The Anthropic SDK then appends
/v1/messagesto the base URL, resulting in a request to/v1/v1/messages→ 404.Root Cause
The generic
customprovider branch (~line 3271) lacks theapi_modeguard that the named custom-provider branch (~line 3380) already has:The generic branch was missing this check entirely.
Fix
Apply the same guard to the generic
custombranch: whenapi_mode == "anthropic_messages", keep the original base URL (only strip trailing slash). For all other api_modes, the existing_to_openai_base_url()rewrite is preserved.Testing
Reproduced and verified with a local Anthropic-compatible proxy (
base_url: http://localhost:6655/anthropic,api_mode: anthropic_messages). Before the fix: 404 on every call. After: requests route correctly to/anthropic/v1/messages.