Instrumentation
Cost & tokens
Pass token usage and Currai computes cost, rolled up per generation, trace, model, and day.
Pass token usage on a generation and Currai turns it into cost — per generation, then rolled up per trace, model, user, and day. Stop guessing what a feature costs and start watching it on a dashboard.
Reporting usage
Pass a usage object to end() with the token counts from your provider's response:
generation.end({
output: completion.choices[0].message.content,
usage: {
input: completion.usage.prompt_tokens,
output: completion.usage.completion_tokens,
total: completion.usage.total_tokens,
unit: "TOKENS",
},
});generation.end(
output=completion.choices[0].message.content,
usage={
"input": completion.usage.prompt_tokens,
"output": completion.usage.completion_tokens,
"total": completion.usage.total_tokens,
"unit": "TOKENS",
},
)input and output are enough — Currai computes total if you omit it.
Usage units
unit describes what you're counting. The supported units are:
| Unit | Use for |
|---|---|
TOKENS | Most text models (the common case). |
CHARACTERS | Character-billed models. |
SECONDS | Audio / realtime models billed by time. |
MILLISECONDS | Sub-second time-billed models. |
REQUESTS | Flat per-request pricing. |
IMAGES | Image generation. |
How cost is computed
Currai matches each generation's model against a built-in, editable model price table and multiplies usage by the per-unit price. You don't compute cost yourself — report usage and the model name, and Currai does the rest.
Costs then roll up automatically:
- per generation — the cost of that single call;
- per trace — the sum across its generations;
- per model, user, and day — for dashboards and budgets.
