Skip to content

Coding agents

Any tool that speaks the OpenAI API works here: paste the base URL, an API key and a model ID and you are running. What most tools cannot discover on their own is each model’s real limits — this page gives you a config that fills them in, plus the three settings that prevent the most confusing failures we see in real logs.

The two-minute setup

Every tool asks for the same three things: base URL https://api.clfaigateway.dev/v1, an API key from your dashboard (starts with sk-gw-, sent as a standard Authorization: Bearer header), and a model ID from the table below. Every model in the catalog supports tool calling and reasoning.

Model IDContext windowReads images
glm-5.31,048,576No
glm-4.7-flash131,072No
deepseek-v4.1-flash1,048,576Yes
qwen3.8-27b262,144Yes

Valid reasoning_effort values differ per model — send one the model does not accept and the error message lists the right set; what each level really does is in the reasoning_effort table. Live pricing for every model is on the models page.

opencode: fill in what the form cannot

The Custom provider form in opencode only stores model IDs and display names, so every model shows Context limit 0 and no reasoning support — which breaks auto-compaction and hides thinking. Paste this into ~/.config/opencode/opencode.jsonc instead (or merge the provider block into your existing file), then restart opencode:

~/.config/opencode/opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "clf-gateway": {
      "name": "CLF AI Gateway",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://api.clfaigateway.dev/v1"
      },
      "models": {
        "glm-5.3": {
          "name": "GLM 5.3",
          "attachment": false,
          "modalities": { "input": ["text"], "output": ["text"] },
          "reasoning": true,
          "tool_call": true,
          "temperature": true,
          "limit": { "context": 1048576, "output": 32768 }
        },
        "glm-4.7-flash": {
          "name": "GLM 4.7 Flash",
          "attachment": false,
          "modalities": { "input": ["text"], "output": ["text"] },
          "reasoning": true,
          "tool_call": true,
          "temperature": true,
          "limit": { "context": 131072, "output": 32768 }
        },
        "deepseek-v4.1-flash": {
          "name": "DeepSeek V4.1 Flash",
          "attachment": true,
          "modalities": { "input": ["text", "image"], "output": ["text"] },
          "reasoning": true,
          "tool_call": true,
          "temperature": true,
          "limit": { "context": 1048576, "output": 32768 }
        },
        "qwen3.8-27b": {
          "name": "Qwen 3.8 27B",
          "attachment": true,
          "modalities": { "input": ["text", "image"], "output": ["text"] },
          "reasoning": true,
          "tool_call": true,
          "temperature": true,
          "limit": { "context": 262144, "output": 32768 }
        }
      }
    }
  }
}

Add your key through the API-key field of the provider form or opencode auth — it lives in opencode’s own auth store, not in this file. Hover a model in the picker to confirm: it should now show the real context limit and reasoning support.

Z Code: custom provider in six steps

Z Code (the desktop coding app from Z.ai) has no documented config file, so the safe route is Settings → Model settings. Each model needs its ID, context window, output budget and reasoning levels — all listed after the steps. To set up every model at once by editing Z Code’s own file, see the faster way below.

  • 1. Add the provider. Click Add provider → Create custom provider, then rename it from the three-dot menu → Rename (for example "CLF AI Gateway").
  • 2. Connect it. Base URL https://api.clfaigateway.dev/v1 — without /chat/completions at the end, or requests hit a doubled path and fail with 404. Set API format to Chat completions (/chat/completions) — new custom providers default to Anthropic messages, which the gateway does not speak. Paste your sk-gw- key into API key.
  • 3. Add each model. Under Model list click Add model and type the model ID exactly as in the table. Smart configuration recognises these names and fills in its own presets, several of which do not match the gateway — for example 200,000 context for glm-4.7-flash (really 131,072) and up to 384,000 output tokens for DeepSeek. Overwrite both fields with the values below. Z Code compacts the conversation based on the context window, so a wrong number there means compaction too early or too late.
  • 4. Set Max output tokens to 32,768. Z Code sends this number as max_completion_tokens on every request, and anything above your organization’s output cap returns 400 max_tokens_exceeds_cap. 32,768 matches the gateway’s own default and leaves room to answer after long thinking.
  • 5. Match the reasoning levels. Open the model’s Edit model settings (pencil icon) → Advanced settings → Reasoning levels. Delete every level that is not in the table’s last column — including disabled and enabled, which Z Code sends as none and high — then use Add reasoning level for any listed level that is missing. Z Code sends the chosen level as reasoning_effort, and a level the model does not accept returns 400 reasoning_effort_not_supported. The one that always needs fixing is qwen3.8-27b: Z Code gives it disabled/enabled, and Qwen accepts neither none nor high.
  • 6. Test, then pick it. Click the plug icon (Test model); the provider dot turns green. Then choose the model from the switcher in the chat composer. The test sends no reasoning level, so a pass there does not prove step 5 — if a chat fails while the test passed, the reasoning level is the first thing to check.
Model IDContext windowReasoning levels the model accepts
glm-5.31,048,576low, medium, high, max
glm-4.7-flash131,072low, medium, high
deepseek-v4.1-flash1,048,576none, low, medium, high, xhigh, max
qwen3.8-27b262,144low, medium, xhigh

Z Code also sends thinking and enable_thinking alongside the level; the gateway accepts and ignores them, so how much the model thinks is decided by reasoning_effort alone. Only attach images on the models marked Yes in the first table on this page.

Z Code, the faster way: edit its config file

Advanced — Z Code does not document this file

