You have used AI in a browser. Someone told you the API is cheaper and you nodded and did nothing, because the word *API* sounds like a job you do not have. This lesson removes that. In about ten minutes you will send a real request and see a real cost, and the number will be smaller than you expect by roughly four orders of magnitude.
Step one: a key, stored properly
An API key is a password that spends money. Two rules and you will never have a bad day: never paste it into a file you might commit, and never paste it into a chat window — including an AI one. Put it in an environment variable instead.
Follow along with Step, or press Play to watch it run. The session is recorded — nothing on your machine is being executed here.
export OPENROUTER_API_KEY="sk-or-v1-your-key-here"Stores the key for this terminal session only. Close the window and it is gone — which is exactly what you want while learning.echo ${OPENROUTER_API_KEY:0:12}...Prints only the first few characters, to confirm it is set without splashing the whole key across your screen.curl -s https://openrouter.ai/api/v1/chat/completions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"qwen/qwen3.7-flash","messages":[{"role":"user","content":"Explain what an API key is, in two sentences, to someone non-technical."}]}'One request, one answer. The interesting part is not the prose — it is the usage block at the bottom.
Your own numbers will differ — token counts depend on your text, and rates move. The arithmetic is what transfers.
Step two: read what it cost
That usage block is the whole game. You sent 24 input tokens and got back 51 output tokens. Qwen3.7 Flash lists $0.03 per 1M input and $0.13 per 1M output, so:
- Input: 24 ÷ 1,000,000 × $0.03 = $0.00000072
- Output: 51 ÷ 1,000,000 × $0.13 = $0.00000663
- Total: $0.0000074 — about seven millionths of a dollar
That is not an argument against subscriptions — lesson 5 does that arithmetic properly, and seats win more often than API evangelists admit. It is an argument against *not knowing*, which is the expensive state.
Knowledge check
You send 1,000 input tokens and receive 1,000 output tokens on a model priced at $0.10 input / $0.40 output per 1M. What did it cost?