
Api Provider Setup
- 30 installs
- 82 repo stars
- Updated August 2, 2026
- aaaaqwq/claude-code-skills
api-provider-setup is a Claude Code skill that adds and configures third-party API relay providers and custom model endpoints in OpenClaw, supporting Anthropic-compatible and OpenAI-compatible formats.
About
api-provider-setup is a Claude Code skill (documented in Chinese) for adding and configuring third-party API relay providers into OpenClaw. A developer uses it to register custom model endpoints in openclaw.json, set aliases and default/fallback models, and sync cached auth profiles after changing keys. It supports Anthropic-compatible and OpenAI-compatible provider formats.
- Adds and configures third-party API relay providers (custom model endpoints) in OpenClaw
- Supports both Anthropic-compatible (anthropic-messages) and OpenAI-compatible (openai-completions) API formats
- Documents editing ~/.openclaw/openclaw.json, model aliases, defaults/fallbacks, and an auth-profile sync step after key
Api Provider Setup by the numbers
- 30 all-time installs (skills.sh)
- Ranked #9,223 of 16,556 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 3, 2026 (Skillselion catalog sync)
api-provider-setup capabilities & compatibility
free skill; requires an API key for whichever provider is configured
- Capabilities
- llm provider config · model endpoint setup · api relay config · auth profile sync
- Pricing
- Bring your own API key
What api-provider-setup says it does
为 OpenClaw 添加和配置第三方 API 中转站供应商。
OpenClaw 运行时优先读 `~/.openclaw/agents/<agent>/agent/auth-profiles.json` 中缓存的 key,而非 `openclaw.json`。改了 `openclaw.json` 的 apiKey 后必须同步。
npx skills add https://github.com/aaaaqwq/claude-code-skills --skill api-provider-setupAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 30 |
|---|---|
| repo stars | ★ 82 |
| Last updated | August 2, 2026 |
| Repository | aaaaqwq/claude-code-skills ↗ |
What it does
A developer uses it to register and configure custom LLM API relay providers and models in OpenClaw.
Who is it for?
Registering custom LLM providers and model endpoints in OpenClaw
Skip if: Non-OpenClaw agents or tasks that do not add model providers
When should I use this skill?
A user needs to add a new API provider, configure a relay endpoint, or set a custom model endpoint
What you get
- configured provider entries in openclaw.json
- model aliases and default/fallback model config
By the numbers
- Config priority chain of 3 layers: auth-profiles.json > models.json > openclaw.json
Files
API Provider Setup
为 OpenClaw 添加和配置第三方 API 中转站供应商。
配置位置
配置文件:~/.openclaw/openclaw.json
在 models.providers 部分添加自定义供应商。
配置模板
Anthropic 兼容 API(如 anapi、智谱)
{
"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 兼容 API(如 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
}
]
}
}
}
}关键字段说明
| 字段 | 必填 | 说明 |
|---|---|---|
baseUrl | ✅ | API 端点地址(不含 /v1/messages 等路径) |
apiKey | ✅ | API 密钥 |
auth | ✅ | 认证方式,通常为 api-key |
api | ✅ | API 格式:anthropic-messages 或 openai-completions |
models | ✅ | 该供应商支持的模型列表 |
models[].id | ✅ | 模型 ID(调用时使用) |
models[].name | ❌ | 显示名称 |
models[].contextWindow | ❌ | 上下文窗口大小 |
models[].maxTokens | ❌ | 最大输出 token 数 |
models[].reasoning | ❌ | 是否支持推理模式 |
添加模型别名
在 agents.defaults.models 中添加别名:
{
"agents": {
"defaults": {
"models": {
"供应商/模型id": {
"alias": "简短别名"
}
}
}
}
}⚠️ 重要约束:alias 字段必须是字符串,不能是数组!>
```json
// ✅ 正确
"alias": "opus46"
>
// ❌ 错误 - 会导致 Config validation failed
"alias": ["opus46", "aixn/opus46"]
```
>
如果需要多个别名指向同一模型,需要在 models 中添加多条记录:```json
"供应商/模型id": { "alias": "别名1" }
```
设置为默认模型
在 agents.defaults.model 中设置:
{
"agents": {
"defaults": {
"model": {
"primary": "供应商/模型id",
"fallbacks": [
"备选供应商1/模型id",
"备选供应商2/模型id"
]
}
}
}
}添加流程
1. 获取供应商信息
- Base URL
- API Key
- API 格式(Anthropic 或 OpenAI 兼容)
- 支持的模型列表
2. 使用 gateway config.patch 添加
gateway config.patch 添加供应商配置3. 重启 Gateway 生效
gateway restart4. 测试新模型
session_status(model="新供应商/模型id")常见中转站配置示例
Anapi (Anthropic 中转)
"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}]
}智谱 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}]
}WOW (LinuxDo API 中转 - OpenAI 兼容)
"wow": {
"baseUrl": "https://linuxdoapi-api-wow.223387.xyz/v1",
"apiKey": "pass show api/wow",
"auth": "api-key",
"api": "openai-completions",
"models": [
{"id": "grok-4.1-thinking", "name": "grok-4.1-thinking", "reasoning": true, "contextWindow": 128000},
{"id": "grok-imagine-1.0", "name": "grok-imagine-1.0", "input": ["text","image"], "contextWindow": 128000},
{"id": "kimi-k2.5", "name": "kimi-k2.5", "contextWindow": 128000}
]
}别名配置(agents.defaults.models):
"wow/kimi-k2.5": { "alias": "wow-k2.5" },
"wow/grok-4.1-thinking": { "alias": "wow-grok-4.1-thinking" },
"wow/grok-imagine-1.0": { "alias": "wow-grok-imagine-1.0" }⚡ 同步 Auth Profiles(改 Key 后必做)
背景:OpenClaw 运行时优先读 ~/.openclaw/agents/<agent>/agent/auth-profiles.json 中缓存的 key,而非 openclaw.json。改了 openclaw.json 的 apiKey 后必须同步。
脚本:~/clawd/skills/api-provider-setup/scripts/sync-agent-auth.sh
# 改了 openclaw.json 的 key 后,一键同步所有 agent
~/clawd/skills/api-provider-setup/scripts/sync-agent-auth.sh
# 只同步指定 provider(如改了 zai 的 key)
~/clawd/skills/api-provider-setup/scripts/sync-agent-auth.sh --provider zai
# 只同步指定 agent
~/clawd/skills/api-provider-setup/scripts/sync-agent-auth.sh --agent quant
# 预览(不实际修改)
~/clawd/skills/api-provider-setup/scripts/sync-agent-auth.sh --dry-run
# 同步后重启
openclaw gateway restart配置优先级链:
auth-profiles.json (缓存key) > models.json (provider定义) > openclaw.json (全局配置)完整改 Key 流程: 1. 改 openclaw.json → models.providers.<provider>.apiKey 2. 运行 sync-agent-auth.sh [--provider <name>] 3. openclaw gateway restart
完整改模型流程: 1. 改 openclaw.json → agents.list[] 或 agents.defaults.model 2. 运行 sync-agent-auth.sh(清除旧 auth 缓存+错误计数) 3. openclaw gateway restart
故障排查
1. 401 Unauthorized - API Key 错误或过期 2. 404 Not Found - baseUrl 路径错误或 API 格式不匹配 3. 模型不存在 - 检查 models[].id 是否正确 4. 格式错误 - 检查 api 字段是否匹配供应商的 API 格式
常见问题与解决方案
API 格式不匹配导致 404
症状:消息发送成功,但 AI 返回 404 status code (no body)
原因:供应商的 API 格式配置错误。
诊断:
# 测试 Anthropic Messages API 格式
curl -X POST "https://your-api-endpoint/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{"model":"model-id","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'
# 测试 OpenAI Completions API 格式
curl -X POST "https://your-api-endpoint/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model":"model-id","messages":[{"role":"user","content":"hi"}],"max_tokens":10}'解决:
1. 确认供应商使用的 API 格式:
- Anthropic 格式:使用
/v1/messages,请求体包含messages数组 - OpenAI 格式:使用
/v1/chat/completions,请求体包含messages数组
2. 修改 models.json 中的 api 字段:
{
"providers": {
"your-provider": {
"api": "anthropic-messages" // 或 "openai-completions"
}
}
}3. 重启 Gateway:
openclaw gateway restart案例:
- Anapi 使用 Anthropic Messages API,必须设置
"api": "anthropic-messages" - OpenRouter VIP 使用 OpenAI Completions API,必须设置
"api": "openai-completions" - 智谱 ZAI 使用 Anthropic Messages API,必须设置
"api": "anthropic-messages"
#!/bin/bash
# sync-agent-auth.sh — 同步 openclaw.json 的 provider keys 到所有 agent 的 auth-profiles.json
# 用法: ./sync-agent-auth.sh [--dry-run] [--agent <id>] [--provider <name>]
#
# 场景:改了 openclaw.json 的 apiKey 后,一键同步到所有 agent
# 原理:删除 auth-profiles.json(或更新其中的 key),重启后 OpenClaw 自动从 openclaw.json 重建
set -euo pipefail
AGENTS_DIR="${HOME}/.openclaw/agents"
CONFIG="${HOME}/.openclaw/openclaw.json"
DRY_RUN=false
TARGET_AGENT=""
TARGET_PROVIDER=""
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run) DRY_RUN=true; shift ;;
--agent) TARGET_AGENT="$2"; shift 2 ;;
--provider) TARGET_PROVIDER="$2"; shift 2 ;;
-h|--help)
echo "用法: $0 [--dry-run] [--agent <id>] [--provider <name>]"
echo ""
echo "选项:"
echo " --dry-run 只显示会做什么,不实际修改"
echo " --agent <id> 只同步指定 agent(如 quant, code)"
echo " --provider <name> 只同步指定 provider 的 key(如 zai, moonshot)"
echo ""
echo "示例:"
echo " $0 # 清除所有 agent 的 auth-profiles,让 OpenClaw 重建"
echo " $0 --agent quant # 只清除 quant 的"
echo " $0 --provider zai # 只更新所有 agent 里 zai 相关的 key"
echo " $0 --dry-run # 预览操作"
exit 0
;;
*) echo "未知参数: $1"; exit 1 ;;
esac
done
if [ ! -f "$CONFIG" ]; then
echo "❌ 找不到 $CONFIG"
exit 1
fi
# 获取 openclaw.json 中所有 provider 的 apiKey
get_provider_key() {
local provider="$1"
python3 -c "
import json
with open('$CONFIG') as f:
d = json.load(f)
key = d.get('models',{}).get('providers',{}).get('$provider',{}).get('apiKey','')
print(key)
" 2>/dev/null
}
updated=0
skipped=0
errors=0
for agent_dir in "$AGENTS_DIR"/*/; do
agent=$(basename "$agent_dir")
auth_file="${agent_dir}agent/auth-profiles.json"
# 过滤指定 agent
[ -n "$TARGET_AGENT" ] && [ "$agent" != "$TARGET_AGENT" ] && continue
if [ ! -f "$auth_file" ]; then
echo "⏭️ $agent: 无 auth-profiles.json,跳过"
((skipped++)) || true
continue
fi
if [ -n "$TARGET_PROVIDER" ]; then
# 精确更新指定 provider 的 key
new_key=$(get_provider_key "$TARGET_PROVIDER")
if [ -z "$new_key" ]; then
echo "❌ openclaw.json 中找不到 provider: $TARGET_PROVIDER"
exit 1
fi
result=$(python3 -c "
import json
with open('$auth_file') as f:
d = json.load(f)
profiles = d.get('profiles', {})
changed = False
for pname, p in profiles.items():
if p.get('provider') == '$TARGET_PROVIDER' or pname.startswith('${TARGET_PROVIDER}:'):
old_key = p.get('key', p.get('apiKey', ''))
if old_key != '$new_key':
p['key'] = '$new_key'
p.pop('apiKey', None)
changed = True
# Clear error stats for this provider
stats = d.get('usageStats', {})
for k in list(stats.keys()):
if '$TARGET_PROVIDER' in k:
stats[k].pop('errorCount', None)
stats[k].pop('failureCounts', None)
stats[k].pop('cooldownUntil', None)
stats[k].pop('lastFailureAt', None)
if changed:
with open('$auth_file', 'w') as f:
json.dump(d, f, indent=2, ensure_ascii=False)
print('updated')
else:
print('same')
" 2>/dev/null)
if [ "$DRY_RUN" = true ]; then
echo "🔍 $agent: 会更新 $TARGET_PROVIDER key ($result)"
elif [ "$result" = "updated" ]; then
echo "✅ $agent: $TARGET_PROVIDER key 已更新"
((updated++)) || true
else
echo "⏭️ $agent: $TARGET_PROVIDER key 已是最新"
((skipped++)) || true
fi
else
# 删除整个 auth-profiles.json,让 OpenClaw 从 openclaw.json 重建
if [ "$DRY_RUN" = true ]; then
echo "🔍 $agent: 会删除 auth-profiles.json"
else
rm -f "$auth_file"
echo "✅ $agent: auth-profiles.json 已删除(重启后自动重建)"
((updated++)) || true
fi
fi
done
echo ""
echo "📊 结果: ${updated} 更新, ${skipped} 跳过, ${errors} 错误"
if [ "$DRY_RUN" = false ] && [ "$updated" -gt 0 ]; then
echo ""
echo "⚡ 请重启 Gateway 生效: openclaw gateway restart"
fi
Related skills
FAQ
Which API formats are supported?
Anthropic-compatible (api: anthropic-messages) and OpenAI-compatible (api: openai-completions) providers.
What must you do after changing a provider key?
Run the sync-agent-auth.sh script to sync cached auth profiles, then restart the gateway, because OpenClaw reads cached keys from auth-profiles.json before openclaw.json.