ai icon indicating copy to clipboard operation
ai copied to clipboard

Add support for compaction and token counting endpoints

Open cloudycotton opened this issue 1 year ago • 10 comments

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

cloudycotton avatar Nov 24 '25 22:11 cloudycotton

unlikely for 6.0

lgrammel avatar Dec 03 '25 12:12 lgrammel

@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

cloudycotton avatar Dec 04 '25 07:12 cloudycotton

We do want this but won't be able to get it done in time for v6

gr2m avatar Dec 09 '25 16:12 gr2m

@gr2m https://x.com/dkundel/status/1997065685831503972 openai also released it!

cloudycotton avatar Dec 10 '25 07:12 cloudycotton

@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

swiecki avatar Dec 21 '25 00:12 swiecki

Re openai compaction: A potential solution here is to support special openai specific system message annotations for compacted histories.

lgrammel avatar Dec 21 '25 10:12 lgrammel

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.

cloudycotton avatar Jan 13 '26 06:01 cloudycotton

Would be great to have support for this, especially the openai compact endpoint!

Potrock avatar Jan 25 '26 18:01 Potrock

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"
}

lgrammel avatar Jul 02 '26 08:07 lgrammel

Tracking separately:

  • https://github.com/vercel/ai/issues/19376
  • https://github.com/vercel/ai/issues/14017

n1ckoates avatar Sep 03 '26 22:09 n1ckoates