Using a Language Model in Code › The Cost of Conversation

Michael BrenndoerferJune 27, 20252 min read
AI Agent HandbookAll chapters
Part 2 of 15Language Models - The Brain of the Agent
Chapter 5Using a Language Model in Code › The Cost of Conversation
Reading section 11 of 15 · The Cost of Conversation · 2 minSection 11 of 15 · 2 min

Book contents

Section 11 of 15 · 2 min read

Using a Language Model in Code › The Cost of ConversationOne section · Sections in this chapter11 / 15 ↓

One practical consideration: API calls cost money. All providers charge based on tokens (roughly, pieces of words) processed. A typical conversation turn might cost a fraction of a cent, but it adds up with heavy use.

Here's a rough guide (prices as of November 2025, but check current rates as they change frequently):

OpenAI:

  • GPT-5: Pricing varies by usage tier; check OpenAI's website for current rates (most advanced, standardized responses)

Anthropic:

  • Claude Sonnet 4.5: $3 per million input tokens, $15 per million output tokens (excellent for agent tasks and coding)
  • Claude Haiku 4.5: $1 per million input tokens, $5 per million output tokens (faster, cost-efficient, good for high-volume tasks)
  • Claude Opus 4.1: $15 per million input tokens, $75 per million output tokens (maximum capability for complex tasks)

Google:

  • Gemini 2.5 Flash: Lower cost, faster responses, good for simple tasks
  • Gemini 2.5 Pro: Competitive pricing with large context window (1M tokens); check Google's pricing page for current rates

A typical message might use 100-500 tokens, so a conversation might cost a fraction of a cent to a few cents depending on the model. Not much for occasional use, but significant if you're processing thousands of requests.

Design consideration: Choose the model based on task complexity. Don't use the most expensive models for simple tasks that cheaper models can handle. We'll explore optimization strategies in Chapter 15.