#How do you properly set up model routing in OpenClaw to reduce GPT-5 cost?

1 messages · Page 1 of 1 (latest)

bright mango
#

Hey everyone, I’m pretty new to OpenClaw and agent setups, and I’m realizing I probably configured things in the most expensive way possible.

Right now I’m using GPT-5.2 as my default model for basically all daily tasks (research, writing, light automation, small debugging), and I’m noticing my API costs are climbing very fast even with normal usage.

From what I’m reading here and in other threads, it sounds like the smarter approach is model routing instead of using one high-end model for everything. For example:
• Strong model for complex reasoning / coding
• Mid-tier model for routine automation
• Cheap/light model for summaries, checks, and simple tasks

My main confusion is the actual implementation inside OpenClaw.

Specifically:
1. Do you set a cheaper model as the main agent default and only escalate to GPT-5 when needed?
2. Are you using routing rules, separate agents, or tool-based model selection?
3. Where in OpenClaw config do you usually define model routing (config.yaml, agents, or provider settings)?
4. Do you also limit max iterations and max tokens to control loop costs?

My use case is mostly daily productivity workflows (not 24/7 autonomous agents):
• Research & summaries
• Marketing-related tasks
• Writing and planning
• Light coding/debugging
• Automation loops

I’m not trying to nerf performance, just stop burning tokens on tasks that don’t need a top-tier reasoning model.

If anyone has a sample config, routing strategy, or “cost-efficient stack” (like default + escalation model), I’d really appreciate seeing how you structured it.

Bonus question:
Did switching to routing actually cut your monthly API cost significantly, or was the biggest win from reducing agent loops/context size?

Any tutorial or somebody can help me with this setup. I’m new to this space.

jade agateBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

dense otterBOT
#

Yep — “model routing” in OpenClaw is mostly (a) set a cheaper default + (b) switch/escalate intentionally, or (c) run multiple agents (each with a different default model) and route chats to them.

1) Do you set a cheaper model as the main default and only escalate to GPT‑5.2?

Most people do, yes.

In OpenClaw the “default model” is:

  • agents.defaults.model.primary

Then you escalate per session with /model … when you hit something that actually needs GPT‑5.2.

Docs: https://docs.openclaw.ai/help/faq#models-defaults-selection-aliases-switching

2) Routing rules vs separate agents vs tool-based selection?

Important nuance: fallbacks are for errors/outages, not “this is a hard task, use a smarter model.”

So the common patterns are:

#
  • Per-session switching (simplest): set cheap default, then /model openai/gpt-5.2 when needed.
  • Separate agents (best if you want muscle memory + isolation): “daily” agent (cheap) + “deep work/coding” agent (GPT‑5.2), then route channels/threads to one or the other via bindings.
  • Sub-agents: you can also push specific work into sub-agents that have a different default model (handy for “do this heavy thing, then report back”).

Docs:

3) Where do you define this in config?

OpenClaw config is JSON5, usually:

  • ~/.openclaw/openclaw.json (not YAML)

Model-related keys live under:

  • agents.defaults.model.primary
  • agents.defaults.model.fallbacks (again: outage fallback, not “auto-escalate”)
#
  • agents.defaults.models (your model catalog + aliases; also acts as the /model allowlist if set)

Docs: https://docs.openclaw.ai/gateway/configuration (see “Choose and configure models”)

Minimal example skeleton (showing the shape, use whatever “cheap” model you prefer from /model list):

{
  agents: {
    defaults: {
      model: {
        primary: "<cheap-provider>/<cheap-model>",
        fallbacks: ["openai/gpt-5.2"], // fallback = only if cheap model fails
      },

      // If you set this, it becomes the allowlist for /model:
#
      models: {
        "<cheap-provider>/<cheap-model>": { alias: "daily" },

        // your expensive model:
        "openai/gpt-5.2": { alias: "gpt" },
      },

      // Optional: keep heartbeats cheap too
      heartbeat: {
        model: "<cheap-provider>/<cheap-model>",
      },
    },
  },
}
#

4) Limit max iterations / max tokens to control loop costs?

There isn’t a simple “max iterations” knob like “stop after N tool calls” (at least not as a common top-level setting people use), but you can control cost via:

  • Timeouts: agents.defaults.model.timeoutSeconds
  • Response token caps (per-model): in agents.defaults.models["provider/model"].params.maxTokens
  • How much context you carry: agents.defaults.model.contextTokens (big lever if you don’t need giant context every run)
  • Session hygiene: use /new when a thread gets huge; compaction/reset settings help too

Config reference (shows timeoutSeconds, contextTokens, and params.maxTokens):
https://docs.openclaw.ai/gateway/configuration-reference#agentsdefaultsmodel


“Did routing cut monthly cost, or was it loops/context?”

In practice: both matter, but the biggest “surprise wins” are usually:

  1. Stop using the expensive model for everything (cheap default + intentional escalation)
