Skip to content
Guide Intermediate 10 min

Optimizing AI workflow costs: method and real numbers

Sébastien Giband · Dev Symfony/TypeScript · multi-model routing in production · · Updated on
Claude Code Anthropic Max z.ai GLM-5.1 Claude Sonnet 4.5 PHP/Symfony 7 TypeScript/React

TL;DR

Route mechanical tasks to budget or free models (MiniMax 2.5 via Kilo Gateway, Gemini Flash), reserve premium models for reasoning. Result: mechanical tasks (~65% of volume) cost nothing, with no perceived quality loss.

inference-cost kilo-code kilo-gateway workflow optimization

Update, July 2026 — the detailed numbers in this guide date from the Kilo Gateway/MiniMax period, which I’ve since abandoned. My current setup: Claude Code on the Max subscription ($100/mo) for daily work, z.ai Pro (~$72/mo, GLM-5.2, price verified July 2026) as a tested budget route — usable directly inside Claude Code. The task-based routing method itself hasn’t moved.

Optimizing AI workflow costs isn’t about being stingy — it’s engineering. Choosing the right tool for each task type, measuring consumption, adjusting. Exactly how you’d size infrastructure.

This guide documents the method and real numbers after several months of daily production usage on a Symfony/TypeScript project.

What’s the starting point?

Starting point: workflow running exclusively on Claude Code with the Anthropic subscription. Cost: flat-rate but single-provider — zero visibility into which task consumes what, and no lever to adjust it.

When Anthropic restricted the use of the Claude Code subscription in third-party tools, migrating to OpenCode then Kilo Code CLI (its fork) became necessary. With it came the ability to route tasks by model — and the discovery that 65% of the work can run on free models.

Why not all tokens are equal

The key to optimization is understanding that inference cost is a variable, not a constant. It depends on the model, and the optimal model depends on the nature of the task.

Two categories of coding tasks:

Mechanical tasks — the pattern is known, the result is predictable, the generated code follows an established template:

  • Boilerplate unit tests (PHPUnit, Vitest)
  • Doctrine schema migrations
  • DTO, Value Object, interface generation
  • Documenting existing methods
  • Mechanical renames and refactors
  • Test fixtures

Reasoning tasks — business context matters, architecture must be understood, decisions aren’t obvious:

  • Refactoring with interface and compatibility constraints
  • Debugging unexpected behavior
  • Architecture and pattern design
  • Complex or legacy code analysis
  • Integrations with non-trivial side effects

On mechanical tasks, a budget model produces results indistinguishable from a premium model in practice. On reasoning tasks, the difference is real and justifies the higher cost.

Which models for which roles?

After comparison on real tasks (not synthetic benchmarks) on the Symfony/TypeScript stack:

Mechanical tasks → MiniMax 2.5 (free via Kilo Gateway)

API price: free via Kilo Gateway
Context  : 128k tokens — more than sufficient for mechanical tasks

MiniMax 2.5 produces idiomatic PHP and TypeScript on common patterns. On PHPUnit unit test generation with fixtures, the result is practically identical to Claude Sonnet. The correction rate in review is comparable — on this type of structured task, the difference isn’t perceptible.

High-volume or long-context tasks -> Gemini 2.0 Flash

API price: $0.075/M tokens input · $0.30/M tokens output
Context  : 1M tokens

Gemini Flash is useful when the task requires loading many files simultaneously — a schema migration touching 15 entities, analyzing an entire module to extract its logic. The million-token context means you don’t need to split the session.

Reasoning tasks -> Claude Sonnet 4.5

API price: $3/M tokens input · $15/M tokens output
Context  : 200k tokens

Refactoring with interface constraints, debugging cryptic behavior, architecture design with multiple business constraints. The cost is justified by reasoning quality — particularly on Symfony code with advanced patterns (Event Sourcing, CQRS).

How do you set up routing?

Today: premium subscription + budget subscription in parallel

My current setup (July 2026): Claude Code on the Max subscription ($100/mo) for reasoning and daily work, and z.ai Pro (~$72/mo, GLM-5.2) as the budget provider — z.ai is directly compatible with Claude Code, the switch is a configuration change. The principle: risky tasks go to the premium model, mechanical work to the budget one, and the split is a documented choice, not a per-session mood.

Back then: Kilo Code CLI + Kilo Gateway (abandoned setup, kept for the record)

