OpenClaw on Ollama: Budgets and Context Discipline

OpenClaw on Ollama: Budgets and Context Discipline

OpenClaw is the most token-hungry tool in my stack, and it is not close. Claude Code burns credits in bursts when I sit down to work. OpenClaw burns them continuously, because it runs continuously — heartbeats, scheduled jobs, memory consolidation — and it carries a persistent identity and memory into every single turn.

That makes it the best case study for the discipline this series is about. If you can run OpenClaw comfortably inside $60 of Ollama credits, everything else is easy.

This is Part 2 of a three-part series. Part 1 covers the plans, the pricing math, and why agent loops multiply cost. Part 3 covers the other tools and what to do when you run out. Pricing references are as of September 2026.

Connecting OpenClaw to Ollama

The fast path is one command:

ollama launch openclaw

It installs OpenClaw if you do not have it, prompts for a model, and writes the config. If you want to make the decisions yourself, openclaw onboard walks the full setup.

There are three shapes this can take:

ModeWhat runsWhen to use it
Cloud + LocalOne signed-in Ollama daemon serving both cloud and local modelsDefault. Cloud for real work, local for overflow and embeddings
Cloud onlyThe ollama-cloud provider, no daemon at allServers, VPS, anything without useful local hardware
Local onlyLocal daemon, no cloud modelsAir-gapped, or when credits are gone

Cloud + Local is what I run. It means a single ollama signin unlocks cloud models while the same daemon keeps nomic-embed-text warm for memory embeddings, which OpenClaw auto-pulls the first time it needs them.

Never point OpenClaw at /v1

This is worth its own heading because it costs people hours.

{
  provider: {
    ollama: {
      // Correct — native /api/chat endpoint
      baseUrl: "http://localhost:11434",
      apiKey: "ollama-local",
    },
  },
}

Do not append /v1. That is the OpenAI-compatibility shim, and OpenClaw’s Ollama provider does not want it. The symptom when you get this wrong is distinctive: tool calling degrades or stops working entirely, and you start seeing raw tool-call JSON printed in the reply as ordinary text instead of being executed. If your agent is narrating its tool calls at you rather than making them, check the base URL first.

The apiKey value is an auth marker, not a secret. Use the literal string ollama-local for loopback, LAN, and .local hosts. A real OLLAMA_API_KEY is only needed when the baseUrl is https://ollama.com or a public remote.

Model configuration and fallback chains

agents.defaults.model takes a primary and an ordered list of fallbacks:

{
  agents: {
    defaults: {
      model: {
        primary: "ollama/glm-5.3-flash:cloud",
        fallbacks: [
          "ollama/glm-5.3:cloud",
          "ollama/gemma4:31b-cloud",
          "ollama/nemotron-3-super:cloud",
          "github-copilot/claude-opus-5",
          "github-copilot/claude-sonnet-5",
          "ollama/deepseek-v4.1-flash:cloud",
          "google/gemini-2.5-pro",
        ],
      },
    },
  },
}

That is close to my own running config, trimmed for the example. Two things worth calling out about it that are easy to miss on a first read:

  • glm-5.3-flash is the primary, not nemotron-3-super. For a while nemotron-3-super was the obvious cheap default — it is still the lowest sticker price on the rate table. But glm-5.3-flash costs about the same in practice and is noticeably better at agentic tool use, so it is what I actually reach for now. Cheapest-on-paper and cheapest-in-practice are not always the same model. glm-5.3-flash is not in Part 1’s rate table, so check its current rate at ollama.com/pricing before you copy this config.
  • The chain does not have to stay inside Ollama. Once the Ollama tiers are exhausted the chain above escalates to github-copilot and google providers before it gives up. A fallback chain’s job is “keep working,” and it does not care whether the next link is billed in Ollama credits or somewhere else entirely.

A fallback chain is not paranoia. There are three concrete failure modes it covers:

  1. Model retirement. Ollama retires models on a rolling schedule. minimax-m2.5 and kimi-k2.5 were retired on 2026-07-31, superseded by minimax-m2.7 and kimi-k2.6 — and the current Kimi model in Part 1’s table is already kimi-k3. An earlier round on 2026-07-15 took out deepseek-v3.1:671b, qwen3-coder:480b, and the entire gemma3 family. Pin nothing forever. A hardcoded model name in a config file you wrote six months ago is a scheduled outage.
  2. Concurrency rejection. Pro gives you three concurrent requests. Requests beyond that are queued, then rejected once the queue fills. An OpenClaw instance with a heartbeat, a cron job, and you typing at it can reach three without trying.
  3. Capacity. Cloud inference has bad afternoons like everything else.

