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:

UnitUse for
TOKENSMost text models (the common case).
CHARACTERSCharacter-billed models.
SECONDSAudio / realtime models billed by time.
MILLISECONDSSub-second time-billed models.
REQUESTSFlat per-request pricing.
IMAGESImage 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.

Next: group traces by session and user.