Skip to content

[Platform] Fix #2274: Preserve cache and reasoning tokens in Generic completions usage#2275

Open
ineersa wants to merge 1 commit into
symfony:mainfrom
ineersa:cache-tokens-extraction
Open

[Platform] Fix #2274: Preserve cache and reasoning tokens in Generic completions usage#2275
ineersa wants to merge 1 commit into
symfony:mainfrom
ineersa:cache-tokens-extraction

Conversation

@ineersa

@ineersa ineersa commented Jul 5, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #2274
License MIT

Generic/OpenAI-compatible completions usage conversion now preserves provider-reported cache and reasoning token details.

The extractor now handles common usage shapes such as:

  • prompt_tokens_details.cached_tokens
  • input_tokens_details.cached_tokens
  • prompt_cache_hit_tokens
  • num_cached_tokens
  • cached_tokens
  • cache_read_tokens
  • cache_read_input_tokens
  • cache_creation_tokens
  • cache_creation_input_tokens
  • completion_tokens_details.reasoning_tokens
  • output_tokens_details.reasoning_tokens

This keeps existing prompt/completion/total token behavior unchanged while exposing available cache-read/cache-creation/cached/reasoning token data when providers include it.

@carsonbot carsonbot added Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review labels Jul 5, 2026

$this->assertSame(40, $tokenUsage->getCacheReadTokens());
$this->assertSame(10, $tokenUsage->getCacheCreationTokens());
$this->assertSame(40, $tokenUsage->getCachedTokens());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should be 50 from my understanding: it basically sums up all tokens where cache could be used - no matter if read or create

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

Labels

Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Platform][Generic] Streaming token usage drops provider-specific cache and reasoning token details

3 participants