The customer must already exist before calling
track. If the customer_id doesn’t match an existing customer, the API returns a customer_not_found error. Create customers using customers.getOrCreate during signup or login.Sending Events
The track route is recommended for tracking consumable features, like AI messages, credits or API calls. Each time a customer uses a feature, send an event to count their usage.You can also send a negative
value to increase the balance counter, which is
useful for increasing a feature limit (eg, if a customer removes a seat).Setting Usage Directly
For non-consumable features (such as seats or workspaces), you may prefer to set usage directly, rather than incrementing Autumn’s feature balance. This enables you to sync a source of truth up on your side with Autumn, preventing any discrepancies.Tracking AI Token Usage
If you’re using an AI credit system, you can track token usage directly withtrackTokens. This automatically converts token counts to a dollar cost using Models.dev pricing and your configured markup, then deducts from the customer’s credit balance.
The modelId must be in provider/model format, matching the provider and model keys from Models.dev. For example:
anthropic/claude-sonnet-4-5-20250514openai/gpt-4ogoogle/gemini-2.5-pro
openrouter/anthropic/claude-opus-4.6.
Token counts are exclusive pools: inputTokens should exclude cached tokens (pass those as cacheReadTokens / cacheWriteTokens) and outputTokens should exclude reasoning tokens (pass those as reasoningTokens). Audio tokens go in audioInputTokens / audioOutputTokens. See the API reference for the full parameter list.
autumn.balances.trackTokens requires an autumn-js release that includes
the method. On older versions, call the REST endpoint directly — see the
cURL tab below.Vercel AI SDK integration
If you’re using the Vercel AI SDK, the@useautumn/gateway package can automatically track token usage for every generateText or streamText call — no manual trackTokens calls needed.
Vercel AI SDK Integration
Using Event Names
In the above examples, we used thefeatureId to identify the feature. You can instead use the eventName parameter to link balances to different events in your application. This can be useful when:
- Multiple balances are affected by the same user action
- Different user actions should be tracked against the same balance
Example Use Case:Your AI chatbot has a daily limit of 10 messages, with a maximum monthly limit of 100 messages. Recording a message in Autumn should decrease both balances simultaneously.In Autumn, you can create two features:
daily-messages and monthly-messages. You can add the same event name to both features: message-sent. Then, assign both features to a plan with the correct included amounts.Every time that event name is recorded, both the daily-messages and monthly-messages balances will be decremented.If you were to use the same feature for both in this case, the daily and monthly balances would sum, allowing the user to send 10 messages a day, with an “overage” balance of 100 messages per month if they go over the daily limit.- Go to the Features Page.
- Click on the feature you want to add an event to.
- In the sheet, under the “advanced” section, add your event names.
- Save the feature.