anomalyco / anomalyco/opencode
Together AI: token usage always 0 — bundled @ai-sdk/togetherai doesn't send stream_options.include_usage
@nexxeln is already working on this.
Since Sep 7, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
Token usage and cost are recorded as 0 for all Together AI models (tested: zai-org/GLM-5.2, zai-org/GLM-5.3, moonshotai/Kimi-K3) on opencode 1.18.29. The UI shows 0 tokens / $0 cost, and the values stored on assistant messages in opencode.db are all zero — this is not a display bug.
Root cause
- opencode's outbound streaming requests to Together do not include
stream_options: {include_usage: true}(verified by capturing the actual request body through a local proxy). - Together's current serving stack only includes
usagein streaming responses when that flag is set. Verified with curl againsthttps://api.together.xyz/v1/chat/completions:- Without
stream_options.include_usage: GLM-5.2/5.3 streams contain nousageat all; Kimi-K3 emits usage only in a non-standard location (insidechoices[0], which the AI SDK parser ignores). - With the flag: all three models return a standard top-level
usagechunk.
- Without
- opencode force-sets
includeUsage: trueonly for providers whose npm package is@ai-sdk/openai-compatible(packages/opencode/src/provider/provider.ts,resolveSDK). models.dev routestogetheraithrough the custom@ai-sdk/togetheraipackage, so the force-set never applies, and the bundled version of that package does not request usage. - This used to work: messages recorded real usage through 2026-07-17. Together changed their serving stack around 2026-07-18→28 (SSE chunk IDs changed from
chatcmpl-...to e.g.9ac28c1f-aws_uw2), after which usage stopped being included by default. Same opencode version, same models — behavior changed server-side, so this affects all opencode versions, not just recent ones.
Suggested fix
@ai-sdk/togetherai@3.0.45 hardcodes includeUsage: true on its chat models (it wraps OpenAICompatibleChatLanguageModel with includeUsage: true). Bumping the bundled @ai-sdk/togetherai dependency to >= 3.0.45 should restore usage reporting with no other changes.
Note: routing togetherai through @ai-sdk/openai-compatible instead is not a good fix — opencode's transform layer gates Together's reasoning_effort parameter on the npm string being exactly @ai-sdk/togetherai (packages/opencode/src/provider/transform.ts), so switching packages silently drops reasoning-effort control.
Workaround attempted (for completeness)
Overriding the provider in config with "npm": "@ai-sdk/openai-compatible" + options.baseURL + explicitly declaring each model in provider.togetherai.models does restore token recording (verified: usage and cost land in the DB), but reasoning_effort is no longer sent, so it's a tradeoff most users shouldn't have to make.
Environment
- opencode 1.18.29 (linux x64)
- Provider: togetherai (API key via
/connect) - Models:
moonshotai/Kimi-K3,zai-org/GLM-5.3,zai-org/GLM-5.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.