A chat LLM is a language model fine-tuned to maintain multi-turn conversation — understanding context from previous messages, maintaining persona, and producing coherent follow-up responses. Every major chatbot you interact with today is built on this pattern.
But multi-turn conversation has a hidden cost problem. Every turn you send the full conversation history as context — and that history grows with every exchange.
The key insight: LLMs are stateless. They don't remember previous turns — you have to remind them every time by including the full conversation history in each API call.
// Turn 1: 50 tokens sent
messages = [
{ "role": "user", "content": "What is Python?" }
]
// Turn 2: 150 tokens sent (previous exchange included)
messages = [
{ "role": "user", "content": "What is Python?" },
{ "role": "assistant", "content": "Python is a high-level programming language..." },
{ "role": "user", "content": "How do I install it?" }
]
// Turn 10: 1,500+ tokens sent
// Turn 20: 3,000+ tokens sent
// Turn 50: 8,000+ tokens sent
This is the context window accumulation problem — and it's why chat apps get dramatically more expensive as conversations grow longer.
Send every message from the start of the conversation on every turn. Simple to implement, but costs grow linearly with conversation length.
Keep only the last N turns in context. Cheap, but the model "forgets" earlier context — which breaks tasks that require remembering something said many turns ago.
const MAX_TURNS = 6 const messages = conversationHistory.slice(-MAX_TURNS)
When the conversation exceeds a threshold, summarize older turns with a cheap model and replace them with the summary. Best of both worlds — cost stays bounded while important context is preserved.
if (messages.length > 20) {
const summary = await summarize(messages.slice(0, -10))
messages = [
{ role: 'system', content: `Conversation summary: ${summary}` },
...messages.slice(-10)
]
}
| Use case | Recommended model | Why |
|---|---|---|
| Customer support | gpt-4o-mini or claude-haiku | Fast, cheap, good at following scripts |
| Coding assistant | claude-sonnet or gpt-4o | Code quality justifies higher cost |
| General assistant | gemini-2.5-flash | Best cost/quality ratio in 2026 |
| Local/private chat | Llama 3.2 via Ollama | Zero API cost, runs on-device |
The only way to know which conversations are expensive is to instrument every API call with cost attribution. Without visibility, you're guessing which users, features, or conversation patterns are driving your bill.
Tokoscope tracks token usage per conversation, per user, and per endpoint — so you can see where costs accumulate. Free to start.
Get started free →