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.
Request
Section titled “Request”The body is JSON:
model(required): the model ID invendor/modelform, for examplesakuranbo/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.
curl -X POST "https://api.sakuranbo.ai/v1/estimate" \ -H "Content-Type: application/json" \ -d '{ "model": "sakuranbo/cherryimage-1.0-pro", "input": { "resolution": "2k" }}'const response = await fetch("https://api.sakuranbo.ai/v1/estimate", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ "model": "sakuranbo/cherryimage-1.0-pro", "input": { "resolution": "2k" } }),});const data = await response.json();console.log(data);import requests
response = requests.post( "https://api.sakuranbo.ai/v1/estimate", json={ "model": "sakuranbo/cherryimage-1.0-pro", "input": { "resolution": "2k", }, },)print(response.json())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 frommessages. A value that is not an integer, or that is outside this range, returns400; 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 returns400.
Response
Section titled “Response”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.
Errors
Section titled “Errors”400invalid_request: the body is not valid JSON, a field has the wrong type, or an input value is out of range.error.paramnames the field.error.details.allowedlists the accepted values when they are a fixed set, anderror.details.minimumanderror.details.maximumgive the limits when the value is a number.404model_not_found: the model ID is not in the catalog.413payload_too_large: the body is larger than 256 KiB.
See Errors for the complete list.
All prices are in USD. Listed prices include our margin.