Measuring Cost per Request
You'll learn how to calculate the actual dollar amount each AI request costs your system, from inputs to outputs.
Understanding the Cost Formula
Every time you call an AI model API, you're charged based on tokens—the chunks of text the model processes. Your total cost per request depends on three main factors:
- Prompt length (input tokens): How much text you send to the model
- Completion length (output tokens): How much text the model generates back
- Model pricing: Different models charge different rates per token
Think of it like a phone call: you pay more for longer conversations (tokens) and premium services (advanced models) cost more per minute.
Calculating a Single Request
Here's the basic math:
Cost = (prompt_tokens × input_price) + (completion_tokens × output_price)
For example, if a model charges 0.03 per 1,000 output tokens:
- 500 input tokens = $0.005
- 200 output tokens = $0.006
- Total request cost = $0.011
Why This Matters
When you multiply one request by thousands or millions of users, small differences add up fast. A request costing 1,000.
Model selection impact is huge: GPT-4 might cost 10-30× more than GPT-3.5 per request. You need to measure if that quality improvement justifies the cost for your use case.
Prompt engineering also matters: a verbose 1,000-token prompt costs double what a streamlined 500-token version does, every single time.
Key Takeaway: Calculate cost per request by multiplying your prompt and completion token counts by their respective model prices—this metric scales directly with your user volume and determines your system's economic viability.