Skip to navigation

Trace a model call

Records the model, tokens and cost of one model call, so Runledger can report cost and margin per run. Leave out cost and Runledger prices the call from its model price table, including cache and reasoning tokens. Join calls made in different processes by sending the same run_id. Deduplicated on idempotency_key for 35 days. Send usage_lines for units other than tokens, such as images, video seconds, audio seconds or GPU seconds, each with the dimension values that set its rate. When an active cost model matches the call’s provider and model, Runledger prices every line from its rate card (priced_by: catalog), applies any override of the cost model, and records which version and which source priced it. Send usage, usage_lines, or both for different units. If there is no cost model but the provider price catalog has the model, the call is priced from the catalog’s list price (priced_by: price_table) with the warning catalog_model_available, which names the catalog model to adopt so your own rates apply. With neither, the call is recorded without a cost (priced_by: none).

Authentication

AuthorizationBearer

A secret key (rl_sk_test_..., rl_sk_live_...) or a restricted key with limited scopes (rl_rk_test_..., rl_rk_live_...). A restricted key can carry agent: true and an expires_at, and is what a coding agent should hold. Keys end in a checksum so secret scanners can recognize them. People create, roll and revoke keys in the dashboard; GET /v1/api_keys lists them, masked.

Request

This endpoint expects an object.
idempotency_keystringRequired<=255 characters
Your unique ID for this model call.
providerstringRequired
The model provider.
modelstringRequired
The model ID as the provider names it.
run_idstringOptional
Joins this cost to the run's events. Send the same value from every process.
customer_idstringOptional
external_customer_idstringOptional
agent_idstringOptional
member_idstringOptional
team_idstringOptional
timestampdatetimeOptional
When the call finished. Defaults to now.
usageobjectOptional
usage_lineslist of objectsOptional

Quantities of any unit, with the dimension values that decide each rate. A unit can’t appear both here and in usage.

costobjectOptional

An amount of money that can hold fractions of a minor unit, such as a per-token cost.

metadatamap from strings to stringsOptional
Up to 50 keys of your own, with keys up to 40 characters and values up to 500 characters.

Response

The recorded cost.
idstring
object"cost"
idempotency_keystring
providerstring
modelstring
priced_byenum

request: you sent the cost. price_table: Runledger priced it from the provider price catalog’s list price, because the catalog has the model and no cost model follows it. catalog: Runledger priced it from your cost models, whether their rates come from the provider price catalog, your overrides or rate cards you entered. none: nothing could price it, and the call carries no cost.

Allowed values:
timestampdatetime
livemodeboolean
created_atdatetime
run_idstringOptional
customerstringOptional
agent_idstringOptional
member_idstringOptional
team_idstringOptional
usageobjectOptional
lineslist of objectsOptional
One entry per usage line, with the rate card version that priced it. Present when the call was priced from the cost catalog.
costobjectOptional

The cost of the call. Left out when the call could not be priced: no cost was sent, no cost model or catalog model matched, or no line matched a rate. The warnings say why.

warningslist of objectsOptional

For example rate_not_found when a usage line matched no rate.

metadatamap from strings to stringsOptional
Up to 50 keys of your own, with keys up to 40 characters and values up to 500 characters.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
409
Conflict Error
422
Unprocessable Entity Error
429
Too Many Requests Error
500
Internal Server Error