Skip to content
广告 · 本站推荐广告

OpenRouter ​

OpenRouter 是一个统一的 AI 模型路由(Router)平台,通过单一 API Key 可以访问来自 OpenAI、Anthropic、Google、Meta 等多家提供商的模型。支持免费模型,非常适合体验和对比不同模型。

获取 API Key ​

  1. 前往 OpenRouter 注册账号
  2. 在 Keys 页面创建 API Key
  3. 复制 API Key

配置 OpenClaw ​

bash
openclaw models auth login --provider openrouter
# 按提示输入 API Key

或手动编辑配置文件:

jsonc
// ~/.openclaw/config.json
{
  "models": {
    "providers": {
      "openrouter": {
        "apiKey": "sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxx",
        "baseUrl": "https://openrouter.ai/api/v1"
      }
    }
  }
}

免费模型 ​

OpenRouter 提供部分免费模型,无需充值即可使用:

模型 ID说明
meta-llama/llama-3.1-8b-instruct:freeLlama 3.1 8B 免费版
mistralai/mistral-7b-instruct:freeMistral 7B 免费版
google/gemma-2-9b-it:freeGemma 2 9B 免费版
qwen/qwen-2.5-7b-instruct:freeQwen 2.5 7B 免费版

使用示例:

bash
# 使用免费模型
openclaw models default set openrouter/meta-llama/llama-3.1-8b-instruct:free

付费模型 ​

通过 OpenRouter 可以使用各家顶级模型:

模型 ID原始提供商
openai/gpt-4oOpenAI
anthropic/claude-sonnet-4-20250514Anthropic
google/gemini-pro-1.5Google
meta-llama/llama-3.1-405b-instructMeta

模型路由特性 ​

自动路由 ​

OpenRouter 可以根据请求自动选择最佳模型:

bash
openclaw chat --model openrouter/auto "回答这个问题"

回退机制(Fallback) ​

如果首选模型不可用,OpenRouter 会自动切换到备用模型。

价格透明 ​

每次请求的费用可以在 OpenRouter 控制台中查看。

环境变量 ​

bash
export OPENROUTER_API_KEY="sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxx"

故障排查 ​

API Key 无效 ​

  • 确认 API Key 以 sk-or- 开头
  • 检查 Key 是否在控制台被撤销

模型不可用 ​

费用问题 ​

  • 免费模型有速率限制
  • 付费模型从账户余额扣费

🇨🇳 中国用户须知

  • 网络代理:OpenRouter 需要从中国大陆配置代理访问
    bash
    export HTTPS_PROXY="http://127.0.0.1:7890"
  • 免费模型:OpenRouter 的免费模型是零成本体验国际模型的好途径
  • 统一入口:如果你需要使用多家国际提供商的模型,OpenRouter 可以减少管理多个 API Key 的麻烦
  • 付费方式:支持信用卡付费

基于MIT协议开源 | 内容翻译自 官方文档,同步更新