DEV Community

Mattias chaw
Mattias chaw

Posted on

Token Economics 101: How to Pick the Right AI Model for Every Task

Token Economics 101: How to Pick the Right AI Model for Every Task

Pricing data from AIWave, July 2026. Calculations are exact, not estimated.

Every AI API call costs money, and the difference between a well-chosen model and a poorly-chosen one isn't 10% — it's often 100× or more. Understanding token economics isn't optional for developers building with AI; it's fundamental.

This guide covers how tokens work, how to calculate real costs, and how to match the right model to each task using actual pricing data.

What Is a Token?

A token is the unit LLMs use to process text. In English, one token ≈ 4 characters or 0.75 words. In Chinese, one character often equals one token (CJK characters are less efficiently tokenized by most models).

def estimate_tokens(text: str) -> int:
    """Rough token estimation. For exact counts, use tiktoken or the API response."""
    chars = len(text)
    cjk_count = sum(1 for c in text if '\u4e00' <= c <= '\u9fff')
    latin_chars = chars - cjk_count
    # English: ~4 chars per token, Chinese: ~1.5 chars per token
    return int(latin_chars / 4 + cjk_count / 1.5)

# Example
english_text = "Implement a binary search function in Python"
print(estimate_tokens(english_text))  # ~10 tokens

chinese_text = "用Python实现二分查找算法"
print(estimate_tokens(chinese_text))   # ~8 tokens (7 CJK + 5 latin)
Enter fullscreen mode Exit fullscreen mode

For production systems, always use the actual usage.prompt_tokens and usage.completion_tokens from the API response rather than estimating.

Input vs Output Token Pricing

Token pricing is almost always asymmetric — output tokens cost more than input tokens. The ratio varies dramatically by model:

Model Input (per 1M) Output (per 1M) Output/Input Ratio
GLM-4.5 $0.15 $0.15 1.0×
DeepSeek V3 $0.15 $0.308 2.0×
Qwen3 Coder 480B $0.12 $0.36 3.0×
Qwen3-32B $0.20 $0.60 3.0×
Kimi K2.6 $1.09 $4.60 4.2×
Qwen3-235B (MoE) $0.342 $3.42 10.0×
DeepSeek R1 $0.605 $2.42 4.0×

The ratio matters because most applications are input-heavy or output-heavy, not balanced.

  • Classification/routing tasks: 200 input tokens, 10 output tokens → input cost dominates
  • Code generation: 100 input tokens, 1500 output tokens → output cost dominates
  • Long document analysis: 100K input tokens, 2K output tokens → input cost dominates by a huge margin

Cost Calculator

Here's a precise cost calculator using real AIWave pricing:

# Real pricing data (USD per 1M tokens)
PRICING = {
    "ernie-4.0-turbo-8k":    {"input": 0.001, "output": 0.001, "context": "128K"},
    "ernie-4.0-8k":           {"input": 0.005, "output": 0.005, "context": "8K"},
    "ernie-tiny-8k":          {"input": 0.178, "output": 0.178, "context": "8K"},
    "qwen3-coder-480b":       {"input": 0.120, "output": 0.360, "context": "128K"},
    "deepseek-v3":            {"input": 0.150, "output": 0.308, "context": "64K"},
    "deepseek-v4-pro":        {"input": 0.420, "output": 0.840, "context": "1M"},
    "glm-5":                  {"input": 1.000, "output": 3.190, "context": "128K"},
    "kimi-k2.6":              {"input": 1.090, "output": 4.600, "context": "128K"},
    "ernie-5.1":              {"input": 2.055, "output": 2.055, "context": "8K"},
}

def calculate_cost(model: str, input_tokens: int, output_tokens: int) -> float:
    """Calculate exact cost for a single API call."""
    p = PRICING[model]
    return (input_tokens * p["input"] + output_tokens * p["output"]) / 1_000_000


def compare_models(task_name: str, input_t: int, output_t: int, models: list[str]):
    """Compare costs across models for a specific task profile."""
    print(f"\n{task_name}")
    print(f"  Input: {input_t:,} tokens | Output: {output_t:,} tokens")
    print(f"  {'Model':<25s} {'Cost':>10s} {'Context':>8s}")
    print(f"  {'-'*25} {'-'*10} {'-'*8}")
    results = []
    for m in models:
        cost = calculate_cost(m, input_t, output_t)
        ctx = PRICING[m]["context"]
        results.append((m, cost, ctx))
        print(f"  {m:<25s} ${cost:>9.4f} {ctx:>8s}")
    return results


# Task 1: Simple routing/classification
compare_models(
    "Task 1: Text Classification (200 in, 10 out)",
    200, 10,
    ["glm-4.7-flash", "ernie-tiny-8k", "deepseek-v3", "kimi-k2.6"]
)

# Task 2: Code generation
compare_models(
    "Task 2: Code Generation (150 in, 1500 out)",
    150, 1500,
    ["qwen3-coder-480b", "deepseek-v3", "deepseek-v4-pro", "ernie-5.1"]
)

# Task 3: Long document summarization
compare_models(
    "Task 3: 100K Document Analysis (100000 in, 2000 out)",
    100_000, 2000,
    ["deepseek-v4-pro", "kimi-k2.6", "glm-5", "qwen3-coder-480b"]
)
Enter fullscreen mode Exit fullscreen mode

Output:

Task 1: Text Classification (200 in, 10 out)
  Input: 200 tokens | Output: 10 tokens
  Model                         Cost   Context
  -------------------------  ---------- --------
  glm-4.7-flash              $0.0000     128K
  ernie-tiny-8k              $0.0000       8K
  deepseek-v3                 $0.0000       64K
  kimi-k2.6                   $0.0002     128K

