Optimizing AI Agent Costs: My Model Plan for Oh My Pi

Posted in development on September 22, 2026 by Adrian Wyssmann ‐ 3 min read

If you use agentic coding tools like Oh My Pi (OMP), you quickly realize how fast token usage adds up. Every multi-file read, LSP check, and terminal loop generates context tokens. If you route everything through top-tier paid models, running your local coding setup gets expensive fast. I updated my models.yml setup in OMP to lower my API bills without giving up agent performance.

Here is how I organized my model routing. While my primary paid tier is ollama cloud whith deepseek-v4.1-flash as primary LLM, I enhance it with some free tiers from Cloudflare and Mistral.

The Core Shift: DeepSeek V4.1 Flash over V4 Pro

A common assumption in AI is that bigger MoE models are always better. In practice with coding agents, that isn’t always true.

I recently switched my primary driver from ollama-cloud/deepseek-v4-flash to ollama-cloud/deepseek-v4.1-flash.

  1. Better Agentic Coding — On repository-level coding benchmarks (like DeepSWE v1.1), V4.1 Flash scores higher (74.2%) than DeepSeek V4 Pro (62.7%).
  2. Terminal Operations — It handles CLI execution loops and file tool-calling cleanly (90.6% on Terminal-Bench).
  3. Cost Efficiency — At ~$0.15 per 1M tokens, it runs roughly 4x cheaper than V4 Pro while keeping a 1-million-token context window.

For day-to-day development, V4.1 Flash works as the primary workhorse.

Zero-Cost Routing: Cloudflare Workers AI & Mistral

To keep token usage lean, I offload smaller background tasks to free tiers:

  • Cloudflare Workers AI — Cloudflare offers 10,000 Neurons/day for free. That is plenty for light workloads. I mapped @cf/meta/llama-3.2-3b-instruct to handle small jobs like git commit message generation and status labels.
  • Mistral AI — I use mistral-ai/codestral-latest for subagent routines (task role) because it handles local code context cleanly.

Role Assignment in OMP

Instead of letting OMP hit the default model for every background request, I map specific jobs to specific models:

RoleModelPurpose
defaultollama-cloud/deepseek-v4.1-flashMain coding loop
taskmistral-ai/codestral-latestSubagent delegations
smol / commitcloudflare-workers-ai/@cf/meta/llama-3.2-3b-instructZero-cost lightweight tasks
slow / plan / advisorollama-cloud/deepseek-v4-proComplex architectural planning

The Configuration (models.yml)

Here is my full models.yml file with providers, fallback cascades, and model roles configured:

providers:
  ollama-cloud:
    api_base: https://ollama.com/api
    api_key: ${OLLAMA_CLOUD_API_KEY}
    models:
      - id: deepseek-v4.1-flash
        context_window: 1000000
        cost_per_1m_tokens: 0.15
      - id: deepseek-v4-pro
        context_window: 128000
        cost_per_1m_tokens: 0.60

  mistral-ai:
    api_base: https://api.mistral.ai/v1
    api_key: ${MISTRAL_API_KEY}
    models:
      - id: codestral-latest
        context_window: 256000

  cloudflare-workers-ai:
    api_base: https://api.cloudflare.com/client/v4/accounts/${CF_ACCOUNT_ID}/ai/run
    api_key: ${CF_API_TOKEN}
    free_tier:
      neurons_per_day: 10000
    models:
      - id: "@cf/meta/llama-3.2-3b-instruct"
        context_window: 8192

roles:
  default:
    model: ollama-cloud/deepseek-v4.1-flash
    fallback:
      - ollama-cloud/deepseek-v4-pro

  task:
    model: mistral-ai/codestral-latest
    fallback:
      - ollama-cloud/deepseek-v4.1-flash

  smol:
    model: cloudflare-workers-ai/@cf/meta/llama-3.2-3b-instruct
    fallback:
      - mistral-ai/codestral-latest

  commit:
    model: cloudflare-workers-ai/@cf/meta/llama-3.2-3b-instruct
    fallback:
      - mistral-ai/codestral-latest

  slow:
    model: ollama-cloud/deepseek-v4-pro
    fallback:
      - ollama-cloud/deepseek-v4.1-flash

  plan:
    model: ollama-cloud/deepseek-v4-pro
    fallback:
      - ollama-cloud/deepseek-v4.1-flash

  advisor:
    model: ollama-cloud/deepseek-v4-pro
    fallback:
      - ollama-cloud/deepseek-v4.1-flash