This was tested on Z Code 3.17.2; a later version may change the format, and then the six steps above are the safe route. Quit Z Code completely first (including from the system tray) or it will overwrite your edit, and keep a backup copy of the file. The file also stores your API key in plain text — never paste or screenshot it anywhere.

  • 1. Quit Z Code and back up the file. It is ~/.zcode/v2/provider_config.json (on Windows %USERPROFILE%\.zcode\v2\provider_config.json). Copy it next to itself before changing anything. If it does not exist yet, create it.
  • 2. Paste the config. If the file is new, or its providerRules holds nothing you want to keep, replace its whole content with the block below. Otherwise merge three pieces into what is there: add "clf-ai-gateway" to providerOrder, add the CLF AI Gateway object to providerRules, and add the model lines to providerModelRules — separated from existing entries by commas.
  • 3. Put in your key. Replace sk-gw-YOUR-KEY with your sk-gw- key, keeping the quotes.
~/.zcode/v2/provider_config.json
{
  "schemaVersion": 1,
  "config": {
    "providerOrder": ["clf-ai-gateway"],
    "providerConfigRules": {
      "providerRules": [
        {
          "providerId": "clf-ai-gateway",
          "providerName": "CLF AI Gateway",
          "config": {
            "group": "standard-personal",
            "access": {
              "type": "api-key",
              "apiKey": "sk-gw-YOUR-KEY"
            },
            "api": {
              "type": "openai-chat-completions",
              "baseUrl": "https://api.clfaigateway.dev/v1"
            },
            "personalModelIds": [
              "glm-5.3",
              "glm-4.7-flash",
              "deepseek-v4.1-flash",
              "qwen3.8-27b"
            ],
            "modelOrder": [
              "glm-5.3",
              "glm-4.7-flash",
              "deepseek-v4.1-flash",
              "qwen3.8-27b"
            ]
          }
        }
      ]
    },
    "modelConfigRules": {
      "providerModelRules": [
        {"providerId":"clf-ai-gateway","modelId":"glm-5.3","config":{"enabled":true,"properties":{"contextWindow":1048576,"inputFormat":{"supportsImage":false,"supportsVideo":false,"supportsPdf":false}},"optionSpecs":{"reasoningLevel":{"values":["low","medium","high","max"]},"maxOutputTokens":{"max":32768}}}},
        {"providerId":"clf-ai-gateway","modelId":"glm-4.7-flash","config":{"enabled":true,"properties":{"contextWindow":131072,"inputFormat":{"supportsImage":false,"supportsVideo":false,"supportsPdf":false}},"optionSpecs":{"reasoningLevel":{"values":["low","medium","high"]},"maxOutputTokens":{"max":32768}}}},
        {"providerId":"clf-ai-gateway","modelId":"deepseek-v4.1-flash","config":{"enabled":true,"properties":{"contextWindow":1048576,"inputFormat":{"supportsImage":true,"supportsVideo":false,"supportsPdf":false}},"optionSpecs":{"reasoningLevel":{"values":["none","low","medium","high","xhigh","max"]},"maxOutputTokens":{"max":32768}}}},
        {"providerId":"clf-ai-gateway","modelId":"qwen3.8-27b","config":{"enabled":true,"properties":{"contextWindow":262144,"inputFormat":{"supportsImage":true,"supportsVideo":false,"supportsPdf":false}},"optionSpecs":{"reasoningLevel":{"values":["low","medium","xhigh"]},"maxOutputTokens":{"max":32768}}}}
      ],
      "manualProviderModelRules": []
    }
  }
}

Reopen Z Code: a provider named CLF AI Gateway appears with every model, the right context windows, a 32,768 output budget, matching reasoning levels and image input only where the model reads images. If Z Code reports a configuration error or the provider does not appear, quit it, restore your backup and use the six steps above.

Cline, Cursor, aider and friends

The same three values work everywhere; the only extra step worth taking is telling the tool the model’s context size and output budget wherever it lets you:

  • Cline / Roo Code: choose the "OpenAI Compatible" provider, paste base URL + key + model ID, and fill the context-window and max-output fields from the table above.
  • Cursor: Settings → Models → override the OpenAI base URL with the gateway’s, paste your key, and add the model IDs as custom models.
  • aider: pass the base URL and key on the command line:
aider
aider --openai-api-base https://api.clfaigateway.dev/v1 \
      --openai-api-key sk-gw-... \
      --model openai/glm-5.3

Three settings that prevent confusing failures

  • Give the model room to answer after it thinks. Reasoning is spent from the same max_tokens budget as the answer, and on 100K+ prompts these models can think for thousands of tokens first. If your tool sets max_tokens itself, make it 8,000 or more for agentic work; if it sends nothing, the gateway defaults to 32,768 and you are fine. Details on the streaming page.
  • A long first-token wait is not a hang. A 250K-token prompt spends ~20 seconds in prefill before anything streams, then the model may think for minutes before visible text. Keep client read timeouts at 60 s or more and turn on reasoning display if your tool has it — in our logs the most common "hang" is a client giving up mid-think.
  • Only five models read images. Attach images only on the models marked Yes above — the others return a named 400 vision_not_available before you are charged anything. The full comparison is on the vision page.
  • One image can break the rest of a session. Agents resend the whole history every turn, so an image pasted earlier rides along after you switch to a model that cannot read images — and every later message fails with 400 vision_not_available. In opencode, the modalities line in the config above prevents this: opencode replaces old images with a short note for text-only models. attachment: false alone does not. Without it, switch back to a model marked Yes or start a new session.

Cost shown inside your tool is an estimate

Coding agents compute cost from whatever price table they were given, which drifts when promos change. The billed number for every request — down to the token — is in your dashboard under Logs, and live per-model pricing is on the models page.