LLM API Guide (2026): What It Is, How It Works, Prices, and the Best Providers
An LLM API is a web endpoint that lets your code send a prompt to a large language model and get generated text, JSON, or tool calls back, billed per token. You call it with an HTTP request that includes an API key, a model name, and your messages, so you get models like GPT, Claude, Gemini, DeepSeek, or Qwen without running any GPUs. In October 2026 prices range from $0.10 per million input tokens for small models to $10 for the largest ones.
This guide is for developers and indie builders choosing their first (or next) LLM API. It covers how the request works, runnable code in curl, Python, and Node.js, current official prices from the major providers, free options, how to pick a provider, and when a unified API makes more sense than separate accounts.
What is an API in an LLM?
An API (application programming interface) is the contract your program uses to talk to another service. For a large language model, the API defines:
- Endpoint: the URL you send requests to, such as
/v1/chat/completionsor/v1/messages. - Authentication: an API key in a header, tied to your account and billing.
- Request format: the model ID, a list of messages (system, user, assistant), and options like
max_tokens,temperature, tools, and response format. - Response format: generated text or structured output, plus token usage for billing.
- Limits: requests and tokens per minute, context window, and maximum output length.
The model itself runs on the provider's GPUs. You never download weights; you rent inference one request at a time. That is the main difference from self-hosting an open model with tools like vLLM or Ollama.
How an LLM API works, step by step
- Your app builds a request with the model name and the conversation so far.
- The provider tokenizes the text (a token is roughly 3 to 4 characters of English).
- The model generates output tokens one at a time, optionally streaming them back as server-sent events.
- The response includes the text and a
usageobject with input and output token counts. - You are billed: input tokens x input price + output tokens x output price.
Because the API is stateless, you resend the relevant conversation history on every call. That is why long chats get more expensive and why prompt caching discounts matter.
LLM API example: your first request
Most providers now accept the OpenAI-style chat format, which is why it has become the de facto standard. This works against OpenAI directly:
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6-luna",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what an LLM API is in one sentence."}
],
"max_tokens": 100
}'
The same request in Python with the official openai package. Changing base_url and the key points it at any OpenAI-compatible provider, including a router such as Flatkey (quickstart):
from openai import OpenAI
client = OpenAI(
api_key="YOUR_KEY",
base_url="https://router.flatkey.ai/v1", # or https://api.openai.com/v1
)
resp = client.chat.completions.create(
model="claude-sonnet-5-5", # any model ID from the provider's catalog
messages=[{"role": "user", "content": "Give me 3 names for a todo app."}],
max_tokens=200,
)
print(resp.choices[0].message.content)
print(resp.usage) # prompt_tokens, completion_tokens -> what you pay for
And in Node.js 18+ with plain fetch and streaming:
const res = await fetch("https://router.flatkey.ai/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.FLATKEY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gemini-4-argon",
stream: true,
messages: [{ role: "user", content: "Write a haiku about APIs." }],
}),
});
const decoder = new TextDecoder();
for await (const chunk of res.body) process.stdout.write(decoder.decode(chunk));
Anthropic and Google also have native formats (the Messages API and the Gemini API) with provider-specific features, but both can also be reached through OpenAI-compatible layers.
Best LLM API providers in 2026 (with official prices)
Prices below are per million tokens (input / output), taken from each provider's official pricing page on October 23, 2026.
| Provider | Premium model | Balanced model | Budget model | Notes |
|---|---|---|---|---|
| OpenAI | gpt-6-astra $10 / $50 | gpt-6.1-sol $2 / $10 | gpt-6-luna $0.10 / $0.50 | Batch and Flex tiers cut prices 50% |
| Anthropic Claude | Opus 5.5 $4 / $20 | Sonnet 5.5 $2 / $10 | Haiku 5.5 $0.10 / $0.50 (prompts up to 100K) | 1M context at standard price on 4.6+ models except Haiku 5.5 |
| Google Gemini | Gemini 4 Argon $2 / $10 through Nov 30, 2026 ($4 / $20 from Dec 1) | Gemini 3.8 Flash $0.75 input through Dec 31, 2026 | Flash-Lite models | Free tier on Flash models; Argon not on free tier |
| DeepSeek | deepseek-v4-pro $1.32 / $3.96 peak, $0.66 / $1.98 off-peak | n/a | deepseek-flash $0.30 / $1.20 peak, $0.15 / $0.60 off-peak | Cache hits from $0.003 |
| OpenRouter | Provider list prices | 5.5% fee on credit purchases (Standard plan) | ||
| Flatkey | e.g. Kimi K3 $1.80 / $9 (list $3 / $15) | e.g. Claude Sonnet 5.5 $1.60 / $8 | e.g. gpt-6-luna $0.06 / $0.30 | One key for 80+ models; prices from model pages |
Flatkey prices come from its model pages on October 23, 2026, which show both Flatkey's rate and the provider list price. For a deeper per-model breakdown, including caching and batch discounts, read our AI API pricing comparison.
Which LLM API is cheapest?
For small, fast models, the cheapest official list prices in October 2026 were OpenAI gpt-6-luna and Claude Haiku 5.5 at $0.10 input / $0.50 output per million tokens, and deepseek-flash at $0.15 / $0.60 during DeepSeek's off-peak hours. Example: 10,000 requests a day with 1,000 input and 300 output tokens each is 300M input and 90M output tokens a month, about $75 on gpt-6-luna list pricing. Batch APIs, prompt caching, and off-peak windows can halve that again.
Are there free LLM APIs?
Yes, with limits. Google's Gemini API has a free tier on Flash models (with usage that may be used to improve Google products), and several routers expose rate-limited free models. Free tiers are fine for prototypes but have low requests-per-day caps. See our list of free LLM APIs in 2026.
How to choose an LLM API
| Question | Why it matters | What to check |
|---|---|---|
| How good does output need to be? | Premium models can cost 50 to 100 times more than budget ones | Test 20 to 50 real prompts on two or three tiers |
| How long are your prompts? | Long context multiplies input cost | Context window and long-prompt pricing (e.g. Haiku 5.5 over 100K) |
| How fast must it respond? | Users notice time to first token | Streaming support and latency in your region |
| How much traffic? | Limits are per minute and per day | RPM/TPM by tier; see our LLM rate limits guide |
| Do you need tools or JSON? | Agents rely on function calling | Tool calling and structured output support |
| Where is data processed? | Compliance and customer contracts | Data retention, regional endpoints (Claude US-only inference costs 1.1x) |
| Will you switch models? | Prices and leaders change every few months | OpenAI-compatible format, or a unified API |
Direct provider vs unified LLM API
Calling one provider directly is simplest when you use one model family. Once you mix models, a unified API (also called an LLM router or LLM gateway) saves work:
- One key and one balance instead of separate accounts, invoices, and rate limits per provider.
- Swap models by changing a string, not an SDK.
- Fallback to another model when one provider is down or rate-limited.
- One usage log for cost per feature or customer.
Options include hosted routers (OpenRouter, Flatkey, Vercel AI Gateway) and self-hosted proxies like LiteLLM. Hosted routers differ mainly in fees: OpenRouter bills provider list prices plus a 5.5% credit fee on its Standard plan, while Flatkey's model pages list rates below provider list prices for many models. Compare them in our OpenRouter alternatives guide and unified AI API explainer.
When an LLM API matters, and when it does not
Use an LLM API when real users depend on the output, when you need more than one model, when cost has to map to features or customers, or when you are building agents that call tools. Self-host instead when you must keep data on your own hardware, need a fine-tuned open model at steady high volume, or require offline operation. Our guide on one API key for multiple AI models shows how small teams set this up without a platform team.
Common mistakes
- Hard-coding one model ID everywhere. Put it in config so you can switch.
- Ignoring output tokens. Output usually costs 4 to 5 times more than input; cap
max_tokens. - Resending huge histories. Summarize or cache long system prompts.
- No retry logic. 429 and 5xx errors happen; add backoff (see our API rate limit exceeded guide).
- Committing keys to git. Use environment variables and rotate keys.
FAQ
What is an API in an LLM?
It is the interface your code uses to send prompts to a large language model and receive its output. It defines the endpoint URL, authentication with an API key, the request and response format, rate limits, and per-token billing.
Is ChatGPT an LLM or NLP?
Both, in a sense. Natural language processing (NLP) is the field; large language models are one kind of NLP model; and ChatGPT is a consumer product built on OpenAI's LLMs. Developers reach the same model family through the OpenAI API rather than the ChatGPT app.
What are the best LLM APIs?
In October 2026 the main options are OpenAI (GPT-6 family), Anthropic (Claude 5.5 family), Google (Gemini 4 Argon and Flash models), DeepSeek (V4 Pro and Flash), plus unified APIs such as OpenRouter and Flatkey that expose many providers through one key.
What is the cheapest LLM API?
Among official list prices on October 23, 2026, OpenAI gpt-6-luna and Claude Haiku 5.5 cost $0.10 per million input tokens and $0.50 per million output tokens, and deepseek-flash costs $0.15 / $0.60 off-peak. Gemini's free tier is cheaper still for low volumes.
Is there a free LLM API?
Yes. Google's Gemini API offers a free tier on its Flash models with daily limits, and some routers offer free, rate-limited models. Expect tight caps and possible data-use terms.
What is the difference between an LLM API and an LLM gateway?
An LLM API is one provider's endpoint for its models. An LLM gateway or router sits in front of many providers, giving one key, one format, routing, fallback, and unified billing.
Do I need a GPU to use an LLM API?
No. The provider runs the model on its own GPUs; you only send HTTP requests and pay per token.



