-
Notifications
You must be signed in to change notification settings - Fork 212
fix(anthropic): honor custom apiModelId instead of silently defaulting to claude-sonnet-4-5 #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
navedmerchant
merged 5 commits into
Zoo-Code-Org:main
from
grizmin:fix/anthropic-custom-model-id-fallback
Jul 9, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
614d693
fix(anthropic): honor custom apiModelId instead of silently defaultin…
grizmin d21cec5
style: trim comments to a single line
grizmin 4726f80
chore: add changeset for anthropic custom model id fallback fix
grizmin aaf2862
Merge branch 'main' into fix/anthropic-custom-model-id-fallback
navedmerchant 7dcf6db
Hoist sorted model IDs out of guessModelInfoFromId method; Make model…
grizmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| "zoo-code": patch | ||
| --- | ||
|
|
||
| Fix Anthropic provider silently replacing a custom/unrecognized `apiModelId` with the hardcoded default model. | ||
|
|
||
| `AnthropicHandler.getModel()` coerced any `apiModelId` not present in the static `anthropicModels` table down to `anthropicDefaultModelId` ("claude-sonnet-4-5"), and that coerced id was what actually got sent as `model` in the API request -- silently ignoring a user-configured custom model name (e.g. a custom Anthropic-compatible deployment or proxy). This produced confusing "model does not exist" errors for the default model instead of the model the user actually selected (#418). | ||
|
|
||
| The same fallback also affected capability lookups used to build the `thinking` request parameter: an unrecognized id fell back to the default model's info, which can be from an older model generation with a different API contract, causing the request to use the legacy `thinking: {type: "enabled", budget_tokens}` shape and get rejected with a 400 by models that require `{type: "adaptive"}`. | ||
|
|
||
| The model id sent to the API now always honors a user-configured `apiModelId`. For unrecognized values, capabilities are best-effort guessed by matching known model-family substrings (mirroring the existing `BedrockHandler.guessModelInfoFromId` heuristic) instead of defaulting to `anthropicDefaultModelId`'s info. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -353,10 +353,25 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa | |
| } | ||
| } | ||
|
|
||
| // Guesses capabilities for an unrecognized model ID via known-family substring match. | ||
| private guessModelInfoFromId(modelId: string): ModelInfo { | ||
| const matchedId = (Object.keys(anthropicModels) as AnthropicModelId[]) | ||
| .sort((a, b) => b.length - a.length) | ||
| .find((knownId) => modelId.includes(knownId)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should lowercase the modelId before matching so the matching is case insensitve |
||
|
|
||
| return matchedId ? anthropicModels[matchedId] : anthropicModels[anthropicDefaultModelId] | ||
| } | ||
|
|
||
| getModel() { | ||
| const modelId = this.options.apiModelId | ||
| const id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId | ||
| let info: ModelInfo = anthropicModels[id] | ||
| const isKnownModel = modelId !== undefined && modelId in anthropicModels | ||
|
|
||
| // Always honor a user-configured apiModelId, even if it's not a known model. | ||
| const id = isKnownModel ? (modelId as AnthropicModelId) : (modelId ?? anthropicDefaultModelId) | ||
|
|
||
| let info: ModelInfo = isKnownModel | ||
| ? anthropicModels[modelId as AnthropicModelId] | ||
| : this.guessModelInfoFromId(id) | ||
|
|
||
| // If 1M context beta is enabled for supported models, update the model info | ||
| if ( | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets hoist a sorted list out of this method so we dont have to needlessly sort every time