Skip to content

Estimate API

POST /v1/estimate calculates the price of a generation from the model and the input. It uses the same calculation as the Playground, and the server calculates the final charge. It needs no API key, and the request body is limited to 256 KiB. The full schema is in the OpenAPI definition.

The body is JSON:

  • model (required): the model ID in vendor/model form, for example sakuranbo/cherryimage-1.0-pro.
  • input (optional): the generation input. Only the values that affect the price are read, and values you leave out use the model defaults. The input fields of each model are listed on its model page.
Terminal window
curl -X POST "https://api.sakuranbo.ai/v1/estimate" \
-H "Content-Type: application/json" \
-d '{
"model": "sakuranbo/cherryimage-1.0-pro",
"input": {
"resolution": "2k"
}
}'

Two optional fields help with estimates:

  • Text models accept prompt_tokens, an integer from 0 up to the context length of the model. Without it, the input size is approximated from messages. A value that is not an integer, or that is outside this range, returns 400; it is never approximated or corrected silently.
  • Image models accept n, the number of images, as an integer within the range listed on the model page. The default is 1. A value outside the range returns 400.

The response has object: "estimate", the model, currency (USD), the total as total_micro_usd and total_usd, a lines array with one entry per price dimension, and an assumptions array that explains the basis of the estimate.

{
"object": "estimate",
"model": "sakuranbo/cherryimage-1.0-pro",
"currency": "USD",
"total_micro_usd": 90000,
"total_usd": "0.09",
"lines": [
{
"dimension": "output_image",
"unit": "per_image",
"quantity": 1,
"unit_price_micro_usd": 90000,
"unit_price_usd": "0.09",
"amount_micro_usd": 90000,
"amount_usd": "0.09",
"conditions": {
"resolution": "2k"
}
}
],
"assumptions": [
"Failed, cancelled, expired, and policy-rejected generations are not billed, except in the rare case where it cannot be confirmed that the request reached the model provider. The reserved amount then stays reserved until it is confirmed whether the request is billed."
]
}

For text models the output side is estimated at max_tokens, the most the model can produce. The input side uses prompt_tokens when you send it, and an approximation from messages when you do not, so the total is not guaranteed to be an upper bound. To treat the total as an upper bound, send prompt_tokens with the real input token count. Failed, cancelled, and policy-rejected generations are not billed. The exception is a chat stream that breaks after the model has started generating output (including reasoning output): the output generated is billed. See Chat.

  • 400 invalid_request: the body is not valid JSON, a field has the wrong type, or an input value is out of range. error.param names the field. error.details.allowed lists the accepted values when they are a fixed set, and error.details.minimum and error.details.maximum give the limits when the value is a number.
  • 404 model_not_found: the model ID is not in the catalog.
  • 413 payload_too_large: the body is larger than 256 KiB.

See Errors for the complete list.