Add support for compaction and token counting endpoints
Description
All major model providers have support for token counting endpoints and claude recently released compaction support in their native sdk.
We should extend the model v3 spec to include token counting endpoint in the provider that is optional.
AI SDK Version
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
unlikely for 6.0
@lgrammel I'm happy to open a PR if you can tell me a bit more about how you would want it done or sponsor someone to do it
We do want this but won't be able to get it done in time for v6
@gr2m https://x.com/dkundel/status/1997065685831503972 openai also released it!
@lgrammel I'm happy to open a PR if you can tell me a bit more about how you would want it done or sponsor someone to do it
i also have no clue how to attack this, openai's endpoint wants the output of the /compact passed straight in as input for the next one, it returns back messages plus a 'compaction' object, but this seems crucial to add for long running agents
Re openai compaction: A potential solution here is to support special openai specific system message annotations for compacted histories.
what about a helper util or middleware that could be model agnostic? @lgrammel right now, it is cumbersome to build due to prepareStep being append only. We could add one like the examples middleware for fallback.
Would be great to have support for this, especially the openai compact endpoint!
Identify issue type
{
"evidence": [
"Description says major providers have token counting endpoints and asks to extend the model v3 spec to include an optional token counting endpoint.",
"The title asks to add support for compaction and token counting endpoints.",
"Maintainer comments state they want this but it will not be done in time for v6, and discuss possible implementation approaches for OpenAI compaction."
],
"rationale": "The issue requests new AI SDK capabilities and provider/spec expansion, not a failure of existing behavior.",
"type": "feature",
"confidence": "high"
}
Tracking separately:
- https://github.com/vercel/ai/issues/19376
- https://github.com/vercel/ai/issues/14017