#
  1. Keep sessions from ballooning (context size/compaction + starting fresh when appropriate)
  2. Be careful with sub-agents (they’re great, but they multiply spend)

If you paste your current agents.defaults.model + agents.defaults.models section (redact keys), I can suggest a concrete refactor that keeps GPT‑5.2 available while making a cheaper model the day-to-day default. Also for “which cheap model is best right now,” the #models channel will have the freshest answers (the model landscape changes constantly).

bright mango
#

I was told just buy a plan use Oauth.

dense otterBOT
#

That advice is half-true, but it depends what they mean by “plan” and which provider/model you’re actually using.

OAuth doesn’t magically make openai/gpt-5.2 cheaper

In OpenClaw there’s an important split:

  • openai/* (e.g. openai/gpt-5.2) → uses an OpenAI API key and is billed pay‑per‑token.
  • openai-codex/* → uses ChatGPT OAuth (“subscription auth”) via openclaw models auth login --provider openai-codex (or the onboarding wizard). This is a different provider in OpenClaw.

So if someone told you “buy a plan + OAuth”, they likely meant use OpenAI Codex via OAuth, not “reduce GPT‑5.2 API costs”. A ChatGPT-style subscription generally does not provide API credits for openai/* models.

Docs (OAuth + Codex flow): https://docs.openclaw.ai/concepts/oauth
Provider overview: https://docs.openclaw.ai/concepts/model-providers

How to set up the OpenAI Codex OAuth flow (if that’s what you want)

On the machine running the Gateway:

#
openclaw models auth login --provider openai-codex
openclaw models status

(or openclaw onboard --auth-choice openai-codex)

Then pick it in-chat with /model (or set it as your default model in config).

If your goal is specifically “stop burning money on GPT‑5.2”

OAuth alone won’t do it. The usual fix is:

  1. set a cheaper default (agents.defaults.model.primary)
  2. keep GPT‑5.2 available and /model switch when you actually need it

If you run this and paste the top part (redact secrets), I can tell you exactly what you’re currently using and what to change:

#
openclaw models status

Also: if you tell me which “plan” you were advised to buy (ChatGPT? Claude Pro/Max?), I can map it to the right OpenClaw auth flow (OpenAI Codex = OAuth; Anthropic subscription = setup-token, not OAuth).

bright mango
#

I am not sure what to use. I used chatgpt because I had a plan at this point the plan does not matter lol. I am trying use what can help me the best with this task:

My use case is mostly daily productivity workflows (not 24/7 autonomous agents):
• Research & summaries
• Marketing-related tasks
• Writing and planning
• Light coding/debugging
• Automation loops

I copied and paste what it shows when i put openclaw models status:

Config : ~.openclaw\openclaw.json
Agent dir : ~.openclaw\agents\main\agent
Default : openai/gpt-5.2
Fallbacks (0) : -
Image model : -
Image fallbacks (0): -
Aliases (2) : GPT -> openai/gpt-5.1-codex, gpt -> openai/gpt-5.2
Configured models (2): openai/gpt-5.1-codex, openai/gpt-5.2

Auth overview
Auth store : ~.openclaw\agents\main\agent\auth-profiles.json
Shell env : off
Providers w/ OAuth/tokens (1): openai (1)

  • openai effective=profiles:~.openclaw\agents\main\agent\auth-profiles.json | profiles=1 (oauth=0, token=1, api_key=0) | openai:manual=token:sk-proj-...LGdXIyEA | env=sk-proj-...LGdXIyEA | source=env: OPENAI_API_KEY
dense otterBOT
#

Your models status output is actually super helpful — it says you’re 100% on the OpenAI API (pay‑per‑token) path right now:

  • Default: openai/gpt-5.2 (expensive)
  • No fallbacks
  • Only 2 models are “allowed/configured” (so /model can’t pick anything else until you add it)
  • Auth is coming from an API key (OPENAI_API_KEY), not OAuth

So the “I have a ChatGPT plan → use OAuth” thing doesn’t apply to your current setup unless you explicitly add the openai-codex OAuth provider.

What I’d do for your exact use case (daily productivity)

A) Keep GPT‑5.2, but stop using it as the default

Make a cheaper model your default for:

  • research + summaries
  • marketing/writing/planning
  • “light” debugging

Then escalate per session to GPT‑5.2 only when it’s actually warranted.

#

In OpenClaw terms:

  • set agents.defaults.model.primary → cheap
  • keep openai/gpt-5.2 in your agents.defaults.models list as the “big hammer”
  • switch with /model ... when needed

Because you currently have an allowlist (Configured models (2)), you must add the cheaper model to agents.defaults.models too.

Example shape (edit ~\.openclaw\openclaw.json):

{
  agents: {
    defaults: {
      model: {
        primary: "<pick-a-cheaper-provider/model-here>",
        fallbacks: ["openai/gpt-5.2"] // optional: only for outages/errors
#
      },
      models: {
        "<pick-a-cheaper-provider/model-here>": { alias: "daily" },
        "openai/gpt-5.2": { alias: "gpt" }
      }
    }
  }
}

Then in chat you’ll do:

  • /model daily (normal life)
  • /model gpt (hard tasks)

How to pick the cheap model without guessing

Run one of these on the gateway machine:

#
openclaw models list --all

(or narrower if you want to stay on OpenAI only:)

openclaw models list --all --provider openai

Pick something that’s clearly positioned as a cheaper/smaller “daily driver”, then paste that exact provider/model into the config above.

B) If you want to use your ChatGPT subscription: add Codex OAuth (optional)

This is the “plan + OAuth” path — it’s separate from openai/* API-key billing:

#
openclaw models auth login --provider openai-codex
openclaw models status

After that you’ll see openai-codex/... models available, and you can /model switch to them. Whether this is a win depends on your plan limits + how well those models match your tasks, but that’s the correct way to try it in OpenClaw.

Docs: https://docs.openclaw.ai/concepts/oauth

Biggest hidden cost lever (besides model choice): context + runaway loops

Two quick habits that help a lot:

  • Use /new when a task is done (don’t drag a huge thread into a tiny question)
  • Turn on cost visibility while tuning: /usage tokens or /usage cost

Docs: https://docs.openclaw.ai/tools/slash-commands#usage-surfaces-what-shows-where


#

If you paste your current agents.defaults block from ~\.openclaw\openclaw.json (just that section; redact keys), I can tell you exactly what to change and where. Also: do you want to stay OpenAI-only for simplicity, or are you open to adding a second provider for a cheaper default?

bright mango
#

Can you help me a little with where I can find tge file to make these changes. I want to do a cheaper second provider, and use my plan since i am already paying for it

#

With these commands can i use it in my chat or only on gateway.

dense otterBOT
#

Yep — on Windows that ~\.openclaw\openclaw.json is literally in your user profile.

Where the file is

OpenClaw’s config file is:

  • %USERPROFILE%\.openclaw\openclaw.json
    • e.g. C:\Users\YourName\.openclaw\openclaw.json

Quick ways to open it:

PowerShell

notepad $env:USERPROFILE\.openclaw\openclaw.json
# or if you use VS Code:
code $env:USERPROFILE\.openclaw\openclaw.json
#

Or via the Control UI

  • Open the dashboard (usually) http://127.0.0.1:18789
  • Go to Config tab
  • Use the Raw JSON editor (this is often the easiest/least error-prone)

Docs: https://docs.openclaw.ai/gateway/configuration

“Use my plan” = set up OpenAI Codex OAuth

Since you’re paying for a ChatGPT/Codex-style plan, the OpenClaw piece you want is:

openclaw models auth login --provider openai-codex
openclaw models status

Docs: https://docs.openclaw.ai/concepts/oauth

#

That will add an openai-codex/... provider you can select with /model.

Add a cheaper second provider (pay‑per‑token) alongside your plan

High level steps:

  1. Add the provider + auth (API key) for your “cheap” provider (best to pick one from openclaw models list --all or ask in #models).
  2. Put both models into agents.defaults.models (because right now you have an allowlist, so /model can’t see anything else).
  3. Decide your default:
    • If you want to “use the plan by default” → set agents.defaults.model.primary to the openai-codex/... model.
    • Keep the cheap model as daily so you can switch with /model daily.

After you edit, re-run:

openclaw models status

…and in chat:

#
/model list

If you paste your current agents.defaults section from openclaw.json (no secrets), I’ll rewrite it into a working “plan model + cheap model” setup with the exact fields in the right places.

#

Good question — some are gateway/terminal commands, some you can do directly in chat.

In chat (Discord/Telegram/etc.)

You can do these in chat:

  • Switch models for the current session:
    • /model
    • /model list
    • /model <number>
    • /model openai/gpt-5.2
  • Start fresh (optionally with a model hint):
    • /new
    • /new gpt
  • Show model/auth details (read-only):
    • /model status

(These are chat commands; they don’t require you to SSH into the gateway.)

#

Docs: https://docs.openclaw.ai/tools/slash-commands

On the gateway machine (terminal/PowerShell)

These must be run on the machine where the Gateway is installed/running (or at least where OpenClaw can access its state dir):

  • openclaw models auth login --provider openai-codex âś… (this is the OAuth login flow)
  • openclaw models status
  • openclaw models list --all
  • Editing ~/.openclaw/openclaw.json

Reason: OAuth tokens + config live in the gateway state directory (~\.openclaw\... on Windows), so the login flow needs to write there.

Practical workflow

  1. On gateway (once): run the OAuth login command and set up any API keys/providers.
  2. In chat (daily): use /model to switch between your “plan” model and your cheaper model.

If you tell me what surface you’re chatting from (Discord? Telegram?) and whether your gateway is local Windows or a remote VPS, I can give you the exact easiest path.

bright mango
#

I am in the config which one is it under