Note what the ordering is for: availability, not cost. The chain is not a smooth climb in price — it jumps to Claude Opus 5 and then drops back to a cheap DeepSeek model — because each link is simply the next thing I would rather use when the one before it is down. The fallback fires when the primary is unavailable, and you would rather keep working than stop. It is not an escalation ladder for hard problems; that is a decision you make by hand.

Advertisement

One budget warning: the github-copilot and google links do not draw on your Ollama credits. They bill against those accounts instead — your Copilot plan’s quota, your Google API billing — so a bad afternoon on Ollama can quietly move spend somewhere else. Know what those links cost before you add them.

The budget caveat nobody mentions

OpenClaw reports all Ollama model costs as 0.

Its cost accounting is built around providers that return pricing metadata. Ollama does not, in the shape OpenClaw expects, so every session shows as free. This means the built-in budget tracking, the session cost display, and any spend limits you configure will never fire for Ollama models. They are not broken; they are looking at a number that is always zero.

Practically, that leaves you with these controls:

ControlWhereWhat it does
90% usage emailollama.com settingsThe only automatic warning you will get. Leave it on.
Usage dashboardollama.com/settingsThe actual source of truth for spend. Check it weekly.
contextTokensOpenClaw model configCaps the input budget OpenClaw will assemble
maxTokensOpenClaw model configCaps output per response — and output is 3–5x input
think levelTop-level, /think, or params.thinkReasoning tokens bill as output
tools.profileOpenClaw configFewer tool schemas loaded means a smaller system prompt

The habit that matters: check ollama.com/settings, not OpenClaw. If you rely on OpenClaw’s cost display you will believe you are spending nothing right up until the 90% email arrives.

Context hygiene is the biggest lever

Part 1 established that every tool call in an agent loop replays the entire conversation. The consequence for OpenClaw is severe, because OpenClaw’s conversation starts with a large fixed prefix: identity files, memory, policies, rules, tool schemas. That prefix is billed on every step of every loop, forever.

Cutting 10k tokens from your system prompt does not save you 10k tokens. It saves you 10k tokens times every tool call you will ever make.

Measure before you cut. Ollama’s native /api/chat response includes prompt_eval_count, the number of input tokens it processed for that request. Look at it on the first turn of a fresh session and you are looking at the size of your fixed prefix. Check it again after each change below and you will know what each one bought you.

Four things that worked, in rough order of payoff:

  1. Trim the identity and memory files. These grow by accretion and nobody ever prunes them. Most of what accumulates is either stale or restates something else. Be ruthless; you can always add it back.
  2. Lazy-load rules instead of preloading. Language and domain rules do not all need to be resident. Reference them conditionally so only the relevant ones load.
  3. Let Tool Search do its job. Tool Search loads tool schemas on demand rather than preloading all of them into the system prompt. It is auto-enabled for local Ollama models; check that it is on for your cloud models too, since those are the ones you pay for. Tool schemas are verbose and you use a small fraction of them in any given turn.
  4. Stop preloading memory. Retrieve memory when it is relevant instead of carrying the whole file into every turn.

The effect is large. On a system prefix in the 40k-token range — not unusual for a well-developed OpenClaw setup — trimming to roughly 15k cuts 25k tokens off every request in every loop. Across a fifteen-step autonomous run that is 375k tokens saved on a single task. At full input rates that is about 5 cents on gemma4 and over a dollar on kimi-k3.

The honest caveat: a stable prefix is exactly what the cache serves, so most of those tokens would have been billed at the cached rate, not the full one. At cached rates the same 375k tokens is about 2 cents on gemma4 and about 11 cents on kimi-k3. Trimming still pays: the saving repeats on every task, every cache miss (a new session, an edited identity file) bills the whole prefix at full price, and a smaller prefix leaves more of your context window for actual work. It is a steady saving rather than a dramatic one per task. These are modeled estimates from the published rate table, not measurements from my account — the ratio is the point, not the absolute numbers.

