Skip to main content
The @useautumn/gateway package integrates Autumn with the OpenRouter SDK, automatically tracking token usage for every chat.send call. No manual trackTokens calls needed.
Using OpenRouter through the Vercel AI SDK (@openrouter/ai-sdk-provider)? Use the AI SDK wrapper with providerId: "openrouter" instead.

Setup

1. Install the package

Requires autumn-js and @openrouter/sdk as peer dependencies.

2. Wrap your client

Use withAutumn to wrap your OpenRouter client. It intercepts chat.send calls, enables OpenRouter’s usage accounting on every request, reads the token usage from the response, and reports it to Autumn automatically.

3. Use as normal

The wrapped client works exactly like a regular OpenRouter client — streaming and non-streaming. Token usage is tracked in the background after each call.

Token pools

The wrapper normalizes OpenRouter’s usage accounting into the exclusive token pools that trackTokens expects: text input (excluding cached and audio tokens), text output (excluding reasoning tokens), cache reads, cache writes, audio input, and reasoning tokens. Each pool is billed at the model’s published rate. The model is reported to Autumn as openrouter/<slug> (e.g. openrouter/openai/gpt-4o), using the resolved model from the response — so router aliases like openrouter/auto bill against the model that actually served the request. Autumn prices usage with OpenRouter’s rates from Models.dev, and OpenRouter’s own reported cost is attached to each event as the openrouter_cost property for reconciliation.

Options

Manual tracking

If you consume OpenRouter through a path the wrapper doesn’t cover (e.g. callModel, or raw fetch against the REST API), use trackOpenRouterUsage directly with the response’s usage object — it accepts both the SDK’s camelCase models and the raw snake_case API shape:
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.