fix(provider): skip includeUsage for incompatible OpenAI-compatible hosts#35446
Open
Fatty911 wants to merge 1 commit into
Open
fix(provider): skip includeUsage for incompatible OpenAI-compatible hosts#35446Fatty911 wants to merge 1 commit into
Fatty911 wants to merge 1 commit into
Conversation
…osts Some OpenAI-compatible providers (Chinese AI gateways like Volcengine, Qianfan, DashScope, etc.) return HTTP 400 when stream_options.includeUsage is sent. This patch checks the baseURL against a list of known incompatible hosts and skips setting includeUsage for them, while still allowing users to explicitly opt in by setting includeUsage: true in their config. Closes anomalyco#31156
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found: PR #31790 - This appears to be a related/duplicate PR addressing the same issue. Both are fixing the |
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.
Issue for this PR
Closes #31156
Type of change
What does this PR do?
Several OpenAI-compatible providers (Chinese AI gateways like Volcengine, Qianfan, DashScope, ModelScope, etc.) return HTTP 400 Bad Request when
stream_options.include_usageis sent in the request body. The current code unconditionally setsincludeUsage: truefor all@ai-sdk/openai-compatibleproviders, causing failures for these hosts.This PR adds a host-based check: before setting
includeUsage, it parses thebaseURLand compares the host against a list of known incompatible providers. If the host matches,includeUsageis skipped. Users can still explicitly opt in by settingincludeUsage: truein their provider config (the!== falsecheck is preserved).The incompatible hosts were identified from issue #31156 and community reports — all are major Chinese AI platforms that use non-standard OpenAI-compatible API implementations.
How did you verify your code works?
baseURLparsing correctly matches hosts likehttps://ark.cn-beijing.volces.com/api/v3→ hostark.cn-beijing.volces.comincludeUsage: truein config still works (the outer!== falseguard is preserved)includeUsageis no longer sentincludeUsage: trueas beforeChecklist