How to Set Up OpenClaw with ANT (Step-by-Step)
·10 min read
⚙️

How to Set Up OpenClaw with ANT (Step-by-Step)

A practical guide to connecting OpenClaw to ANT for dynamic model routing. Covers configuration, virtual models, routing pipeline, cost impact, and troubleshooting.

guideopenclawsetuprouting

OpenClaw is a terminal-based AI coding agent. It handles code generation, refactoring, debugging, and file operations from your CLI. By default, it sends every request to a single model — typically Claude or GPT-4o.

ANT is a routing layer that sits between your application and LLM providers. It classifies each request, scores available models, and routes to the best one for that specific task. It speaks the OpenAI API, so any compatible tool works without code changes.

Connecting OpenClaw to ANT means every request gets routed to the optimal model — simple tasks go to fast/free models, complex tasks go to premium ones. You get lower costs, better latency on simple tasks, and automatic failover if a provider goes down.

Architecture Overview

Without ANT, OpenClaw sends every request directly to one provider:

text
Default:     OpenClaw ──▶ Claude API (every request)

With ANT:    OpenClaw ──▶ ANT ──▶ Classify ──▶ Route ──▶ Best Model
                                                          ├─ Groq (Llama 3.3 70B)
                                                          ├─ NVIDIA NIM (DeepSeek V3)
                                                          ├─ Anthropic (Claude)
                                                          ├─ OpenAI (GPT-4o)
                                                          ├─ Google (Gemini 2.5 Flash)
                                                          └─ 30+ more providers

ANT replaces the single provider connection with a routing pipeline. OpenClaw doesn't know or care which model handles the request — it gets a response back in the same format as before.

