OpenClaw

Last updated:

On this page

Configure OpenClaw with staik to use all models directly via Telegram, Discord, or the terminal.

Configuration

Add the following to your openclaw.json:

json
{
  "models": {
    "providers": {
      "staik": {
        "baseUrl": "https://api.staik.se/v1",
        "apiKey": "sk-st-your-key",
        "api": "openai-completions",
        "models": [
          {
            "id": "gemma4:31b",
            "name": "Gemma 4 31B",
            "contextWindow": 262144,
            "contextTokens": 64000,
            "maxTokens": 8192
          },
          {
            "id": "qwen3.6:35b-a3b",
            "name": "Qwen 3.6 35B A3B",
            "contextWindow": 262144,
            "contextTokens": 64000,
            "maxTokens": 8192
          },
          {
            "id": "qwen3.5:9b",
            "name": "Qwen 3.5 9B",
            "contextWindow": 262144,
            "contextTokens": 28000,
            "maxTokens": 4096
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "staik/gemma4:31b",
        "fallbacks": ["staik/qwen3.6:35b-a3b", "staik/qwen3.5:9b"]
      },
      "compaction": {
        "mode": "safeguard",
        "keepRecentTokens": 20000,
        "reserveTokens": 24000
      }
    }
  }
}

Switch models with /models in OpenClaw. fallbacks gives automatic failover if the primary model is unavailable. Which model fits which role — see Models.

Fine-tune context handling

ParameterWhereDescription
contextTokensper modelMax tokens of conversation history per request. Lower if the model times out.
maxTokensper modelMax tokens in the model response. Lower if responses get cut off.
keepRecentTokenscompactionTokens of recent messages that are never compressed.
reserveTokenscompactionTokens reserved for the response during compaction. Raise if responses get truncated.
contextWindowper modelThe model's total context window (262K for all chat models).

Quick diagnosis

Model stops responding mid-conversation → lower contextTokens. Responses get truncated → raise reserveTokens. Model forgets what you just said → raise keepRecentTokens.

Configuration per plan

Every request counts both prompt tokens (history) and completion tokens (response). The key to staying within budget is contextTokens — it controls how much history is sent per request.

json
{
  "models": {
    "providers": {
      "staik": {
        "baseUrl": "https://api.staik.se/v1",
        "apiKey": "sk-st-your-key",
        "api": "openai-completions",
        "models": [
          {
            "id": "qwen3.5:9b",
            "name": "Qwen 3.5 9B",
            "contextWindow": 262144,
            "contextTokens": 12000,
            "maxTokens": 2048
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": { "primary": "staik/qwen3.5:9b" },
      "compaction": {
        "mode": "safeguard",
        "keepRecentTokens": 6000,
        "reserveTokens": 8000,
        "maxHistoryShare": 0.3
      }
    }
  }
}

Rules of thumb per profile:

ProfilecontextTokensmaxTokensModelCapacity (approx.)
Frugal (PAYG/EA pot)12,0002,048qwen3.5:9b~80 requests per 1M tokens
Hobby (250K/day)24,0004,0969b + 35b~15 rounds/day
Agent (500K/h rolling)48,0008,192gemma4 + 35b + 9b~10 requests/h

The fast 9b model uses the fewest tokens; a low maxHistoryShare compresses early and saves budget. With rolling hourly windows (the Agent plans), tokens from an hour ago no longer count.

Sub-agents (ACP)

For larger projects (e.g. a multi-file site), OpenClaw splits the work into sub-agents via ACP (Agent Coordination Protocol). Each sub-agent gets isolated context — without ACP the main agent must hold the entire project state in every request (5 files × 30K context = 150K+ tokens in a single round); with ACP token usage can drop 70–80%.

json
{
  "agents": {
    "list": [{
      "id": "<your_agent_id>",
      "runtime": {
        "type": "acp",
        "acp": {
          "agent": "codex",
          "backend": "acpx",
          "mode": "persistent"
        }
      }
    }]
  },
  "session": {
    "threadBindings": {
      "enabled": true,
      "spawnSubagentSessions": true
    }
  }
}

Verify in your chat: /acp spawn <agent_id> spawns a sub-agent manually, /verbose shows in real time which sub-agents are spawned and where errors occur.

Gateway connection closed?

The error "Cannot start sub-agent (gateway connection closed)" refers to OpenClaw's internal gateway, not the staik API. Check that the acpx backend is installed, gateway.mode: "local" is set, the gateway runs on the right port, and no stale processes block it. When ACP fails the main agent does everything itself — the entire project context is sent in every request and tokens burn fast.

Troubleshooting

OpenClaw produces no response

Turn off streaming in the provider block — some channels have issues with streaming responses; without streaming a regular request is sent that waits for the full response:

json
{
  "models": {
    "providers": {
      "staik": {
        "baseUrl": "https://api.staik.se/v1",
        "apiKey": "sk-st-your-key",
        "api": "openai-completions",
        "streaming": "off",
        "models": ["..."]
      }
    }
  }
}

Agent asks "Should I run?" between steps

The behavior comes from OpenClaw's own agent prompt, not from staik. Override it with a system prompt — per Telegram group via channels.telegram.groups.<chat_id>.systemPrompt, or globally via the workspace files (~/.openclaw/workspace/IDENTITY.md or SOUL.md):

text
You are an autonomous agent. Execute ALL steps of a task in sequence without
asking between them. Stop only on (1) an explicit error requiring a decision,
or (2) when the entire task is done.

Other causes: the sub-agent could not start (see ACP above), or the task requires more output than maxTokens — raise it to 8192 if budget allows.

429 mid-session

You've hit your token limit. Lower contextTokens (64000 → 16000–32000), switch to qwen3.5:9b as primary, or upgrade your plan — see Error codes and rate limits. Monitor in real time via the X-RateLimit-Used-Tokens header.