# Rate limits, tokens, and costs

[Skip to content](#lm-inhoud)Network/[NL](/en/rate-limits-en-kosten)EN[Hubhub.llmnet.nlCompare models on task, language, cost and license.](https://hub.llmnet.nl/en/)[Communitycommunity.llmnet.nlPrompt techniques, patterns and system prompts.](https://community.llmnet.nl/en/)[APIapi.llmnet.nlLLMs in production: rate limits, routing, structured output.](https://api.llmnet.nl/en/)[Consultancyconsultancy.llmnet.nlRolling out AI in an organization, pilot to production.](https://consultancy.llmnet.nl/en/)[Newsnieuws.llmnet.nlAI developments, explained for the Netherlands.](https://nieuws.llmnet.nl/en/)[Benchmarkbenchmark.llmnet.nlMeasure AI quality yourself, on your own tasks.](https://benchmark.llmnet.nl/en/)[Careersvacatures.llmnet.nlAI roles, salaries and career paths in the Netherlands.](https://vacatures.llmnet.nl/en/)[Learnleren.llmnet.nlAI concepts in plain language, beginner to builder.](https://leren.llmnet.nl/en/)[Guidegids.llmnet.nlRun AI privately on your own Mac, PC, NAS or home server.](https://gids.llmnet.nl/en/)[Directorydirectory.llmnet.nlMapping the AI ecosystem: tools, models, companies.](https://directory.llmnet.nl/en/)[Radarradar.llmnet.nlSignals from X, research and communities for indie developers.](https://radar.llmnet.nl/en/)[Appsapps.llmnet.nlReviews of AI apps and open-source repos, with tips for builders.](https://apps.llmnet.nl/en/)[llmnet.nl — main site](https://llmnet.nl/en/)[](https://x.com/intent/post?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten&text=Rate%20limits%2C%20tokens%2C%20and%20costs)[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten)[](https://www.reddit.com/submit?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten&title=Rate%20limits%2C%20tokens%2C%20and%20costs)[](#)[](https://x.com/intent/post?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten&text=Rate%20limits%2C%20tokens%2C%20and%20costs)[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten)[](https://www.reddit.com/submit?url=https%3A%2F%2Fapi.llmnet.nl%2Fen%2Frate-limits-en-kosten&title=Rate%20limits%2C%20tokens%2C%20and%20costs)[](#)By Ivo Donker — created with AI assistance (Claude & Gemini) · Last updated: July 27, 2026

# Rate limits, tokens, and costs: how to keep your LLM API usage under control

When building web applications that rely on Large Language Models, you quickly run into the technical reality of API integrations: tokens are not free, and bandwidth is not infinite. Especially with advanced implementations, such as a RAG (Retrieval-Augmented Generation) architecture with vector search, costs and latency can quickly add up unnoticed. In this guide, we dissect the mechanisms and offer concrete tools for optimization.

## What is a token (and context vs. output)?

Roughly speaking, one token equals three-quarters of a word. LLM providers, whether you use models like Claude Pro variants or DeepSeek, bill based on two streams:

- Input tokens (Context): The text, instructions, and context you send to the model.

- Output tokens (Completion): The response generated by the model.

Output tokens are significantly more expensive than input tokens with most providers (sometimes by a factor of 3 to 5). When designing your prompts, it is therefore essential to guide the model toward concise, structured output (such as JSON) to reduce completion costs, even if this means your input prompt becomes slightly longer.

Be careful with RAG: If you use vector search to retrieve document chunks, you will quickly blow up your context window. Retrieve only the top-k most relevant results instead of sending entire documents.

## Rate limits: Understanding TPM and RPM

Providers protect their infrastructure with limits. This usually happens along two axes:

- RPM (Requests Per Minute): The number of individual API calls you are allowed to make.

- TPM (Tokens Per Minute): The total volume of processed tokens (input + output combined).

If you hit these limits, the API returns an HTTP 429 Too Many Requests error. Simply ignoring this leads to broken applications and poor user experiences.

## Caching, Batching, and Routing

To reduce costs and bypass rate limits, the architecture needs to be built smarter:

- Semantic Caching: Store answers to frequently asked, similar questions. If a user asks a question that semantically matches a previous question by 95%, serve the cache instead of making a new LLM call.

- API Orchestrators: Use a gateway or orchestrator (for example, a setup with OpenRouter) to route requests smartly. Simple classification tasks can go to a cheaper, faster model, while complex reasoning goes to the most expensive flagship model.

## Pseudocode: Exponential Backoff & Caching

Below is an abstract example of how to robustly handle rate limits and caching in your application layer:

function call_llm_api_with_backoff(prompt, max_retries=3):
# 1. Check local cache first
cache_result = check_semantic_cache(prompt)
if cache_result:
return cache_result

# 2. Prepare API call
delay = 1

for attempt in range(max_retries):
response = execute_request(prompt)

if response.status == 200:
save_to_cache(prompt, response.data)
return response.data

if response.status == 429: # Rate limit hit
wait(delay)
delay = delay * 2 # Exponential increase (1s, 2s, 4s...)
else:
abort_with_error(response)

throw Error("Rate limit persistently exceeded after retries")

## Cost Control Checklist

- Set Max Tokens: Always define a hard limit for max_tokens in your API call to prevent infinite generation loops.

- Smart Model Routing: Use fast, cheap models for simple NLP tasks (such as entity extraction) and reserve complex models exclusively for heavy reasoning.

- RAG Optimization: Reduce your chunk size during vectorization and set strict thresholds (similarity scores) so that irrelevant context is not sent.

- Batch Processing: Do you have asynchronous tasks (e.g., background summaries)? Make use of the Batch API endpoints that many providers offer at reduced rates (often a 50% discount).

- Monitor your Tiers: Upgrade to higher usage tiers with your provider in time by pre-funding your account, which often immediately raises your TPM/RPM ceilings.

Need help setting up a cost-effective architecture or optimizing your RAG pipelines? Check out our [LLM Consultancy services](https://consultancy.llmnet.nl/en/) for tailored technical advice.
