OverpayingForAIPricing desk

Lesson 7 of 8 · 11 min read · Beginner

OpenAI API quickstart: when per-token beats the subscription

How tokens are billed, a minimal working call to the OpenAI Responses API in curl and Python, and the two features (prompt caching and Batch) that cut the bill.

In this lesson you will

  • Explain how input, output and cached tokens are billed
  • Make a first successful call to the OpenAI Responses API from curl or Python
  • Identify when the API is cheaper than a ChatGPT plan and when it is not

The API is the same models without the chat app. You pay for tokens, nothing else: no monthly fee, no usage cap beyond rate limits, no Projects or memory unless you build them. That makes it the cheapest option for moderate programmatic use and the most expensive option for someone who wants a chat window.

Tokens and the context windowA token is roughly ¾ of an English word. The context window is the maximum tokens the model can hold at once — everything you send plus everything it writes.System prompt + instructionsConversation history + documentsNew answerfreeWhy it costs moneyEvery turn re-sends the whole history. A 40-message chat with a pasted PDF bills that PDF 40 times unless the provider caches it.“1M context” is a ceiling, not a target. Filling it on every request is the fastest way to overpay.rule of thumb: 1,000 tokens ≈ 750 words ≈ 1.5 pages
Figure 1.Every call is billed on input tokens (your prompt, files, prior turns) and output tokens (the reply). Output is priced several times higher than input on every OpenAI text model, so long answers dominate cost.

Token maths in 60 seconds

Prices are quoted per million tokens. At the time of writing our catalogue lists GPT-5.4 mini at $0.75 input and $4.50 output per 1M. A call with 2,000 input tokens and 500 output tokens therefore costs 0.002 × 0.75 + 0.0005 × 4.50, about $0.0038. A thousand such calls is under $4. The same thousand calls on GPT-5.5 ($5 in, $30 out) would be about $25.

In a multi-turn conversation, the whole history is re-sent as input on every turn. That is why long chats get expensive and why starting a fresh conversation for a new topic is a cost decision, not just a tidiness one.

Your first call

Create an API key at platform.openai.com/api-keys, add a small prepaid balance, and set it as an environment variable. The Responses API is OpenAI's current primary endpoint; the older Chat Completions endpoint still works but the examples below use Responses.

bashcurl: one request to the Responses API
export OPENAI_API_KEY="sk-..."

curl https://api.openai.com/v1/responses \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "input": "Rewrite this in one sentence: The meeting that was scheduled for Tuesday has been moved to Thursday at the same time."
  }'
pythonPython: the official openai SDK (pip install openai)
from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from the environment

response = client.responses.create(
    model="gpt-5.4-mini",
    input="Rewrite this in one sentence: The meeting that was scheduled for Tuesday has been moved to Thursday at the same time.",
)

print(response.output_text)
print(response.usage)  # input_tokens, output_tokens, cached tokens

The usage object on every response tells you exactly what you were billed for. Log it from day one. The full reference is at platform.openai.com/docs/api-reference/responses, and current prices are at platform.openai.com/docs/pricing.

Prompt caching

Prompt caching: stop paying full price for the same prefixIf the start of your request is identical each time (system prompt, docs, tool list), the provider can serve it from cache at a fraction of the input price.Request 1Stable prefix — written to cache (full price)new questionRequest 2Stable prefix — cache hit (discounted)new questionRequest 3Stable prefix — cache hit (discounted)new questionRule: put the unchanging parts first, the changing parts last. A timestamp at the top of a system prompt silently kills the cache on every call.
Figure 2.When the start of your prompt (system instructions, reference documents) is identical across calls, OpenAI can serve those tokens from cache at a discounted input rate. It is automatic on repeated prefixes; your job is to keep the stable part at the front and the changing part at the end.

Caching is why the order of your prompt matters. Put the long, unchanging content first (instructions, a policy document, a code file) and the user's question last. Anything before the first change can be cached; anything after it cannot. The mechanics and the current discount are documented at platform.openai.com/docs/guides/prompt-caching.

Batch API

If you do not need the answer now, the Batch API runs jobs asynchronously within a window at a discounted rate. Our catalogue lists batch variants of the main models at half the standard per-token price at the time of writing, for example GPT-5.4 at $1.25 in and $7.50 out per 1M versus $2.50 and $15 standard. The workflow is: upload a JSONL file of requests, submit the batch, download the results. Details at platform.openai.com/docs/guides/batch.

Knowledge check

Which change reduces API cost for an app that sends the same 5,000-token policy document with every user question?

Lesson FAQ

Does ChatGPT Plus include API access?

No. ChatGPT plans and API usage are billed separately. The API needs its own prepaid balance on platform.openai.com.

Is the API cheaper than ChatGPT Plus?

For moderate, programmatic use on a mini model, usually yes by a wide margin. For a person chatting all day on a flagship model, often no. Run your numbers at /compare/subscription-vs-api-ai-cost.

Which endpoint should I use, Responses or Chat Completions?

Responses is OpenAI's current primary API and the one new features land on. Chat Completions still works and is widely supported by third-party tools. Either is fine for a first project.

Finished reading?

Mark it done to track your progress through the course.

Compare, calculate, decide — for ChatGPT

If our calculators helped you cut down on hidden AI wallet leaks, consider buying us a coffee. A tiny fraction of your savings keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.