Task 2: Code Generation (150 in, 1500 out)
  Input: 150 tokens | Output: 1500 tokens
  Model                         Cost   Context
  -------------------------  ---------- --------
  qwen3-coder-480b            $0.0006     128K
  deepseek-v3                  $0.0005       64K
  deepseek-v4-pro              $0.0013       1M
  ernie-5.1                    $0.0034       8K

Task 3: 100K Document Analysis (100000 in, 2000 out)
  Input: 100,000 tokens | Output: 2000 tokens
  Model                         Cost   Context
  -------------------------  ---------- --------
  deepseek-v4-pro              $0.0437       1M
  kimi-k2.6                    $0.1182     128K
  glm-5                        $0.1064     128K
  qwen3-coder-480b             $0.0127    128K
Enter fullscreen mode Exit fullscreen mode

Model Selection Strategy by Task

Based on the pricing data, here's an evidence-based model selection guide:

Classification, Routing, Simple Q&A

Use GLM-4.7-Flash ($0.03/1M) or ERNIE Tiny ($0.178/$0.178).

The budget tier of GLM-4.7-Flash at $0.03/1M supports 128K context and scores 72.5% on HumanEval. For routing, classification, and simple queries, there's no reason to spend more. Only switch to a paid model if accuracy drops below your threshold.

Code Generation and Review

Use Qwen3 Coder 480B ($0.12/$0.36) for most tasks.

88.4% HumanEval at 3.0× output/input ratio is a strong deal. At 128K context, it handles full-file refactoring. Only escalate to DeepSeek V4 Pro ($0.42/$0.84) for tasks requiring 1M+ context or when you need its 92.1% HumanEval score.

Deep Reasoning and Math

Use DeepSeek R1 ($0.605/$2.42) or DeepSeek V4 Pro ($0.42/$0.84).

V4 Pro is cheaper and faster for most reasoning tasks. Reserve R1 for the hardest problems where its chain-of-thought approach justifies the 4.0× output premium.

Long Document Analysis

Use DeepSeek V4 Pro ($0.42/$0.84) or Qwen3 Coder 480B ($0.12/$0.36).

Both support large context windows (1M and 128K respectively). For documents under 128K tokens, Qwen3 Coder is 3.6× cheaper on input. For documents exceeding 128K, V4 Pro's 1M context is the only option in this price range.

General-Purpose Chatbot

Tier your approach:

  1. GLM-4.7-Flash ($0.03/1M) for greetings and simple lookups
  2. DeepSeek V3 ($0.15/$0.308) for moderate queries
  3. Kimi K2.6 ($1.09/$4.60) only for complex, multi-turn conversations requiring high-quality responses

Cost Optimization Strategies

1. Systematic Prompt Trimming

Every unnecessary token in your prompt costs money. Especially with input-heavy tasks:

def trim_prompt(system_prompt: str, user_prompt: str, max_tokens: int = 500) -> tuple[str, str]:
    """Ensure total input stays under budget."""
    total = estimate_tokens(system_prompt + user_prompt)
    if total <= max_tokens:
        return system_prompt, user_prompt

    # Trim system prompt first (usually has more redundancy)
    ratio = max_tokens / total
    trimmed_system = system_prompt[:int(len(system_prompt) * ratio * 0.7)]
    trimmed_user = user_prompt[:int(len(user_prompt) * ratio)]
    return trimmed_system, trimmed_user
Enter fullscreen mode Exit fullscreen mode

2. Response Length Limits

Set max_tokens appropriately. A classification response doesn't need 4096 tokens:

# Bad: default max_tokens wastes money on output
response = client.chat.completions.create(model="kimi-k2.6", messages=msgs)

# Good: limit to what you actually need
response = client.chat.completions.create(
    model="kimi-k2.6",
    messages=msgs,
    max_tokens=100  # Classification only needs a few words
)
Enter fullscreen mode Exit fullscreen mode

3. Caching Layer

For repeated queries or similar prompts, implement a semantic cache:

from hashlib import md5

class TokenCache:
    def __init__(self):
        self._cache: dict[str, dict] = {}

    def get(self, messages: list[dict]) -> dict | None:
        key = md5(str(messages).encode()).hexdigest()
        return self._cache.get(key)

    def set(self, messages: list[dict], result: dict, ttl_seconds: int = 3600):
        key = md5(str(messages).encode()).hexdigest()
        self._cache[key] = result
Enter fullscreen mode Exit fullscreen mode

A cache hit rate of just 15% on a 10K daily request volume can save hundreds of dollars monthly.

4. Batch Processing

For non-real-time tasks (document processing, analysis), batch requests during off-peak hours when some providers offer lower pricing.

The Compound Effect

Small per-request savings compound. Consider a team processing 5,000 documents per week:

Strategy Model Cost/Doc Weekly Cost
No optimization Kimi K2.6 (100K input) $0.109 $545.00
Router + budget tier triage GLM-4.7-Flash (60%), K2.6 (40%) $0.044 $218.00
Router + cheapest adequate model GLM-4.7-Flash (60%), Qwen3 Coder (40%) $0.0051 $25.40

From $81 to $5 per week — a 16× reduction — by choosing the right model for each subtask instead of using one model for everything.

Start Optimizing

Understanding token economics is the highest-ROI skill for teams building with AI APIs. The difference between a $100/month AI bill and a $1,000/month bill often comes down to model selection and prompt efficiency — not the volume of requests.

Sign up | Pricing | Discord


All pricing in this guide reflects AIWave rates as of July 2026. Verify current prices at aiwave.live/pricing.

Top comments (0)