Skip to content

fix(providers): map gateway model ids before cloud fallback - #118

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-d140
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-d140

Conversation

@cursor

@cursor cursor Bot commented Oct 15, 2026

Copy link
Copy Markdown

Bug and impact

Copying config.example.toml and setting ANTHROPIC_API_KEY makes every chat fail. agent.model is anthropic/claude-sonnet-4-20250514. The Anthropic Messages API expects the id without the anthropic/ prefix and rejects the example value with HTTP 4xx. The router treats 4xx as terminal, so the local llama-server backend is never tried.

If Anthropic is down (5xx) and OPENAI_API_KEY is also set, OpenAI is called with the same Claude id, returns HTTP 400, and local is still skipped.

Root cause

anthropic.c and openai.c send config_agent_model() verbatim. The built-in gpt-4o-mini / claude-3-5-sonnet-20241022 defaults apply only when that string is missing, which config_load does not allow. A 4xx anywhere in the provider error stops fallback_chain.

Fix

provider_model_id_for_backend() strips a matching vendor/ prefix (anthropic/claude-sonnet-4-20250514 becomes claude-sonnet-4-20250514 on Anthropic, openai/gpt-4o becomes gpt-4o on OpenAI). A known foreign cloud id is skipped with an error that does not contain HTTP 4xx, so the router continues to the next backend. Unknown names such as the local Phi-3 id are left unchanged.

Validation

make test_provider test_anthropic test_openai passed. The Anthropic test records the request model with HTTP skipped and expects claude-sonnet-4-20250514. The OpenAI test uses the example model and a dummy key and expects an immediate retryable skip with no network call.

Open in Web聽View Automation聽

config.example.toml sets agent.model to anthropic/claude-sonnet-4-20250514.
Both cloud backends forwarded that string. Anthropic rejects the vendor
prefix with HTTP 4xx, which stops the fallback chain before local.
OpenAI receives the same Claude id after an Anthropic 5xx and returns
HTTP 400, which also stops the chain.

Strip a matching vendor prefix and skip a foreign cloud id with a
non-HTTP error so the router can continue.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@adriannoes

Copy link
Copy Markdown
Collaborator

Superseded by #130: consolidated into the operator-authored branch fix/providers-model-mapping (same fix, rebased on #124 and re-validated with make test_anthropic, make test_openai, make test_provider, CI=true make test, make static). Closing in favor of the consolidation.

@adriannoes adriannoes closed this Oct 17, 2026
@adriannoes
adriannoes deleted the cursor/high-severity-issues-d140 branch October 17, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants