Skip to main content
The @useautumn/gateway package integrates Autumn with the Vercel AI SDK, automatically tracking token usage for every generateText or streamText call. No manual trackTokens calls needed.

Setup

1. Install the package

Requires autumn-js and ai (v6+) as peer dependencies.

2. Wrap your model

Use withAutumn to wrap any AI SDK language model. It intercepts generate and stream calls, reads the token usage from the response, and reports it to Autumn automatically.

3. Use as normal

The wrapped model works exactly like a regular AI SDK model. Token usage is tracked in the background after each call.

Token pools

The wrapper normalizes the AI SDK’s usage object into the exclusive token pools that trackTokens expects: text input (excluding cached tokens), text output (excluding reasoning tokens), cache reads, cache writes, and reasoning tokens. Each pool is billed at the model’s published rate, so cached and reasoning-heavy requests are priced correctly without any extra work.

Model ID format

The wrapped model constructs the modelId sent to Autumn using provider/model format, derived from the AI SDK model’s provider and modelId fields. This must match a valid provider and model key from Models.dev. For example:
  • @ai-sdk/anthropicanthropic/claude-sonnet-4-5-20250514
  • @ai-sdk/openaiopenai/gpt-4o
  • @ai-sdk/googlegoogle/gemini-2.5-pro
If the AI SDK provider name doesn’t match the Models.dev provider key, use the providerId option to override it:

Options

Full example

Tracking failures are caught and logged to the console — they won’t break your AI features. Check your server logs if usage isn’t appearing in Autumn.