fix: unify Anthropic/Claude model detection in ProviderTransform#20414
Open
bussnet wants to merge 2 commits intoanomalyco:devfrom
Open
fix: unify Anthropic/Claude model detection in ProviderTransform#20414bussnet wants to merge 2 commits intoanomalyco:devfrom
bussnet wants to merge 2 commits intoanomalyco:devfrom
Conversation
Extract isClaudeModel() helper to replace three inconsistent detection strategies that used different conditions to identify Claude models. The empty-content stripping (L56) only checked api.npm while caching (L282) and tool-ID scrubbing (L76) used broader name-based checks. This mismatch caused 400 prefill errors when Claude models were routed through OpenAI-compatible proxies — caching applied but the required empty-content stripping did not.
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
The test spread from anthropicModel which has id containing 'claude', making isClaudeModel() correctly detect it as Claude despite the overridden providerID and api fields.
Author
|
Reson for the failing e2e-tests: OPENCODE_API_KEY is required when OPENCODE_E2E_REQUIRE_PAID=true — missing secret, not related to this change |
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.
Summary
isClaudeModel()helper intransform.tsto replace three inconsistent detection strategies for identifying Claude/Anthropic modelsProblem
ProviderTransformuses three different conditions to detect Anthropic/Claude models, and they disagree:api.npm === "@ai-sdk/anthropic"api.id.includes("claude")providerID || api.id || model.id || api.npmWhen a Claude model is accessed through an OpenAI-compatible proxy (
@ai-sdk/openai-compatible), the model name may contain "claude" but the npm package is not@ai-sdk/anthropic. This causes caching and tool-ID scrubbing to activate while empty-content stripping does not. Empty assistant messages survive, get cache metadata attached, and Anthropic rejects them as invalid prefill.Fix
Single
isClaudeModel(model)function used at all three sites:Testing
packages/opencode/src/provider/transform.ts