Hi OpenAI community! I've noticed a discrepancy between my calculated cost for a gpt-3.5-turbo-0125 model usage and what's shown in my billing data, and I'm looking for insights.
Code snippet for cost calculation:
// OpenAI API call
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo-0125",
messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userPrompt }],
max_tokens: Math.min(Math.max(characterCount / 4, 100), 4096),
n: 1,
});
console.log({ usage: response.usage });
// Cost calculation
function calculateOpenAICost(promptTokens: number, completionTokens: number): string {
const inputCost = 0.0005, outputCost = 0.0015; // Cost per 1000 tokens
const totalCost = ((promptTokens + completionTokens) / 1000) * (inputCost + outputCost);
return totalCost.toFixed(6);
}
console.log(`Total Cost: $${calculateOpenAICost(138, 18)}`); // Outputs $0.000096
Pricing details:
- Input tokens: $0.0005 / 1K tokens
- Output tokens: $0.0015 / 1K tokens
Billing discrepancy:
- Expected cost: $0.000096 (for 138 prompt tokens and 18 completion tokens)
- Billed amount: $0.01065 (from billing data export)
{
"timestamp": 1708992000.0,
"currency": "usd",
"GPT-4 Turbo": 0.0,
"GPT-4": 0.0,
"GPT-3.5 Turbo": 0.01065,
"Assistants API": 0.0,
"Fine-tuning models": 0.0,
"Embedding models": 0.0,
"Base models": 0.0,
"Image models": 0.0,
"Audio models": 0.0
}
I'm puzzled by the discrepancy between the calculated cost and the billed amount. Is there an aspect I'm overlooking, such as additional fees not covered in the token cost calculation? Any advice or insights would be much appreciated!