SuperAPI AI Directory

api-provider-setup

Coding & development

View repository

Updated 10-16 06:50

About this skill

API Provider Setup

Add and configure third-party API relay providers for OpenClaw.

Configuration Location

Configuration file:~/.openclaw/openclaw.json

In the models.providers section, add a custom provider.

Configuration Template

Anthropic-compatible API (such as anapi, Zhipu)

{
  "models": {
    "mode": "merge",
    "providers": {
      "供应商名称": {
        "baseUrl": "https://api.example.com",
        "apiKey": "sk-your-api-key",
        "auth": "api-key",
        "api": "anthropic-messages",
        "models": [
          {
            "id": "model-id",
            "name": "显示名称",
            "reasoning": false,
            "input": ["text"],
            "contextWindow": 200000,
            "maxTokens": 8192,
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            }
          }
        ]
      }
    }
  }
}

OpenAI-compatible API (such as OpenRouter)

{
  "models": {
    "mode": "merge",
    "providers": {
      "供应商名称": {
        "baseUrl": "https://api.example.com/v1",
        "apiKey": "sk-your-api-key",
        "auth": "api-key",
        "api": "openai-completions",
        "models": [
          {
            "id": "gpt-4",
            "name": "GPT-4",
            "reasoning": false,
            "input": ["text"],
            "contextWindow": 128000,
            "maxTokens": 4096
          }
        ]
      }
    }
  }
}

Key Field Descriptions

Field Required Description
baseUrl ✅ API endpoint address (excluding paths such as /v1/messages)
apiKey ✅ API key
auth ✅ Authentication method, usually api-key
api ✅ API format:anthropic-messages or openai-completions
models ✅ List of models supported by this provider
models[].id ✅ Model ID (used when calling)
models[].name ❌ Display name
models[].contextWindow ❌ Context window size
models[].maxTokens ❌ Maximum output token count
models[].reasoning ❌ Whether reasoning mode is supported

Add Model Alias

In agents.defaults.models , add an alias:

{
  "agents": {
    "defaults": {
      "models": {
        "供应商/模型id": {
          "alias": "简短别名"
        }
      }
    }
  }
}

Set as Default Model

In agents.defaults.model , set:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "供应商/模型id",
        "fallbacks": [
          "备选供应商1/模型id",
          "备选供应商2/模型id"
        ]
      }
    }
  }
}

Adding Process

  1. Obtain provider information

    • Base URL
    • API Key
    • API format (Anthropic or OpenAI compatible)
    • List of supported models
  2. Add using gateway config.patch

    gateway config.patch 添加供应商配置
    
  3. Restart Gateway for changes to take effect

    gateway restart
    
  4. Test the new model

    session_status(model="新供应商/模型id")
    

Common Relay Configuration Examples

Anapi (Anthropic relay)

"anapi": {
  "baseUrl": "https://anapi.9w7.cn",
  "apiKey": "sk-xxx",
  "auth": "api-key",
  "api": "anthropic-messages",
  "models": [{"id": "opus-4.5", "name": "Opus 4.5", "contextWindow": 200000}]
}

Zhipu ZAI

"zai": {
  "baseUrl": "https://open.bigmodel.cn/api/anthropic",
  "apiKey": "xxx.xxx",
  "auth": "api-key",
  "api": "anthropic-messages",
  "models": [{"id": "glm-4.7", "name": "GLM-4.7", "contextWindow": 200000}]
}

OpenRouter VIP

"openrouter-vip": {
  "baseUrl": "https://openrouter.vip/v1",
  "apiKey": "sk-xxx",
  "auth": "api-key",
  "api": "openai-completions",
  "models": [{"id": "gpt-5.2", "name": "GPT-5.2", "contextWindow": 200000}]
}

Troubleshooting

  1. 401 Unauthorized - API Key error or expired
  2. 404 Not Found - baseUrl path error
  3. Model does not exist - Check whether models[].id is correct
  4. Format error - Check whether the api field matches the provider's API format