OpenAI API Cost Calculator
Calculate OpenAI API costs for GPT-4o, GPT-4, o1, and other models. Estimate daily, monthly, and yearly spending from token counts and request volumes.
OpenAI API Cost Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: Cost = (Input Tokens / 1,000,000) x Input Price + (Output Tokens / 1,000,000) x Output Price
Worked example โ Monthly API cost: $75.00 | Cost per request: ~$0.005 (half a cent)
Formula
Cost = (Input Tokens / 1,000,000) x Input Price + (Output Tokens / 1,000,000) x Output Price
OpenAI charges per million tokens with separate rates for input and output. Input tokens include your prompt, system message, and context. Output tokens are the model response. Prices vary by model, with GPT-4o Mini being the most affordable and GPT-4 the most expensive.
Worked Examples
Example 1: Startup Chatbot Monthly Cost
Problem:A startup runs a customer support chatbot using GPT-4o with 500 requests per day, averaging 800 input tokens and 300 output tokens per request.
Solution:Daily input tokens = 500 x 800 = 400,000 Daily output tokens = 500 x 300 = 150,000 Daily input cost = (400,000 / 1,000,000) x $2.50 = $1.00 Daily output cost = (150,000 / 1,000,000) x $10.00 = $1.50 Daily total = $2.50 Monthly cost = $2.50 x 30 = $75.00
Result:Monthly API cost: $75.00 | Cost per request: ~$0.005 (half a cent)
Example 2: Enterprise Document Processing
Problem:An enterprise processes 2,000 documents daily using GPT-4 Turbo, with 3,000 input tokens (document + prompt) and 500 output tokens per request.
Solution:Daily input tokens = 2,000 x 3,000 = 6,000,000 Daily output tokens = 2,000 x 500 = 1,000,000 Daily input cost = (6,000,000 / 1,000,000) x $10.00 = $60.00 Daily output cost = (1,000,000 / 1,000,000) x $30.00 = $30.00 Daily total = $90.00 Monthly = $2,700 | Yearly = $32,850
Result:Monthly cost: $2,700 | The same volume on GPT-4o costs $25.00/day, or $750/month, saving ~$1,950/month (72% reduction)
Frequently Asked Questions
How does OpenAI API pricing work for different models?
OpenAI charges per token processed, with separate rates for input tokens (your prompts and context) and output tokens (the model responses). Pricing varies dramatically across models: GPT-4o costs $2.50 per million input tokens and $10.00 per million output tokens, while GPT-4 costs $30.00 and $60.00 respectively, making it 12 times more expensive for input. GPT-4o Mini is the most affordable option at $0.15 per million input tokens. One token is approximately 4 characters or about three-quarters of a word in English. System prompts, conversation history, and function definitions all count as input tokens, which is why costs can increase rapidly with long conversations.
What is the difference between input tokens and output tokens in cost?
Input tokens are the tokens you send to the API, including your system prompt, user message, conversation history, function definitions, and any retrieved context. Output tokens are what the model generates in response. Output tokens are consistently more expensive than input tokens across all models, typically costing 2 to 4 times more. This is because generating tokens requires more computational resources than processing them. For GPT-4o, output tokens cost 4 times more than input tokens. This means optimizing your prompts to elicit concise responses can significantly reduce costs. Techniques like asking for structured JSON output or setting max_tokens limits can help control output token spending.
How can I estimate my monthly API costs before deploying?
To estimate monthly costs, first profile your typical request by counting tokens in a sample prompt and response using the tiktoken library or the OpenAI tokenizer tool. Multiply the average input and output tokens per request by your expected daily request volume, then multiply by 30 days. Include hidden token costs like system prompts repeated in every request, conversation history that grows with each turn, and function or tool definitions. A common mistake is underestimating input tokens because developers forget that the full conversation context is sent with each message. Add a 20 to 30 percent buffer for variability in response lengths and unexpected usage spikes during peak periods.
What strategies can reduce OpenAI API costs significantly?
Several strategies can dramatically reduce API costs. First, use the cheapest model that meets quality requirements: on the rates in the table above, GPT-4o Mini bills $0.15 per million input tokens against GPT-4's $30.00, and $0.60 against $60.00 for output, so a like-for-like workload costs roughly one two-hundredth as much on input and one hundredth on output. Second, implement prompt caching by using shorter, optimized prompts and storing reusable system instructions. Third, limit conversation history to recent messages rather than sending the full chat log with each request. Fourth, set max_tokens to prevent unnecessarily long responses. Fifth, use streaming to let users see partial results and cancel early. Sixth, implement a tiered approach where simple queries go to cheaper models and only complex ones escalate to GPT-4o. Batch processing non-urgent requests can also qualify for discounted rates at up to 50 percent off standard pricing.
How do reasoning models like o1 compare to GPT-4o in cost?
Reasoning models such as o1 and o3-mini are designed for complex multi-step problem solving and carry higher per-token costs than standard chat models. The o1 model charges $15.00 per million input tokens and $60.00 per million output tokens, which is 6 times more expensive than GPT-4o for input. However, reasoning models often produce better results on the first attempt for complex tasks, potentially reducing the number of retries needed. The o3-mini model offers a more affordable reasoning option at $1.10 input and $4.40 output per million tokens. For most standard chat, summarization, and classification tasks, GPT-4o or GPT-4o Mini provides the best balance of quality and cost efficiency.
What counts as an input token besides my user message?
Everything in the request body that the model reads. The system prompt, every earlier turn of the conversation, the JSON schemas of any tools or functions you declare, few-shot examples, and passages injected by a retrieval step all bill at the input rate. Images sent to a vision-capable model are converted into a token count derived from their dimensions and the detail setting. Tool schemas catch people out most often: a dozen function definitions can add a thousand input tokens to every single call.
How do I count tokens exactly before sending a request?
Use the tiktoken library locally and select the encoding that matches the model - cl100k_base for the GPT-4 and GPT-3.5 Turbo generation, o200k_base for GPT-4o. Encode the exact string you intend to send and take its length. For chat completions, add the small fixed overhead per message that the API inserts for role and delimiter tokens. Counting locally is free and is the only way to fill the average-token fields above with measured numbers instead of the four-characters-per-token rule of thumb.
What is the difference between max_tokens and the context window?
The context window bounds prompt and completion together; max_tokens caps only the completion. With a 128,000-token window and 120,000 tokens of context sent, at most 8,000 remain for the reply regardless of what max_tokens is set to. Because output bills at several times the input rate, setting max_tokens is the cheapest guard against runaway generation cost. Set it too low, though, and responses truncate mid-sentence while you still pay for every token that was produced.
Does streaming a response change what I pay?
No. Billing follows tokens generated, not how they are delivered, so a streamed reply and a buffered one of identical length cost exactly the same. What streaming adds is the option to stop early: closing the connection halts generation, so you are charged only for the tokens produced up to that moment. That is a real saving in interactive interfaces, where users frequently have what they need after the first couple of sentences of a long answer.
How do rate limits interact with cost planning?
Rate limits govern throughput rather than price. They are published as requests per minute and tokens per minute for your usage tier, so they cap how fast you can spend, not what a token costs. The cost connection is retries: a call refused with HTTP 429 before any processing generates no tokens and no charge, but a client that times out after the model has already started generating and then retries pays for both attempts. Use exponential backoff and generous client timeouts.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎLLM API Cost Comparator
Compare API costs across GPT-4o, Claude, Gemini, Llama, and Mistral by token count and use case.
๐งฎChatGPT Plus vs API Cost Calculator
Calculate when ChatGPT Plus subscription is cheaper vs paying per API token.
๐งฎClaude API Cost Calculator
Calculate Anthropic Claude API costs from input tokens, output tokens, and model tier.
๐งฎBatch Inference Cost Calculator
Calculate cost savings of batch vs real-time API inference from volume and latency tolerance.
๐งฎAPI Rate Limit Calculator
Calculate required API rate limits from expected users, requests per user, and peak multiplier.
๐งฎAI Video Generation Cost Calculator
Estimate costs for AI video generation across Sora, Runway, Pika, and Kling by duration.
๐งฎAI Voice Cloning Cost Calculator
Compare voice cloning and TTS costs across ElevenLabs, PlayHT, and Resemble AI.
๐งฎAI Chatbot Cost Calculator
Estimate monthly costs of running an AI chatbot from conversation volume and model choice.