Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
在调用模型前,将模型目录中的价格与端点计费单位(如 Token、图片、音频时长或任务数量)结合起来,估算 CometAPI 请求成本。
import math import os prompt = "Write a short product description for CometAPI." max_output_tokens = 200 input_price_per_1m = float(os.environ["MODEL_INPUT_PRICE_PER_1M"]) output_price_per_1m = float(os.environ["MODEL_OUTPUT_PRICE_PER_1M"]) estimated_input_tokens = math.ceil(len(prompt) / 4) estimated_cost = ( estimated_input_tokens * input_price_per_1m + max_output_tokens * output_price_per_1m ) / 1_000_000 print(f"Estimated maximum cost: ${estimated_cost:.6f}")
Estimated maximum cost: $0.000123
curl https://api.cometapi.com/v1/chat/completions \ -H "Authorization: Bearer $COMETAPI_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "your-model-id", "messages": [ { "role": "user", "content": "Write a short product description for CometAPI." } ], "max_completion_tokens": 200 }'
{ "usage": { "prompt_tokens": 10, "completion_tokens": 42, "total_tokens": 52 } }
const taskCount = 3; const pricePerTask = Number(process.env.MODEL_PRICE_PER_TASK); const estimatedCost = taskCount * pricePerTask; console.log(`Estimated maximum cost: $${estimatedCost.toFixed(4)}`);
Estimated maximum cost: $0.4500
max_completion_tokens