@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
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
providerId option to override it:
Options
| Parameter | Type | Required | Description |
|---|---|---|---|
autumn | Autumn | Yes | Your Autumn SDK client instance |
model | LanguageModelV3 | Yes | The AI SDK language model to wrap |
customerId | string | Yes | The Autumn customer ID to attribute usage to |
providerId | string | No | Override the provider prefix in the model name sent to Autumn. Falls back to the model’s provider field |
featureId | string | No | Target a specific AI credit system feature. Auto-detected if you only have one |
entityId | string | No | Entity ID for entity-scoped balance tracking |
properties | Record<string, unknown> | No | Additional properties to attach to each usage event |