Token Counter and ChatGPT Token Calculator for the OpenAI API

Paste a prompt to count its tokens for GPT-5, GPT-4.1, GPT-4o, the o reasoning models, GPT-4 and embedding models, then estimate the cost with your model's price.

Your prompt is never stored. It is only used to calculate the token count.
Tokens
0
Words
0
Characters
0
  • Models (encoding)Tokens
  • GPT-5, GPT-4.1, GPT-4o, GPT-4o mini, o4-mini, o3, o1, o1-mini

    o200k_base

    0
  • GPT-4 Turbo, GPT-4, GPT-3.5 Turbo, text-embedding-3-large, text-embedding-3-small, text-embedding-ada-002

    cl100k_base

    0
  • GPT-2

    gpt2

    0

Enter your model's price per 1M input tokens from the OpenAI pricing page.

per 1M tokens

Step-by-step guide

How to count tokens for the OpenAI API

Paste your text into the token counter above. It splits the text the same way OpenAI models do and shows the token count for each model family. In English, one token is about four characters, or about three quarters of a word, but the exact count depends on the model's encoding.

  1. Paste the full prompt

    Include the instructions and examples you send to the model, not only the question, because every part counts. The API also adds a few tokens per chat message for formatting.

  2. Read the count for your model

    GPT-5, GPT-4.1, GPT-4o and the o-series reasoning models use the o200k_base encoding. GPT-4, GPT-3.5 Turbo and the embedding models use cl100k_base.

  3. Estimate the cost

    Enter your model's price per 1M input tokens. The cost is the token count divided by 1,000,000, times the price. Output tokens are billed separately, at their own price.

  4. Shorten the prompt if needed

    Remove repeated instructions and long examples, and send only the part of a document the model needs. Then count again.

Token count examples
  • Hello, world!

    4 tokens with o200k_base and cl100k_base (13 characters)

  • Photosynthesis happens in the chloroplasts.

    9 tokens (43 characters, 5 words)

  • ¿Dónde está la biblioteca?

    6 tokens with o200k_base, 9 with cl100k_base: newer encodings often need fewer tokens for languages other than English

  • https://www.quizrise.com/token-counter

    8 tokens: links and code split into many small pieces

With the advance of artificial intelligence technologies comes the need for precise cost prediction tools. Our Free Token Calculator for the OpenAI API helps estimate your usage costs with accuracy. This tool provides a clear picture of expenses when utilizing models like GPT-5, GPT-4.1, GPT-4o, GPT-4o Mini, o1, o3 reasoning models, GPT-4 Turbo, GPT-3.5 Turbo, and embedding models such as text-embedding-3-large, text-embedding-3-small and text-embedding-ada-002. The calculator assists in monitoring your expenditure by analyzing the tokens used in API calls based on different model encodings. Decipher the OpenAI API cost with this free token pricing calculator and effectively leverage the power of AI without unplanned expenses.

ChatGPT Token Calculator: A Guide to Estimating Your Token Costs

The Token Calculator is an innovative tool allowing you to estimate token costs. Utilizing OpenAI's `tiktoken` library, this calculator evaluates the number of tokens in a text string for various models, giving you a clear idea of your consumption. This is crucial for API usage, where token count significantly impacts your bill. It facilitates budgetary management for developers, offering a better understanding of usage patterns and costs across different models like GPT-4o, GPT-4o Mini, o1, o3 reasoning models, GPT-4, and GPT-3.5 Turbo. Calculating tokens helps maintain cost efficiency while enabling optimal resource utilization.

How our token counter helps:

Our integral token counter assists users in optimizing OpenAI costs. Counting tokens helps control text length and forecast usage across different models, ensuring you stay within specific utilization constraints. This forecasting ability is crucial for managing OpenAI billing effectively. Understanding how tokens are counted provides greater visibility into usage and helps minimize unnecessary costs. Improper token management can lead to higher expenses, making the token counter an indispensable tool for cost-efficient usage of OpenAI's language and embedding model services.

How to calculate token usage

To calculate token usage with our tool, simply input your text. It utilizes the `tiktoken` library to determine the token count based on each model's encoding (e.g., `o200k_base` for GPT-5 and GPT-4o, `cl100k_base` for GPT-4/GPT-3.5 Turbo, `r50k_base`/`gpt2` for older models). Remember that a token isn't always a full word; it can be part of a word, a punctuation mark, or whitespace. By seeing how different models tokenize your text, you can better estimate potential API costs and optimize your prompts for efficiency.

What Are OpenAI GPT Tokens?

An OpenAI token is the fundamental unit of text or code processed by models like GPT-4o, GPT-4, GPT-3.5-turbo, and embedding models. The cost of using these models via the API depends directly on the number of tokens in your input (prompt) and the model's output (completion). While more tokens can allow for more complex instructions or detailed responses, it also increases computational cost. Roughly, 1,000 tokens equate to about 750 English words, but this varies. Understanding tokens is key to managing API costs.

How OpenAI Models Count Tokens (Encodings)

OpenAI uses Byte Pair Encoding (BPE) via the `tiktoken` library to convert text into tokens. Different models use different BPE encodings, affecting the token count for the same text:

  • `o200k_base`: Used by the latest models including GPT-5, GPT-4.1, GPT-4o, GPT-4o Mini, and reasoning models like o4-mini, o1, o1-mini, o1-preview, and o3.
  • `cl100k_base`: Used by GPT-4 models (including Turbo & Vision), GPT-3.5 Turbo, and current embedding models like `text-embedding-ada-002`, `text-embedding-3-small`, and `text-embedding-3-large`.
  • `p50k_base`: Used by older Codex models and models like `text-davinci-002`/`003`.
  • `r50k_base` (or `gpt2`): Used by older GPT-3 models (`davinci`, `curie`, `babbage`, `ada`) and GPT-2.

A token can be a word, part of a word (e.g., "calcul" and "ator"), a single character, punctuation, or whitespace. Even a space before a word often forms part of a token (e.g., " hello"). Our calculator shows how your text breaks down for each encoding.

Tips for Optimized API Usage Cost

Optimizing API usage costs involves several strategies focused on token efficiency:

  • Prompt Conciseness: Shorter, clearer prompts use fewer input tokens.
  • Model Selection: Choose the most cost-effective model for your needs (e.g., GPT-3.5 Turbo is cheaper than GPT-4 or GPT-4o for simpler tasks).
  • Limit Output Length: Use the `max_tokens` parameter to control completion length and cost.
  • Instruction Efficiency: Refine instructions to get the desired output with fewer tokens.
  • Caching: Avoid redundant API calls by caching results when appropriate.
  • Monitor Usage: Regularly check your OpenAI usage dashboard.

Using our Token Calculator helps you experiment with prompt changes and understand their token impact before incurring API costs.

How to monitor my OpenAI API usage and cost?

You can review how much you use in the OpenAI dashboard usage section.
In the OpenAI dashboard billing section, you can quickly create spending limitations.