Post

LLM API Pricing Compared: How to Find the Cheapest Provider

How LLM API pricing works and how to find the cheapest provider — the per-token model, hidden costs, and a Python cost calculator you can run on your own usage.

LLM API Pricing Compared: How to Find the Cheapest Provider
🚀 Find Better AI Tools Faster Submit Your AI Tool & Reach Thousands of Builders Get Started →

The Cheapest Provider Depends on Your Usage

There’s no single cheapest LLM API — it depends on your input/output ratio, volume, and whether you cache. Published price-per-token tables go stale fast and hide the costs that actually bite. This guide explains the pricing model and gives you a Python calculator to compare providers on your real workload.

How LLM API Pricing Works

Almost every provider charges per token, split into input and output — and output usually costs several times more than input. A token is roughly ¾ of a word.

1
2
3
4
Total cost = (input_tokens  x input_price)
           + (output_tokens x output_price)

Output tokens are typically 2-4x the price of input tokens.

This asymmetry matters: a chatbot with short prompts and long answers is dominated by output cost, while a document classifier with long inputs and one-word answers is dominated by input cost.

A Cost Calculator You Can Run

Don’t trust a marketing table — compute your own cost. Plug in each provider’s current prices and your token counts.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def cost(input_tokens, output_tokens, in_price, out_price):
    """Prices are USD per 1M tokens (check the provider's current page)."""
    return (input_tokens / 1_000_000 * in_price
            + output_tokens / 1_000_000 * out_price)

# Example: 2000 input + 500 output tokens per call, 100k calls/month
calls = 100_000
providers = {
    "Model A": (0.15, 0.60),   # (input $/1M, output $/1M) -- fill with live prices
    "Model B": (0.50, 1.50),
    "Model C (local)": (0.0, 0.0),
}
for name, (ip, op) in providers.items():
    monthly = cost(2000, 500, ip, op) * calls
    print(f"{name:20} ${monthly:,.2f}/month")

Fill the tuples from each provider’s live pricing page. The ranking often surprises people — a “cheaper” input price loses to a rival with cheaper output when your answers are long.

The Hidden Costs

Per-token price isn’t the whole bill. Three factors move the real total more than the headline rate:

  • Caching. Repeated prompt prefixes (system prompts, few-shot examples) can be cached at a large discount. See prompt caching explained.
  • Model size. A smaller model at 1/10th the price often does the job. Don’t pay flagship rates for classification.
  • Retries and context bloat. Long chat histories resent every turn quietly inflate input tokens. Trim history and cap retries.

Cutting Cost to (Almost) Zero

The cheapest API is no API. For prototyping and low-volume work, start with a genuinely free endpoint — directories like FreeLLM list current free LLM APIs. For high-volume, non-critical work, a local model via Ollama has zero per-token cost after hardware. Route easy requests to a small or local model and reserve the expensive flagship for hard ones — a two-tier setup that often cuts bills by more than half. See the free LLM API options for zero-cost starting points.

Frequently Asked Questions

Why is output more expensive than input?

Generating tokens is sequential and compute-heavy — the model runs a full forward pass per output token. Reading input is parallelized and cheaper. That’s why prompts with long answers cost more than long prompts with short answers.

What is the cheapest LLM API?

It depends on your input/output mix and volume. Small open models on aggregators or free tiers are cheapest per token; a local model is cheapest at high volume. Run the calculator above on your own usage to decide.

How can I reduce LLM API costs?

Use a smaller model where quality allows, cache repeated prompt prefixes, trim conversation history, cap retries, and route easy requests to cheap or local models. These usually beat switching providers.

Takeaways

  • Pricing is per-token, and output costs 2-4x input — your ratio decides the winner.
  • Compute cost on your own token counts, not a marketing table.
  • Caching, smaller models, and local routing cut bills more than provider-hopping.

To eliminate per-token cost entirely for suitable workloads, run models yourself with Ollama.

Khushal Jethava
Khushal Jethava

Machine Learning Engineer at Codiste, specializing in Generative AI, NLP, and Computer Vision. Building production AI systems with Python.

🚀 Find Better AI Tools Faster Submit Your AI Tool & Reach Thousands of Builders Get Started →
This post is licensed under CC BY 4.0 by the author.
🚀 Find Better AI Tools Faster Submit Your AI Tool & Reach Thousands of Builders Get Started →
🚀 Find Better AI Tools Faster Submit Your AI Tool & Reach Thousands of Builders Get Started →