vercel / vercel/ai

Support for cache write tokens in returned response usage

Open
#8,367 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

ai/provider provider/anthropic provider/gateway support task-identify-issue-type-done
Dominant language
TypeScript
Stars
26.9k
Forks
5.2k
Avg merge
17h 48m
Merged PRs (30d)
516

Description

Description

Some providers like anthropic also charge for cache writes

https://www.anthropic.com/pricing#api

It would be great for generateText, streamText ( LanguageModelV2Usage) to include cache write tokens as well so we can accurately compute cost correctly for all models

AI SDK Version

v5

Code of Conduct
  • I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the generateText and streamText entry points and the LanguageModelV2Usage type to see how returned usage is assembled. Check the provider usage mapping, especially for cache writes, and add coverage showing that cache write tokens are returned so callers can calculate costs accurately.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.