@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 Node.js 22+, ESM imports, and
autumn-js and ai (v7) as peer dependencies. AI SDK 6 applications should stay on the previous gateway release.2. Wrap your model
UsewithAutumn 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 themodelId 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/anthropic→anthropic/claude-sonnet-4-5-20250514@ai-sdk/openai→openai/gpt-4o@ai-sdk/google→google/gemini-2.5-pro
openai.responses, anthropic.messages, and google.generative-ai. Vercel’s gateway namespace maps to vercel. Dots and slashes in the model ID are preserved. Other provider names pass through unchanged.
For a custom mapping, use providerId. Explicit overrides are used verbatim: