Skip to content

fix(provider): skip includeUsage for incompatible OpenAI-compatible hosts#35446

Open
Fatty911 wants to merge 1 commit into
anomalyco:devfrom
Fatty911:fix/include-usage-incompatible-providers
Open

fix(provider): skip includeUsage for incompatible OpenAI-compatible hosts#35446
Fatty911 wants to merge 1 commit into
anomalyco:devfrom
Fatty911:fix/include-usage-incompatible-providers

Conversation

@Fatty911

@Fatty911 Fatty911 commented Jul 5, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #31156

Type of change

  • Bug fix

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_usage is sent in the request body. The current code unconditionally sets includeUsage: true for all @ai-sdk/openai-compatible providers, causing failures for these hosts.

This PR adds a host-based check: before setting includeUsage, it parses the baseURL and compares the host against a list of known incompatible providers. If the host matches, includeUsage is skipped. Users can still explicitly opt in by setting includeUsage: true in their provider config (the !== false check 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?

  • Verified that the baseURL parsing correctly matches hosts like https://ark.cn-beijing.volces.com/api/v3 → host ark.cn-beijing.volces.com
  • Confirmed that explicitly setting includeUsage: true in config still works (the outer !== false guard is preserved)
  • Tested with a Volcengine endpoint that previously returned 400 — with this fix, the request succeeds because includeUsage is no longer sent
  • Verified that standard OpenAI-compatible providers (OpenRouter, Together, etc.) still get includeUsage: true as before

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicate found:

PR #31790 - fix(llm): allow disabling compatible stream usage
#31790

This appears to be a related/duplicate PR addressing the same issue. Both are fixing the includeUsage problem with incompatible OpenAI-compatible providers that return 400 errors. You may want to review #31790 to see if it's already merged or if the approaches differ.

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.

[Bug]: "stream_options" injected into OpenAI-compatible provider causing 400 Bad Request on Databricks AI Gateway

1 participant