Skip to main content
Record the calls that your app makes through OpenRouter, and see their tokens, latency, and cost in AI observability. Use the Agent SDK with the Vercel AI SDK, or post events from any language with HTTP batch ingest.

What you need

  • An OpenRouter API key in OPENROUTER_API_KEY.
  • Your Squasher ingest key and project ID in SQUASHER_API_KEY and SQUASHER_PROJECT_ID. See Create an ingest key.

Record calls with the Agent SDK

1

Install the packages

2

Wrap the AI SDK and call a model

src/ai.ts
usage: { include: true } asks OpenRouter to return the cost of the call. The SDK reads it from providerMetadata.openrouter.usage.cost.
3

Check the call in Squasher

Select AI observability in the sidebar, then the Requests tab. The provider is openrouter, and the model is the full OpenRouter model name, such as openai/gpt-4.1-nano.
In a long-running server, you do not need ai.flush() after each call. For all SDK options, see the Agent SDK.

Send events with HTTP batch ingest

Without an SDK, post a batch of JSON events. Each event has an id, a type, a timestamp, and a body. The format follows the Langfuse ingestion API.
Squasher answers 207 with a successes list when it accepts the batch. The project ID in the URL must be the project of the key. Fields of a generation body:

How Squasher counts cost

When the call reports its cost, Squasher uses it. Otherwise, Squasher computes the cost from the token counts and a public price list, which it updates every 24 hours. Models that are not on the list have a cost of 0.

Limits

  • score-create events are not supported in HTTP batch ingest. Squasher answers 201 for them but drops them. Send scores with the Agent SDK.
  • A costDetails total of 0 counts as no cost, and Squasher computes the cost instead.
  • The key goes in the x-squasher-key header. Never put it in the URL.

Next steps

AI observability

Read cost, latency, and sessions in the dashboard.

Agent SDK

All options, scores, and privacy settings.