Thinking control

Reasoning tokens bill at the output rate, which is three to five times input. OpenClaw gives you three places to control it:

  • Top-level think — the global default.
  • /think off|low|medium|high|max — per-turn, mid-conversation.
  • params.think — per-model, so your cheap primary and your premium escalation model can have different defaults.

My working pattern is off as the default with deliberate /think high on the turns that warrant it. Most agent turns are mechanical — read this file, run this command, apply this edit — and extended reasoning on a mechanical turn is pure waste.

Advertisement

Two details worth knowing:

  • Local compaction defaults thinking off already. Compaction is summarization; it does not need to deliberate.
  • Qwen3.5 treats low as thinking-on, not reduced-budget. Qwen3.5 is a common local model on Ollama (Part 3’s hardware table has it at 16GB). If you want reasoning off on Qwen3.5, say off. Setting low and expecting a cheaper version of thinking will surprise you on the bill.

Keeping local models warm

If you are running local models alongside cloud ones, cold-loading a 16GB model on every request is miserable. Two settings fix it:

{
  provider: {
    ollama: {
      params: {
        keep_alive: "30m",
        num_ctx: 65536,
      },
      timeoutSeconds: 300,
    },
  },
}

keep_alive holds the model in memory between requests. timeoutSeconds: 300 gives a cold load room to finish instead of failing the request — the default is short enough that a first load on a large model can time out.

Keep num_ctx and contextTokens aligned. num_ctx is what Ollama allocates for the request; contextTokens is the input budget OpenClaw will assemble. If contextTokens exceeds num_ctx, Ollama silently truncates and you get the mysterious-amnesia symptoms from Part 1. If num_ctx is much larger than contextTokens, you are just reserving memory you will never use.

Off-peak and async work

Not everything OpenClaw does needs to happen while you are watching, and not everything needs your best model.

  • Point scheduled jobs at cheap models. Nightly summarization, feed processing, and memory consolidation run fine on glm-5.3-flash or nemotron-3-super. glm-5.3-flash is priced close to nemotron-3-super but noticeably better at tool use, which is why it is the default primary in the config above rather than a fallback. This is the easiest saving available and it costs you nothing in quality on tasks that are mostly compression.
  • Schedule DeepSeek work outside 12:00–18:00 UTC Mon–Fri. As of September 2026, deepseek-v4-flash and deepseek-v4-pro are the only models with peak pricing, and they double during that window. deepseek-v4-flash also has the best cached-input rate on the platform at $0.007/M, which makes it excellent for long batch runs — as long as you keep them off the clock.
  • Use isolated sessions for background work. Anything that runs unattended should not be accumulating in your main conversation history, both for cost and for memory quality. I wrote about the memory side of this in OpenClaw Heartbeat Tuning.
  • The cron safety check helps. OpenClaw skips scheduled runs when the local daemon is unreachable rather than failing them noisily. Useful when your laptop is closed, and it means a local-model cron job degrades to “did not run” instead of “ran on the expensive cloud fallback four hundred times.”

Ollama Web Search ships with OpenClaw as a web_search provider. Configure it with:

openclaw configure --section web

For local hosts it requires ollama signin. Worth enabling — a search result is far cheaper than a model hallucinating and you spending three turns correcting it.

What actually moved the needle

If you do nothing else from this article, in priority order:

  1. Fix the base URL if it has /v1 on it.
  2. Set num_ctx and contextTokens to 64k and keep them aligned.
  3. Trim the system prefix. This is the compounding one.
  4. Default thinking to off; escalate deliberately.
  5. Put a fallback chain in place before a retirement forces you to.
  6. Bookmark ollama.com/settings, because OpenClaw will never tell you.

Part 3 covers Claude Code, Kilo Code, Cline and the rest of the ecosystem, plus a concrete plan for the month you hit 90% on day fourteen.

Related reading: One Month With an AI Assistant for the broader setup, and The Agent Who Couldn’t Remember on what happens when persistent memory is missing entirely.

Lightly corrected and edited by Grok.

Advertisement
Kevin Duane

Kevin Duane

Site reliability engineer writing first-person about AI, engineering, and productivity — what actually works in daily practice.