POST /v1/estimate は、モデルと入力から生成の料金を計算します。Playground と同じ計算を使い、最終的な請求額はサーバーが計算します。API キーは不要で、リクエスト本文は 256 KiB までです。完全なスキーマは、OpenAPI 定義にあります。
本文は JSON です。
model(必須):vendor/model形式のモデル ID です。例:sakuranbo/cherryimage-1.0-pro。input(任意): 生成の入力です。価格に影響する値だけを読み、省略した値にはモデルの既定値を使います。各モデルの入力フィールドは、モデルのページに載せています。
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())見積に役立つ任意のフィールドが 2 つあります。
- テキストモデルは
prompt_tokensを受け付けます。0 以上でモデルの文脈長以下の整数を指定します。省略すると、入力の大きさをmessagesから概算します。整数でない値や範囲外の値は400になり、概算や補正に黙って切り替えることはありません。 - 画像モデルは、画像の枚数を表す
nを受け付けます。モデルのページに載せた範囲の整数を指定します。既定は 1 です。範囲外の値は400になります。
レスポンスには、object: "estimate"、model、currency(USD)、合計の total_micro_usd と total_usd、価格の項目ごとに 1 件の lines 配列、見積の前提を説明する assumptions 配列が入ります。
{ "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." ]}テキストモデルでは、出力側を max_tokens(モデルが出力できる最大のトークン数)として見積もります。入力側は、prompt_tokens を渡せばその値を使い、渡さなければ messages からの概算になるため、合計は上限を保証しません。合計を上限として使うときは、実際の入力トークン数を prompt_tokens で渡してください。失敗・キャンセル・コンテンツポリシーによる拒否の生成は課金されません。例外は、モデルが出力(推論の出力を含みます)を生成し始めたあとに途切れたチャットのストリーミングで、生成された出力が課金されます。チャットを参照してください。
400invalid_request: 本文が JSON として不正、フィールドの型が違う、または入力値が範囲外です。error.paramにフィールド名が入ります。指定できる値が決まっているときはerror.details.allowedに一覧が入り、数値のときはerror.details.minimumとerror.details.maximumに許容範囲が入ります。404model_not_found: モデル ID がカタログにありません。413payload_too_large: 本文が 256 KiB を超えています。
すべてのコードは、エラーを参照してください。
価格はすべて USD 表示です。表示価格には当社のマージンを含みます。