Skip to content

feat(schema): add streamUsage compatibility to turn off stream_options - #57255

Merged
rekram1-node merged 2 commits into
devfrom
stream-usage-compat
Oct 20, 2026
Merged

rekram1-node merged 2 commits into
devfrom
stream-usage-compat

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #57230 (the stream_options half; store was handled in #57239).

Chat Completions always sends stream_options: { include_usage: true }, and there was no way to turn it off from config. Strict OpenAI-style APIs that reject unknown fields (Sarashina in #57230, Databricks AI Gateway in #31156) fail with a 400.

Changes:

  • Adds streamUsage to the public model/provider compatibility schema. "compatibility": { "streamUsage": false } on a provider or model drops stream_options from the request. Defaults to true, so behavior is unchanged unless set.
  • Renames the internal supportsUsageInStreaming to streamUsage so config and the AI package share one name, and removes the always-true detector plus Cohere's redundant true.
  • Regenerates the client types, packages/protocol/openapi.json, and the services/www OpenAPI docs. Only the two streamUsage hunks are included; the generator also produced unrelated drift already on dev, which is left out.

Example:

{
  "providers": {
    "example": {
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.example.com/v1" },
      "compatibility": { "streamUsage": false }
    }
  }
}

Without usage chunks, token and cost numbers for that provider are only as good as what the API returns without include_usage.

Testing:

  • bun test in packages/ai: all pass except the two Bedrock PDF cassettes, which fail only because of the host's AWS_REGION; they pass with it unset. New test: streamUsage: false omits stream_options.
  • bun run typecheck in packages/ai and packages/schema; tsc for packages/core src and tests.
  • packages/core config/provider, normalization, and model-resolver tests. New test: provider-level compatibility.streamUsage: false reaches the resolved runtime model.

Requested by: @rekram1-node (Aiden Cline via Slack)

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described. I ran opencode run from source against a local OpenAI-compatible server that records request bodies, with "compatibility": { "streamUsage": false } on the provider. On the base, the key is ignored and every request still sends stream_options: { include_usage: true }. With this PR, stream_options is left out and the run completes normally. The openai-chat, config/provider and model-resolver tests pass, and so does typecheck in ai, schema and core.

Public API impact:

  • Added: optional compatibility.streamUsage (boolean, defaults to true) on models and providers in the config schema, in the OpenAPI ModelCompatibility / ProviderCompatibility and in the generated client types. Backwards compatible.
  • Renamed in the published @opencode/ai package: LanguageModelCompatibility.supportsUsageInStreaming → streamUsage. Only direct SDK callers that set the old field to false are affected: TypeScript flags it, and untyped callers would quietly start sending stream_options again. Existing configs are unaffected.

No blocking concerns.

Related: #31156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provider: openai-compatible always injects stream_options and store, breaking non-OpenAI-compatible APIs

1 participant