What Is a Token in AI: How It's Calculated, How Much the OpenAI, Anthropic, and Google APIs Cost, and How to Optimize

Dan Patiño

AI Strategy & Innovation at Coderhouse

Artificial Intelligence

What Is a Token in AI: How It's Calculated, How Much the OpenAI, Anthropic, and Google APIs Cost, and How to Optimize

Published on

When you integrate an AI API into a project and the first bill arrives, the first question is usually the same: what exactly is a token and why am I being charged for them? Tokens are the unit of measurement on which language models operate, and understanding how they are counted and how much they cost is key to building scalable AI applications without surprises in the cost.

What is a token in language models?

A token is not exactly a word, although they are quite similar. Language models process text by dividing it into fragments called tokens, which can be complete words, parts of words, or even punctuation marks.

As a general rule, in English 1 token is equivalent to approximately 0.75 words, or 4 characters. In Spanish, due to its more complex morphology, the ratio can be slightly different: a long word like "implementación" can count as 3 or 4 tokens depending on the model.

For example, the phrase "Hola, ¿cómo estás?" can be tokenized in different ways depending on the model. OpenAI offers its Tokenizer tool to explore how any text is divided into tokens before being sent to the model.

Why does each model count differently?

Each family of models uses its own tokenizer, an algorithm trained to divide the text as efficiently as possible. OpenAI uses cl100k_base for GPT-4 and later versions; Anthropic uses its own tokenizer for Claude; Google has its own for Gemini.

This means the same text can consume a different number of tokens depending on the model you use. For projects at scale, this difference can significantly impact the final costs.

Price table per million tokens: GPT-5.5, Claude, and Gemini

As of May 2026, the prices per million tokens of the main commercial models are approximately:

Model

Input (per 1M tokens)

Output (per 1M tokens)

Maximum context

GPT-5.5 Instant (OpenAI)

USD 2.50

USD 10.00

128K tokens

Claude Opus 4 (Anthropic)

USD 15.00

USD 75.00

200K tokens

Gemini 2.5 Pro (Google)

USD 1.25

USD 5.00

1M tokens

Input tokens are the ones you send to the model (your prompt, the conversation history, context documents). Output tokens are the ones the model generates as a response. In applications with long conversations or RAG, the input usually dominates the cost.

How to calculate the cost of an AI project

To estimate the cost of an application, you need to calculate how many tokens each average interaction consumes, both input and output, multiply it by the model's price, and project it to the expected volume of use.

For example: if you have a chatbot that sends prompts of 500 tokens (including the system prompt) and receives responses of 300 tokens, each interaction consumes ~800 total tokens. With GPT-5.5 Instant at USD 2.50/M input and USD 10/M output, the cost per interaction would be approximately USD 0.00425. With 10,000 daily interactions, the monthly cost would be ~USD 1,275.

Strategies to reduce costs by optimizing token usage

Reducing token consumption doesn't always mean cutting quality. There are several techniques that allow you to optimize without degrading the results:

  • Compress the system prompt: eliminate redundant instructions and be precise. A system prompt of 200 tokens instead of 500 can reduce the cost per interaction by almost half.

  • Truncate the conversation history: instead of sending the entire conversation, keep only the last N turns or use a summary of the previous ones.

  • Choose the right model for each task: not all tasks require the most powerful model. For simple classifications or short summaries, a more economical model may be enough.

  • Manage the context window well in RAG: retrieve only the most relevant fragments, not the entire knowledge base.

If you're interested in going deeper into how model customization techniques like RAG and fine-tuning work, you can read our article about fine-tuning, RAG, and prompt engineering: how to choose the right technique.

Recommended Coderhouse courses

Mastering the cost model of AI APIs is part of the training of any developer who works with LLMs in production:

  • Introduction to Artificial Intelligence Course (beginner level): to understand how language models work, including concepts like tokenization and context window.

  • AI Agents Course (intermediate level): where you learn to build applications with AI APIs, optimizing prompts and context flows to keep costs low.

  • AI Engineering Course (advanced level): to implement production pipelines with full control over token consumption, model evaluation, and cost optimization at scale.

Frequently asked questions

Do input and output tokens cost the same?

No. In all the main models, output tokens cost more than input tokens. This is because generating text requires more computation than processing it. That's why controlling the length of the model's responses is one of the most effective ways to reduce costs.

How can I know how many tokens my application uses?

Most APIs return the token consumption in each response (generally in the usage object). You can also use each provider's official tokenization tools to estimate the cost before making the call.

Do tokens accumulate in a conversation?

Yes. In conversational applications, every time you send a message, the model receives the complete history of the conversation plus the new message. This means that as the conversation progresses, the cost per interaction grows. Managing the history (truncating or summarizing it) is essential to control costs in intensive-use chatbots.

Is there a token limit per call?

Yes, each model has a maximum context limit: the total number of tokens it can process in a single call (input + output combined). GPT-5.5 Instant has 128K tokens, Claude Opus has 200K, and Gemini 2.5 Pro reaches one million. Exceeding this limit generates an error, so you have to design applications keeping this cap in mind.

Is it worth using cheaper models to reduce costs?

It depends on the task. For simple use cases like text classification, structured data extraction, or short predictable responses, a more economical model can work perfectly. For complex reasoning, advanced code generation, or analysis of long documents, the flagship models remain the most reliable.

About the author

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.

English

© 2026 Coderhouse. All rights reserved.

English

© 2026 Coderhouse. All rights reserved.

English

© 2026 Coderhouse. All rights reserved.

English

© 2026 Coderhouse. All rights reserved.