Prerequisites

  • •OpenClaw installed and working (any version that supports custom providers)
  • •An Antbase account — sign up at antbase.ai/register
  • •An API key from the Antbase dashboard (Settings > API Keys)
  • •Access to ~/.openclaw/openclaw.json (OpenClaw's config file)

Step 1: Get Your ANT API Key

Log in to the Antbase dashboard at antbase.ai/app. Go to API Keys and create a new key. Copy it — you'll need it in the next step.

Store the key in your shell environment so OpenClaw can read it:

bash
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export ANT_API_KEY="ant_your-api-key-here"

# Reload your shell
source ~/.zshrc

Step 2: Configure OpenClaw Provider

Open your OpenClaw config file and add ANT as a provider:

json
// ~/.openclaw/openclaw.json
{
  "providers": {
    "antbase": {
      "baseUrl": "https://antbase.ai",
      "apiKey": "${ANT_API_KEY}",
      "api": "anthropic-messages",
      "models": [
        { "id": "auto", "name": "ANT Auto", "reasoning": true, "input": ["text"], "contextWindow": 200000, "maxTokens": 8192 },
        { "id": "best", "name": "ANT Best", "reasoning": true, "input": ["text"], "contextWindow": 200000, "maxTokens": 16384 },
        { "id": "fast", "name": "ANT Fast", "reasoning": false, "input": ["text"], "contextWindow": 128000, "maxTokens": 4096 },
        { "id": "free", "name": "ANT Free", "reasoning": false, "input": ["text"], "contextWindow": 131072, "maxTokens": 8192 },
        { "id": "reasoning", "name": "ANT Reasoning", "reasoning": true, "input": ["text"], "contextWindow": 200000, "maxTokens": 16384 },
        { "id": "coder", "name": "ANT Coder", "reasoning": true, "input": ["text"], "contextWindow": 200000, "maxTokens": 16384 }
      ]
    }
  }
}

Field reference:

  • •baseUrl — ANT's endpoint. All requests go here instead of directly to a model provider.
  • •apiKey — Your Antbase API key. Uses ${ANT_API_KEY} to read from your environment.
  • •api — Protocol. ANT supports anthropic-messages format for OpenClaw compatibility.
  • •models — Virtual models available for selection. Each maps to a routing preset in ANT.

Step 3: Use ant:auto for Dynamic Routing

Set your default model to antbase/auto. This tells ANT to classify every request and route it to the best available model based on task type, complexity, and your preference weights.

bash
# Set as default provider
openclaw -p antbase

# Or specify per-request
openclaw -m antbase/auto "refactor this function to use async/await"

What happens internally when you send a request with ant:auto:

  • •ANT's classifier tags the request — task type (coding, reasoning, creative, etc.), complexity (simple/medium/complex), required capabilities (vision, tools, reasoning)
  • •Optional prompt optimizer compresses redundant tokens (20-40% savings when enabled)
  • •Router scores all available models using a weighted formula: quality fit + cost + latency + provider health
  • •Request is forwarded to the highest-scoring model. If it fails, ANT re-scores and falls back to the next-best model from a different provider

Step 4: Optional — Use ant:free for Zero-Cost Requests

ant:free routes exclusively through free-tier providers. No credits are consumed. ANT maintains a pool of free models across NVIDIA NIM, Groq, Cerebras, Gemini, Mistral, and others.

bash
# Use free routing for a session
export OPENCLAW_MODEL="antbase/free"

# Or per-request
openclaw -m antbase/free "explain what this regex does"

Tradeoffs:

  • •Free models are capable — DeepSeek V3, Llama 3.3 70B, Gemini 2.5 Flash — but not frontier-class.
  • •Rate limits are lower. If the free pool is saturated, you get an error rather than a surprise charge.
  • •Complex multi-file refactors or novel architecture tasks may produce lower quality results.
  • •Best used for: simple edits, explanations, boilerplate generation, code review, test writing.

If you want free-first with paid fallback, use ant:auto instead. It tries free models when appropriate but escalates to paid when the task requires it.

Step 5: Test the Setup

Run a few requests and verify everything works:

bash
# Simple task — should route to a fast/free model
openclaw -m antbase/auto "what does the -p flag do in docker run?"

# Medium task — should route to a mid-tier model
openclaw -m antbase/auto "write a Python function to validate email addresses with regex"

# Complex task — should route to a premium model
openclaw -m antbase/best "refactor this Express.js monolith into a modular service architecture"

What to check:

  • •Responses return successfully with no authentication errors
  • •Simple queries respond faster than complex ones (different models selected)
  • •No persistent provider errors (check the Antbase dashboard logs if you see issues)
  • •The dashboard shows requests in your logs with routing metadata (model used, task type, cost)

How the Routing Pipeline Works

Every request through ANT passes through four stages:

How this request was routed
routing...
1
Your App 
2
Classify LLM 
3
Optimize LLM 
4
Route AI 
5
LLM 
PrimaryGroq / Mixtral 8x7B
Fallback 1DeepSeek V3 via NVIDIA
Fallback 2OpenAI GPT-4o-mini
Groq healthy — no fallback triggered

Stage 1 — Classify: ANT's classification model runs parallel micro-inferences (under 15ms) to produce route tags: task type, complexity, and capabilities needed.

Stage 2 — Optimize: When enabled, compresses your prompt by removing redundant tokens. Saves 20-40% on token cost with no quality loss. Enable this in the dashboard under Settings.

Stage 3 — Route: Scores every available model in real-time using your virtual model's preference weights (speed, quality, cost) combined with the classification tags. The scoring formula accounts for model capability, current latency, cost per token, provider health, and context window fit.

Stage 4 — Execute: Forwards to the winning model. If the provider returns an error or times out, ANT re-scores the remaining healthy models and retries — up to 3 attempts, each targeting a different provider.

Real-World Examples

Example 1: Daily Coding Agent on ant:auto

A developer runs OpenClaw through ANT with ant:auto as their default model. Over a typical day:

  • •"rename userId to accountId across these files" — classified as coding/simple. Routed to Llama 3.3 70B via Groq. Cost: $0.00. Latency: 0.8s.
  • •"write unit tests for this auth middleware" — classified as coding/medium. Routed to DeepSeek V3 via NVIDIA NIM. Cost: $0.00. Latency: 1.4s.
  • •"design a rate limiter with sliding window and Redis" — classified as coding/complex. Routed to Claude Sonnet via Anthropic. Cost: $0.03. Latency: 3.2s.

Result: 75% of requests cost nothing. The 25% that needed a premium model got one. Total daily cost: ~$2.50 instead of ~$8.

Example 2: Budget-Conscious Development on ant:free

A developer working on a side project uses ant:free exclusively. All requests route to free-tier models:

  • •Code explanations and documentation → Llama 3.3 70B via Groq
  • •Function generation and refactoring → DeepSeek V3 via NVIDIA NIM
  • •Quick questions and debugging hints → Gemini 2.5 Flash
  • •If one free provider hits rate limits → circuit breaker shifts to the next healthy free provider

Result: $0/month. Around 5% of complex tasks produce noticeably lower quality, but for side projects and learning, it's an acceptable tradeoff.

Cost and Performance Impact

The cost reduction comes from matching model capability to task complexity. Most coding agent tasks don't require a frontier model:

  • •ant:auto typically reduces costs 60-70% compared to using Claude or GPT-4o for everything. Simple tasks route to free models, medium tasks to mid-tier, complex tasks to premium.
  • •ant:free reduces costs to near-zero. Free-tier models (DeepSeek V3, Llama 3.3, Gemini Flash) handle most coding tasks well.
  • •The routing pipeline adds ~100-200ms overhead. On a 2-3 second model response, this is negligible.
  • •Costs still increase when most of your tasks are genuinely complex — architecture design, multi-file refactors, novel algorithm development. These route to premium models regardless.

From real usage data running OpenClaw through ANT:

  • •Direct Claude Sonnet for everything: ~$240/month
  • •ant:auto (dynamic routing): ~$75/month — 68% reduction
  • •ant:free (free-tier only): ~$9/month — 96% reduction, with ~5% quality tradeoff on complex tasks

Troubleshooting

Invalid API key (401 errors)

Verify your key is set correctly:

bash
echo $ANT_API_KEY
# Should print ant_...

# If empty, check your shell config and reload
source ~/.zshrc

If the key is set but still failing, regenerate it in the dashboard at antbase.ai/app/keys.

Provider errors (5xx responses)

ANT handles provider failures automatically. If you see persistent errors, check the request logs in the Antbase dashboard — they show which provider was selected, what error occurred, and whether fallback was triggered. If all providers for your requested capability are down, ANT returns an ALL_PROVIDERS_DOWN error with the list of attempted providers.

Model not recognized

Make sure the model ID in your config matches a valid virtual model. Valid IDs: auto, fast, best, free, reasoning, coder, creative, vision. The provider prefix (antbase/) is added by OpenClaw automatically — don't include it in the config.

Fallback not working

Fallback is automatic for ant:auto — if a provider fails, ANT retries with the next-best model. For ant:free, fallback stays within the free pool. If the entire free pool is exhausted, ant:free returns an error rather than escalating to paid models. If you want free-first with paid fallback, use ant:auto.

Summary

OpenClaw + ANT gives you dynamic routing for every coding task without changing your workflow. Set up is one config file change. ant:auto handles most use cases — it routes simple tasks to free/fast models and complex tasks to premium ones. ant:free gives you zero-cost inference for side projects and testing.

The core principle: routing is more important than model selection. No single model is the right choice for every request. ANT makes that decision in under 200ms, per request, across 2,500+ models from 30+ providers.

Try ANT routing today

Drop-in OpenAI-compatible API. Change your base URL and every request gets intelligent routing across 30+ providers.