Kilo Code CLI (fork of OpenCode) integrated Kilo Gateway, which provided access to free models including MiniMax 2.5 — zero cost on mechanical tasks, until the free tier stopped being worth it.

# In the Kilo Code CLI TUI: press 'm' to switch models
# MiniMax 2.5 (free at the time) for mechanical tasks
# Claude Sonnet for reasoning

With OpenCode + OpenRouter

OpenRouter is an OpenAI-compatible API proxy that gives access to dozens of models via a single key:

// ~/.config/opencode/config.json
{
  "providers": {
    "openrouter": {
      "apiKey": "sk-or-..."
    },
    "anthropic": {
      "apiKey": "sk-ant-..."
    }
  },
  "model": "openrouter/google/gemini-2.0-flash-001"
}

With Kilo Code (VS Code) + OVH AI Gateway

OVH AI Gateway is an OpenAI-compatible proxy hosted in Europe. It centralizes access to multiple providers (Anthropic, Gemini, Mistral) via a single key, with per-team consumption tracking.

// Kilo Code configuration (VS Code settings.json)
{
  "kilocode.apiProvider": "openai-compatible",
  "kilocode.openaiCompatible.baseUrl": "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1",
  "kilocode.openaiCompatible.apiKey": "your-ovh-key",
  "kilocode.openaiCompatible.model": "gemini-2.0-flash-001"
}

What are the real numbers?

Current breakdown at the same usage intensity (Symfony/TypeScript project, ~6-8h of active sessions per workday):

Multi-model routing with Kilo Code CLI
  ~65% of sessions: MiniMax 2.5 (mechanical tasks) → free via Kilo Gateway
  ~20% of sessions: Gemini Flash (long context)    → a few dollars/month
  ~15% of sessions: Claude Sonnet (reasoning)      → variable by intensity

The majority of work volume costs nothing. The bill comes down to premium sessions (Sonnet, Gemini). Perceived quality on deliverables hasn’t changed — PRs are the same quality, code reviews haven’t flagged any regression.

How do you identify which tasks are mechanical?

The practical question: before starting a session, could I write the expected result as a template with variables? If yes, it’s a mechanical task.

✅ Mechanical: "write unit tests for [service] covering
   [nominal, exception, null value] cases"

✅ Mechanical: "create a DTO for [entity] with fields [list]"

❌ Reasoning: "identify why this service produces inconsistent
   results depending on the user context"

❌ Reasoning: "propose an architecture to decouple [module A]
   from [module B] without breaking the existing interface"

Over time, the distinction becomes intuitive. For the first two or three weeks, it’s worth explicitly asking yourself the question before each session.

When does cost optimization become a team topic?

For a solo dev with moderate usage, optimization stays a personal call — the setup complexity doesn’t always justify the savings. Past 3+ devs or intensive usage running into tens of dollars a month, it changes nature: the budget becomes a governance decision, not an individual optimization. Someone has to decide the team’s default model, document the routing in a versioned file, and arbitrate cost vs. capability at the project level — not at the session level.

Resources

Frequently Asked Questions

Does quality actually degrade with budget models?
On repetitive mechanical tasks — boilerplate unit tests, schema migrations, documentation, mass renames, type conversions — no. The perceived quality difference is marginal. On complex reasoning tasks (architecture, cryptic debugging, refactoring with heavy business context), yes — and that's why you don't route everything to the budget model.
How do you measure actual consumption?
OpenRouter provides a consumption dashboard by model and by day. OVH AI Gateway does too. The simplest starting point: note the cost at the beginning and end of a typical week, break it down by session type. The tracking tool isn't the starting point — conscious routing is.
What's the risk of switching models mid-project?
Minimal if you switch between models of comparable capability. The real risk is switching models during a long session — the style can drift. Best practice: switch models only at the start of a session, never mid-session. With OpenCode, it's a single command before you start.
OpenRouter vs direct provider API: when to use which?
OpenRouter if you want access to multiple providers without managing multiple API keys and billing accounts. Direct API if you use a single provider exclusively and latency is critical (OpenRouter adds ~50-100ms). For a mixed multi-provider workflow, OpenRouter simplifies things enough that the slight extra latency is negligible.
Is cost optimization worth the configuration investment?
For a solo dev with moderate usage (~$10-15/month), probably not — the added complexity doesn't justify the savings. For a team of 3+ devs or intensive usage exceeding $30/month, definitely yes. The break-even on setup time (~2h) is reached within a few weeks. See below: past that point, it's a team topic.