GPT prompts · Encoding and context planning

GPT Token Calculator

Count prompt text with a selected encoding, reserve response space and check a context budget. Inspect every token ID before making a GPT request.

Accuracy note

Raw encodings count the supplied text exactly for that encoding. Compatible model views exclude some request formatting; provider API usage remains authoritative for complete requests.

How the GPT token calculator works

Paste your prompt and select a raw encoding to count exactly the text you entered. The default o200k_base view shows both the number of tokens and their numeric IDs. Selecting a GPT model preset provides its labeled compatible view; it does not guarantee that all provider-side request formatting is present in the editor.

Use the budget controls to reserve space for a response and add input that is not already counted, such as omitted history or known template overhead. Enter the context limit of your exact model. The initial 8,192-token setting is only an editable example, and the calculator does not infer a model limit from its name.

pythonReproduce a raw encoding count
# pip install tiktoken
import tiktoken

prompt = "Hello world! 你好,世界!"
for name in ["o200k_base", "cl100k_base"]:
    encoding = tiktoken.get_encoding(name)
    ids = encoding.encode(prompt)
    print(name, len(ids), ids)
# Raw text only; no complete API request wrapper.

GPT token calculator vs word counter

A word-count shortcut cannot explain how an encoding handles punctuation, numbers, code or multilingual text. Count the actual draft when trimming a GPT prompt. Shortening one sentence may save fewer tokens than removing a repeated instruction, a long example or an unnecessary block of structured data.

For budget planning, add measured prompt tokens, additional input and reserved output. A prompt of 800 tokens, 100 tokens of extra input and a 400-token output reserve needs 1,300 tokens of planned space. A 4,096-token context budget would leave 2,796. These allowances are choices for planning, not predictions of what the response will consume.

GPT token count by encoding and model

Use the encoding comparison to understand a vocabulary and the linked model guide to understand a preset. For the mixed-language sample in the Python example, o200k_base produces 8 tokens while cl100k_base produces 11. Those are raw-text results; a structured request can contain more than that sample sentence.

Before a production request, confirm the current model ID and the provider's supported input-counting method. Chat roles, tool schemas, images and response accounting are not interchangeable with a raw token list. Recount when the model or message format changes, and inspect returned usage when measuring the completed interaction.

SelectionWhat is countedAccuracy boundary
o200k_baseRaw text in the selected vocabularyExact raw encoding; no complete request wrapper
cl100k_baseRaw text in a different vocabularyExact raw encoding; choose it deliberately
GPT-5.6 compatible viewText under the compatible o200k_base viewCheck complete request usage with OpenAI

Tiktokenizer Reference Sources

Tokenizer behavior and model limits change. Verify production decisions with current provider documentation:

Frequently asked questions

Is this GPT token calculator free?

Yes. The live text counter and editable budget calculation run in your browser without signup.

Is o200k_base exact for every GPT request?

It is exact for text under that raw encoding. A compatible GPT preset does not include every possible provider-side wrapper, tool or media input.

How much space should I reserve for output?

Choose an allowance for your application and check the model's output limit. The calculator displays your chosen reserve; it does not predict response length or hidden reasoning.

Should I add chat overhead twice?

No. Additional input should cover only content missing from the measured prompt. If your text already contains a known wrapper or history, avoid adding it again.

Does this calculate API prices?

This page calculates token counts and context space. Check current model pricing and actual usage separately when estimating or reconciling cost.

Where can I build a conversation instead of pasting raw text?

Use the linked ChatGPT token calculator or choose a supported chat-model preset to explore the existing conversation editor and its labeled formatting.