Skip to main content

Request cost

GET https://api.entrim.ai/v1/generation?id={x-request-id}

Returns the exact amount billed for one request. It is most useful for a stream that ended before its usage block arrived, for example when the user stopped the generation.

Get the request ID​

Every response carries an x-request-id header. It is sent before the first token, so you have it even if the stream is cut off at once. Keep it with the request.

Example request​

curl "https://api.entrim.ai/v1/generation?id=$REQUEST_ID" \
-H "Authorization: Bearer $ENTRIM_API_KEY"

Use any active Model API key of the account that made the request. A request appears about a minute after it ends.

Example response​

{
"data": {
"id": "0f6f3c1e8a7d4b52a9c1d2e3f4a5b6c7",
"model": "zai-org/GLM-5.3-Flash",
"created_at": "2026-11-09T14:00:00.000Z",
"status": "success",
"tokens_prompt": 1205,
"tokens_completion": 100,
"tokens_cached": 200,
"tokens_cache_write": 5,
"total_cost": "0.000398",
"cost_details": {
"input": "0.0003",
"cache_read": "0.000006",
"cache_write": "0.000002",
"output": "0.00009"
}
}
}

Response fields​

FieldTypeDescription
idstringThe request ID you asked for
modelstringThe model that was billed
created_atstringWhen the request started, in UTC
statusstringsuccess or failure
tokens_promptintegerAll input tokens, including cached ones
tokens_completionintegerOutput tokens, including reasoning
tokens_cachedintegerInput tokens read from the cache
tokens_cache_writeintegerInput tokens written to the cache
total_coststringThe amount billed, in USD
cost_detailsobject or nullThe amount by kind of token, in USD. input covers only the input tokens not read from or written to the cache. The four parts add up to total_cost exactly. It is null in the rare case the split cannot be shown; total_cost is still exact

Amounts are strings so that no digits are lost. Parse them with a decimal type, not a float.

Streams that were cut off​

If output was generated before the connection dropped, you are billed for that output and for the prompt. The model never reports usage for such a stream, so we count the tokens ourselves and bill the whole prompt at the input rate, with no cached tokens.

If no output was generated, the request is not billed and the lookup returns 404.

Errors​

StatusCodeMeaning
400invalid_idThe id parameter is missing or too long
401missing_api_key, invalid_api_keyThe key is missing, revoked or not a Model API key
404not_foundNo billed request of your account has this ID. It may still be on its way, so try again after a minute. If it is still missing after that, the request was not charged
409ambiguous_idYour account used this ID on more than one request
429rate_limitedMore than 1,200 lookups in a minute with this key. Wait for retry_after_seconds

Requests can be looked up for 90 days.