{"id":"ai.cost.estimate","module":"ai-runtime","namespace":"ai","action":"cost.estimate","method":"POST","path":"/v1/ai/cost/estimate","idempotent":false,"available":true,"vendors":[],"vendors_ready":[],"vendors_pending":[],"key_status":"live","default_vendor":null,"self_hosted":true,"minimum_tier":"standard","supported_message_classes":null,"regions":["western","china"],"dynamic_params":{},"models_tracked":false,"sdk_hint":"Regular parameters + types are stable — read them from the typed SDK signature / API reference for this capability. discovery only carries the runtime-dynamic values above (available, vendors, dynamic_params).","params":{"title":"CostEstimateRequest","description":"Request shape for ai.cost.estimate (single model) and ai.cost.compare (models[] for multi-model comparison). Unknown model_id MUST raise MODEL_NOT_FOUND (no silent fallback). See docs/Infrai_SDK_AI_Runtime.md §1.6.","type":"object","required":["messages"],"additionalProperties":false,"properties":{"messages":{"type":"array","minItems":1,"items":{"title":"ChatMessage","type":"object","required":["role"],"additionalProperties":false,"properties":{"role":{"enum":["system","user","assistant","tool"],"description":"Role of the message author (system, user, assistant, tool)"},"content":{"oneOf":[{"type":"string"},{"type":"array"},{"type":"null"}],"description":"DNS record value/content"},"name":{"type":"string","description":"Human-readable name for this resource"},"tool_calls":{"type":"array","items":{"title":"ToolCall","type":"object","required":["id","type","function"],"additionalProperties":false,"properties":{"id":{"type":"string","description":"Unique identifier for this resource"},"type":{"const":"function","description":"Type discriminator for this resource"},"function":{"type":"object","required":["name","arguments"],"additionalProperties":false,"properties":{"name":{"type":"string"},"arguments":{"type":"string","description":"JSON-encoded string."}},"description":"Function definition for tool calling"}}},"description":"Tool/function calls requested by the model"},"tool_call_id":{"type":"string","description":"Present when role='tool'."}}},"description":"Chat messages to price (same shape as ai.chat); cost is estimated from their token count."},"model":{"type":["string","null"],"default":"openai/gpt-4o","description":"Single model to estimate. Used by ai.cost.estimate. Explicit model_id is allowed here (selection semantics)."},"models":{"type":["array","null"],"items":{"type":"string"},"description":"Models to compare. Used by ai.cost.compare; result is sorted ascending by final cost."},"expected_output_tokens":{"type":"integer","minimum":0,"default":500,"description":"Assumed completion length for the estimate."},"cache_strategy":{"enum":["vendor","infrai","none"],"default":"vendor","description":"Cache strategy hint (none, exact, semantic)"},"batch_mode":{"type":"boolean","default":false,"description":"When true, applies the 50% batch discount to the estimate."},"tools":{"type":["array","null"],"items":{"type":"object"},"description":"Tool/function definitions for the model to call"}}},"response":{"title":"CostEstimate","description":"Pre-send cost estimate for one model. ai.cost.estimate returns one; ai.cost.compare returns an array sorted ascending by breakdown.final. See docs/Infrai_SDK_AI_Runtime.md §1.6.","type":"object","required":["model","vendor","prompt_tokens","expected_output_tokens","breakdown"],"additionalProperties":false,"properties":{"model":{"type":"string","description":"Resolved model_id this estimate is for."},"vendor":{"type":"string","description":"Vendor that would serve the request."},"vendor_region":{"enum":["china","western"],"description":"Region of the serving vendor (drives markup)."},"prompt_tokens":{"type":"integer","minimum":0,"description":"Number of tokens in the prompt"},"expected_output_tokens":{"type":"integer","minimum":0,"description":"Estimated number of output tokens"},"breakdown":{"description":"Cost breakdown by component","title":"CostBreakdown","type":"object","required":["final","currency"],"additionalProperties":false,"properties":{"currency":{"enum":["USD","CNY"],"description":"ISO 4217 currency code (e.g. USD, CNY)"},"input_cost":{"type":"number","minimum":0,"description":"Input token cost in USD"},"output_cost":{"type":"number","minimum":0,"description":"Output token cost in USD"},"markup":{"type":"number","minimum":0,"description":"Markup applied on top of vendor cost"},"cache_discount":{"type":"number","minimum":0,"description":"Discount from cache hits in USD"},"batch_discount":{"type":"number","minimum":0,"description":"Discount for batch processing in USD"},"failover_adjustment":{"type":"number","description":"Cost adjustment due to vendor failover"},"final":{"type":"number","minimum":0,"description":"Final cost after all adjustments in USD"}}}}},"errors":["ACCOUNT_AUTORECHARGE_LIMIT","ACCOUNT_FROZEN","AUTH_RATE_LIMIT","AUTH_REFRESH_TOO_FREQUENT","BATCH_REJECTED","CAPABILITY_DEGRADED_NOT_ALLOWED","CONTENT_FILTERED","CONTEXT_WINDOW_EXCEEDED","FAILOVER_COST_EXCEEDED","IDEMPOTENCY_KEY_CONFLICT","INSUFFICIENT_CREDIT","INTERNAL_ERROR","INVALID_ARGUMENT","INVALID_MESSAGE_SCHEMA","INVALID_RESPONSE_FORMAT","INVALID_TOOL_SCHEMA","KEY_REVOKED","MAINTENANCE","MODEL_DEPRECATED","MODEL_NOT_AVAILABLE","MODEL_NOT_FOUND","MODEL_NO_IMAGE_INPUT","MODEL_QUOTA_EXCEEDED","NETWORK_ERROR","NO_HEALTHY_KEY","NO_HEALTHY_VENDOR","RATE_LIMIT_ACCOUNT","RATE_LIMIT_USER","RATE_LIMIT_VENDOR","SCOPE_INSUFFICIENT","STREAM_INTERRUPTED","UNAUTHORIZED","VENDOR_AUTH_ERROR","VENDOR_DOWN","VENDOR_KEY_DUPLICATE","VENDOR_KEY_INVALID","VENDOR_KEY_NOT_FOUND","VENDOR_NOT_CONFIGURED","VENDOR_REQUEST_FAILED","VENDOR_REQUEST_INVALID","VENDOR_RESPONSE_INVALID","VENDOR_TIMEOUT","WALLET_EXPIRED"],"examples":{"curl":"curl -X POST https://api.infrai.cc/v1/ai/cost/estimate \\\n  -H \"Authorization: Bearer $INFRAI_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"messages\": [{\"role\": \"system\"}]}'","python":"# Zero-install REST call — no SDK required (short-term the API is REST-only).\nimport os, requests\n\nresp = requests.post(\n    \"https://api.infrai.cc/v1/ai/cost/estimate\",\n    headers={\n        \"Authorization\": f\"Bearer {os.environ['INFRAI_API_KEY']}\",\n    },\n    json={'messages': [{'role': 'system'}]},\n)\nresp.raise_for_status()\nprint(resp.json())","javascript":"// Zero-install REST call — no SDK required (short-term the API is REST-only).\nconst resp = await fetch(\n  \"https://api.infrai.cc/v1/ai/cost/estimate\",\n  {\n    method: \"POST\",\n    headers: {\n      \"Authorization\": `Bearer ${process.env.INFRAI_API_KEY}`,\n      \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\"messages\": [{\"role\": \"system\"}]}),\n  },\n);\nconsole.log(await resp.json());","typescript":"// Zero-install REST call — no SDK required (short-term the API is REST-only).\nconst resp = await fetch(\n  \"https://api.infrai.cc/v1/ai/cost/estimate\",\n  {\n    method: \"POST\",\n    headers: {\n      \"Authorization\": `Bearer ${process.env.INFRAI_API_KEY}`,\n      \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\"messages\": [{\"role\": \"system\"}]}),\n  },\n);\nif (!resp.ok) throw new Error(`infrai ${resp.status}`);\nconst data: unknown = await resp.json();\nconsole.log(data);","go":"// Zero-install REST call — no SDK required (short-term the API is REST-only).\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n)\n\nfunc main() {\n\tbody := []byte(`{\"messages\": [{\"role\": \"system\"}]}`)\n\treq, _ := http.NewRequest(\"POST\", \"https://api.infrai.cc/v1/ai/cost/estimate\", bytes.NewReader(body))\n\treq.Header.Set(\"Authorization\", \"Bearer \"+os.Getenv(\"INFRAI_API_KEY\"))\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\tresp, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer resp.Body.Close()\n\tfmt.Println(resp.Status)\n}","java":"// Zero-install REST call — no SDK required (short-term the API is REST-only).\nimport java.net.URI;\nimport java.net.http.*;\n\nHttpRequest req = HttpRequest.newBuilder()\n    .uri(URI.create(\"https://api.infrai.cc/v1/ai/cost/estimate\"))\n    .header(\"Authorization\", \"Bearer \" + System.getenv(\"INFRAI_API_KEY\"))\n    .header(\"Content-Type\", \"application/json\")\n    .method(\"POST\", HttpRequest.BodyPublishers.ofString(\"{\\\"messages\\\": [{\\\"role\\\": \\\"system\\\"}]}\"))\n    .build();\nHttpResponse<String> resp = HttpClient.newHttpClient()\n    .send(req, HttpResponse.BodyHandlers.ofString());\nSystem.out.println(resp.body());","csharp":"// Zero-install REST call — no SDK required (short-term the API is REST-only).\nusing System;\nusing System.Net.Http;\n\nvar client = new HttpClient();\nvar req = new HttpRequestMessage(new HttpMethod(\"POST\"), \"https://api.infrai.cc/v1/ai/cost/estimate\");\nvar key = Environment.GetEnvironmentVariable(\"INFRAI_API_KEY\");\nreq.Headers.Add(\"Authorization\", \"Bearer \" + key);\nreq.Content = new StringContent(\"{\\\"messages\\\": [{\\\"role\\\": \\\"system\\\"}]}\", System.Text.Encoding.UTF8, \"application/json\");\nvar resp = await client.SendAsync(req);\nConsole.WriteLine(await resp.Content.ReadAsStringAsync());","php":"<?php\n// Zero-install REST call — no SDK required (short-term the API is REST-only).\n$ch = curl_init(\"https://api.infrai.cc/v1/ai/cost/estimate\");\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"POST\");\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\ncurl_setopt($ch, CURLOPT_HTTPHEADER, [\n    \"Authorization: Bearer \" . getenv(\"INFRAI_API_KEY\"),\n    \"Content-Type: application/json\",\n]);\ncurl_setopt($ch, CURLOPT_POSTFIELDS, \"{\\\"messages\\\": [{\\\"role\\\": \\\"system\\\"}]}\");\n$response = curl_exec($ch);\ncurl_close($ch);\necho $response;","ruby":"# Zero-install REST call — no SDK required (short-term the API is REST-only).\nrequire \"net/http\"\nrequire \"uri\"\n\nuri = URI(\"https://api.infrai.cc/v1/ai/cost/estimate\")\nhttp = Net::HTTP.new(uri.host, uri.port)\nhttp.use_ssl = true\nreq = Net::HTTP::Post.new(uri)\nreq[\"Authorization\"] = \"Bearer #{ENV['INFRAI_API_KEY']}\"\nreq[\"Content-Type\"] = \"application/json\"\nreq.body = '{\"messages\": [{\"role\": \"system\"}]}'\nres = http.request(req)\nputs res.body","rust":"// Zero-install REST call — no SDK required (short-term the API is REST-only). (uses the reqwest + tokio crates)\nuse std::env;\n\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    let resp = reqwest::Client::new()\n        .post(\"https://api.infrai.cc/v1/ai/cost/estimate\")\n        .header(\"Authorization\", format!(\"Bearer {}\", env::var(\"INFRAI_API_KEY\")?))\n        .header(\"Content-Type\", \"application/json\")\n        .body(r#\"{\"messages\": [{\"role\": \"system\"}]}\"#)\n        .send()\n        .await?;\n    println!(\"{}\", resp.text().await?);\n    Ok(())\n}","request":{"messages":[{"role":"system"}]}},"billing":{"is_billable":false,"free":true,"billing_class":"free","unit":"per_call","note":"free (rate-limited); does NOT consume the new-account trial"}}