Skip to content

Custom baseURL providers report zero prompt cache tokens for subagent sessions #30663

Description

@ThreeIce

Description

When using a custom OpenAI-compatible baseURL, prompt cache accounting stays at zero for subagent sessions.

I tested both provider configurations:

  • npm: "@ai-sdk/openai" with a custom baseURL
  • npm: "@ai-sdk/openai-compatible" with a custom baseURL

In both cases, after running a subagent task and exporting the subagent session with opencode export <sessionID>, the exported subagent session reports:

"tokens": {
  "cache": {
    "read": 0,
    "write": 0
  }
}

Each assistant message in the exported subagent session also reports tokens.cache.read = 0 and tokens.cache.write = 0.

The same custom endpoint does report prompt cache normally in the main conversation. The zero cache accounting appears specific to subagent sessions.

This looks related to, but not identical to:

The difference here is that the issue reproduces with both @ai-sdk/openai and @ai-sdk/openai-compatible, while the main conversation cache works normally. The observed symptom is specifically exported subagent sessions reporting zero cache read/write tokens.

Plugins

None

OpenCode version

1.15.13

Steps to reproduce

  1. Configure a custom provider with a custom OpenAI-compatible baseURL using @ai-sdk/openai.
  2. Run a normal main conversation and confirm prompt cache accounting is non-zero.
  3. Run a simple subagent task, for example an explore subagent that reads a few repository files.
  4. Export the subagent session:
opencode export <subagent-session-id>
  1. Observe that the exported subagent session has tokens.cache.read = 0 and tokens.cache.write = 0.
  2. Repeat with the same custom baseURL configured through @ai-sdk/openai-compatible.
  3. Observe the same zero cache accounting in the exported subagent session.

Expected behavior: if prompt caching is enabled and reported for the custom endpoint in the main conversation, subagent sessions should report cache read/write token counts consistently as well.

Actual behavior: both provider paths report zero cache read/write tokens for exported subagent sessions, while the main conversation cache works normally.

Operating System

Windows / win32

Terminal

PowerShell / Windows terminal environment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions