Skip to content

fix: read prompt_tokens_details cache reads in TS OpenAI Chat - #3885

Merged
opieter-aws merged 2 commits into
strands-agents:mainfrom
opieter-aws:agent-tasks/3546-ts-openai-chat-cache-reads
Aug 19, 2026
Merged

opieter-aws merged 2 commits into
strands-agents:mainfrom
opieter-aws:agent-tasks/3546-ts-openai-chat-cache-reads

Conversation

@opieter-aws

@opieter-aws opieter-aws commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

The TypeScript OpenAI Chat Completions path doesn't read prompt_tokens_details.cached_tokens, so prompt-cache reads were invisible in its usage

Related Issues

Part of the #3546 usage-accounting work (the py/ts Chat parity gap).

Documentation PR

N/A

Type of Change

Bug fix

Testing

Ran the TS OpenAI Chat unit suite (src/models/openai/__tests__/chat.test.ts), covering a cached-read payload surfacing cacheReadInputTokens and a zero/absent case that must not introduce the field.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@opieter-aws opieter-aws changed the title fix(models): read prompt_tokens_details cache reads in TS OpenAI Chat fix: read prompt_tokens_details cache reads in TS OpenAI Chat Aug 19, 2026
@github-actions github-actions Bot added bug Something isn't working typescript Pull requests that update typescript code area-model Related to models or model providers complexity/medium Touched functions have moderate cognitive complexity (11-25) size/xs labels Aug 19, 2026
Removed outdated regression comment regarding TS Chat.
@opieter-aws
opieter-aws marked this pull request as ready for review August 19, 2026 14:30
@opieter-aws
opieter-aws requested a review from a team as a code owner August 19, 2026 14:30
@opieter-aws
opieter-aws requested a review from poshinchen August 19, 2026 14:30
Comment thread strands-ts/src/models/openai/__tests__/chat.test.ts
@github-actions

Copy link
Copy Markdown
Contributor

Assessment: Approve

Clean, well-scoped bug fix that closes the py/ts Chat parity gap for prompt-cache reads. The new guard mirrors the Responses path (mapResponsesUsage in responses-adapter.ts) exactly, so both OpenAI paths now surface cacheReadInputTokens consistently, and the field stays optional (matching the Usage type and Bedrock/Anthropic adapters).

Review Notes
  • Correctness: Present-and-positive guard is right and consistent across the two OpenAI paths.
  • Testing: Full-object toEqual assertions are used (good). One minor gap noted inline — the "absent" wording in the second test isn't directly exercised.
  • API/Scope: Internal fix, no public API surface change; PR is small and focused.

Nice job keeping this tightly aligned with the existing Responses implementation.

@opieter-aws
opieter-aws enabled auto-merge (squash) August 19, 2026 15:25
@opieter-aws
opieter-aws merged commit 2b2d9bd into strands-agents:main Aug 19, 2026
31 of 33 checks passed
@opieter-aws
opieter-aws deleted the agent-tasks/3546-ts-openai-chat-cache-reads branch August 19, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-model Related to models or model providers bug Something isn't working complexity/medium Touched functions have moderate cognitive complexity (11-25) size/xs typescript Pull requests that update typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants