No card needed. After sign-up, claim $0.50 of free test credit with one click (once per person).
Get API keyKey points
- For English text, characters divided by four gives a usable token estimate. Add 20% as a safety margin.
- Count everything you send: system prompt, full chat history, documents, and tool definitions.
- Prompt plus completion must fit in the 100,000-token window, so check the sum before you send.
- Use max_tokens to put a ceiling on the output side of the cost.
The quick estimate
You want a number before you press send, because the number tells you whether the request fits, and roughly what it will cost. The shortcut for English prose is:
- tokens are about characters divided by 4, or
- tokens are about words multiplied by 1.33.
A 12,000-character prompt is therefore about 3,000 tokens. A 500-word page is about 670. These are averages. They drift for other languages, for source code and for text full of numbers or symbols, all of which tend to use more tokens per character than plain English. Treat the result as a planning figure and add a margin of around 20%.
That margin turns the estimate into a safe upper bound. Our 12,000-character prompt becomes 3,000 x 1.2 = 3,600 tokens for planning purposes.
What goes into the count
People undercount because they only measure the last user message. The model sees much more than that, and every part is billed as input. Add up all of these:
- The system prompt. If you keep a long persona or style guide there, it is paid for on every call.
- The full conversation history. The API does not remember earlier turns. You resend them, so they count again each time.
- Documents and retrieved snippets that you paste into the prompt.
- Tool definitions and JSON schemas if you use tool calling or a structured output format. They travel with the request, so plan for them to count as input.
- Small formatting overhead for message roles. It is only a few tokens per message, but the 20% margin covers it.
On the output side there is a single item: the reply. You do not control its length exactly, but you can cap it, which brings us to the next section.
Counting tokens with a small function
Here is a short Python helper. It estimates the prompt from all message text, applies the margin, and returns a worst-case cost based on the max_tokens you plan to set.
import math
INPUT_PER_M = 0.15
OUTPUT_PER_M = 0.50
WINDOW = 100_000
def plan(messages, max_tokens, margin=1.2):
chars = sum(len(m["content"]) for m in messages)
prompt = math.ceil(chars / 4 * margin)
if prompt + max_tokens > WINDOW:
raise ValueError(f"too big: {prompt} + {max_tokens} > {WINDOW}")
worst = prompt / 1_000_000 * INPUT_PER_M + max_tokens / 1_000_000 * OUTPUT_PER_M
return prompt, worst
messages = [{"role": "user", "content": "x" * 12_000}]
print(plan(messages, max_tokens=800)) # (3600, 0.00094)Feed it the 12,000-character prompt from earlier with max_tokens=800 and you get 3,600 tokens of input and a worst case of 3,600 / 1,000,000 x $0.15 + 800 / 1,000,000 x $0.50 = $0.00054 + $0.0004 = $0.00094. Under a tenth of a cent, with the ceiling known in advance.
A chat request estimated step by step
Take a typical chat call and walk through it with the rule. The system prompt is 800 characters. The history holds six earlier messages averaging 600 characters each, which is 3,600. The new user message is 400 characters.
- Total characters: 800 + 3,600 + 400 = 4,800.
- Raw estimate: 4,800 / 4 = 1,200 tokens.
- With the 20% margin: 1,200 x 1.2 = 1,440 tokens.
- Set
max_tokensto 500 for the reply. - Worst-case cost: 1,440 / 1,000,000 x $0.15 = $0.000216, plus 500 / 1,000,000 x $0.50 = $0.00025, so $0.000466.
The window check is trivial here, 1,440 + 500 is far below 100,000. The same method scales to batch jobs. For 2,000 documents of 6,000 characters each, one document is 1,500 tokens, or 1,800 with the margin. That is 3,600,000 input tokens, worth $0.54. With a cap of 200 output tokens each, you add 400,000 tokens, worth $0.20, for a ceiling of $0.74 on the whole batch. You know the maximum before the first request leaves your machine.
When the rule of thumb is weakest
The four-characters rule is built on English prose. Text in other languages, source code, tables, long numbers and emoji tend to split into smaller pieces, so the true count lands higher than the estimate. For those inputs, raise the margin to 30 or 40 percent on your first pass, then replace the guess with a ratio measured from your own logged usage data.
Staying inside the 100,000-token window
The window is shared by the prompt and the completion. That makes the check a sum, not a single comparison: estimated prompt plus the reply you allow must come to 100,000 or less.
A worked case. You have a 300,000-character file to analyse.
- Estimate: 300,000 / 4 = 75,000 tokens.
- With the 20% margin: 90,000 tokens.
- Room left for the reply: 100,000 - 90,000 = 10,000 tokens. That is enough for a long summary, so it fits.
Now try a 360,000-character file. The raw estimate is 90,000 tokens, and with the margin it is 108,000, which is over the limit before you even leave room for an answer. You need to split the file, send it in parts, or summarise each part and combine the summaries.
Remember the rule for chats too. Because history is resent each turn, a conversation that began as a few hundred tokens can creep towards the limit. Trim old turns, or replace them with a short summary, before the sum gets close.
Trimming history to fit
When the sum goes over, drop the oldest turns first and keep the system prompt. Walk backwards from the newest message, adding each one to a running character total, and stop when the estimate plus your reply cap reaches the limit you set for yourself. Many teams pick a working limit well below 100,000, such as 30,000 tokens, because shorter prompts are faster to process and cheaper to send. A short summary of the dropped turns, written once and kept at the top of the history, preserves the thread of the conversation without paying for every old word again.
Putting a ceiling on the reply
Output tokens cost $0.50 per 1M, a little over three times the $0.15 input rate, and you cannot know the reply length in advance. What you can do is set max_tokens. The model stops when it reaches the cap, so the output side of the bill can never exceed that number of tokens.
Pick the cap from the task. A classification or yes/no check needs 10 to 50 tokens. A paragraph answer needs maybe 300. A story scene might need 2,000. If you leave the parameter out, the completion is free to use the rest of the window, which is fine for long-form writing and wasteful for short answers.
One caution: a cap that is too small cuts a reply off mid-sentence. Look at the finish_reason in the response. If it says the output was truncated by length, raise the cap or ask the model for a shorter answer.
Check the estimate against the real count
After each call, the response gives you the real prompt and completion token counts in its usage block. Streamed responses report usage at the end of the stream. Log these next to your estimate for a week and look at the ratio.
curl -i https://api.llmtokenprices.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"max_tokens": 100,
"messages": [{"role": "user", "content": "Say hello in five words."}]
}'The -i flag prints the response headers, including X-Balance-USD. Compare the balance before and after a batch of calls and it should match the cost computed from the usage numbers.
If your estimates run consistently low, say by 15%, raise the margin. Languages other than English and code-heavy prompts usually need a bigger one. The real figures let you tune once and stop worrying.
Where to go next
Once you can size a request, the next step is turning it into a budget. The pricing page lists the rates and the top-up bonuses, and the quickstart shows the request format in several languages. If you have not made a call yet, get a key on the API key page; the one-click $0.50 trial credit is enough to run your first dozen estimates against reality.
