🧠

一钥通百模 · 智能路由降本增效

One API key for 70+ AI models. Route to GPT, Claude, Gemini, Grok and more · v1.0.0
可以安装,但有提示 HAS_SCRIPTS
AI 增强 安全 B 级 作者 chaimengphp 公开目录收录
1.3k 下载 2 安装 4.8k 收藏 3 浏览

简介

统一AI网关服务,单一API密钥访问70+大模型(GPT/Claude/Gemini等),支持智能路由与成本优化

原始描述

Unified LLM Gateway - One API for 70+ AI models. Route to GPT, Claude, Gemini, Grok and more with a single API key.

通过你的 Agent 添加

安装目录:llm-router/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/one-api-key-for-70-ai-models-route-to-gpt-claude-gemini-grok-and-more/
Codex CLI~/.codex/skills/one-api-key-for-70-ai-models-route-to-gpt-claude-gemini-grok-and-more/
DeepSeek Harness~/.agents/skills/one-api-key-for-70-ai-models-route-to-gpt-claude-gemini-grok-and-more/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心功能

OpenClaw LLM Router 是一款面向AI智能体的统一大语言模型网关服务,通过单一API密钥即可访问70+主流AI模型,包括OpenAI GPT系列、Anthropic Claude、Google Gemini、xAI Grok、Meta Llama及Mistral等。服务采用OpenAI兼容API格式,开发者无需修改现有代码即可无缝迁移。

显著优点

聚合访问:告别管理十余个不同厂商API密钥的繁琐,统一账单与用量追踪大幅降低运维复杂度。智能路由:内置模型切换与降级机制,支持按任务类型自动选择最优模型(简单查询用轻量模型、复杂推理用旗舰模型),实现成本与性能的平衡。高兼容性:完全兼容OpenAI SDK,仅需修改base_url和api_key即可接入,学习成本极低。丰富功能:支持流式响应、多模态图像分析、函数调用、模型A/B对比测试等企业级特性。

潜在局限

第三方依赖:作为聚合层,服务质量受底层各厂商API稳定性影响,若原厂商故障或限流,可能出现连锁延迟。定价透明度:虽然提供统一计费,但跨厂商的价格对比和成本预估需要用户自行核算,新用户学习曲线存在。合规风险:数据流经第三方网关,对金融、医疗等敏感行业需额外评估数据驻留与隐私合规。厂商绑定:深度使用后可能形成路径依赖,迁移回原生API需一定改造成本。

适合人群

  • 多模型AI应用开发者:需要快速对比不同模型效果,或按场景动态切换的团队
  • AI智能体/Agent构建者:追求统一工具调用接口,简化架构复杂度的工程师
  • 成本敏感型团队:希望通过智能路由策略优化推理开销的中小型企业
  • 原型快速验证:不想逐一申请各厂商账号即可体验多模型能力的个人开发者

常规风险提示

风险类型 说明 缓释建议
数据隐私 请求内容经第三方服务器中转 避免传输PII/商业机密,敏感场景优先原生API
服务连续性 依赖AIsa平台稳定性 生产环境务必实现fallback到原生API的逃生通道
计费管控 统一账单可能掩盖单模型用量异常 设置用量阈值告警,定期审计cost字段
模型可用性 厂商政策变动导致模型下架 避免硬编码模型名,使用/models端点动态获取

技术亮点

  • 零依赖Python客户端,单文件即可运行
  • SSE流式传输支持实时交互体验
  • 原生Gemini格式兼容,灵活适应Google生态
  • 详细用量元数据(token计数+预估费用)助力FinOps

技能正文


name: llm-router description: "Unified LLM Gateway - One API for 70+ AI models. Route to GPT, Claude, Gemini, Grok and more with a single API key." homepage: https://openclaw.ai metadata: {"openclaw":{"emoji":"🧠","requires":{"bins":["curl","python3"],"env":["AISA_API_KEY"]},"primaryEnv":"AISA_API_KEY"}}

OpenClaw LLM Router 🧠

Unified LLM Gateway for autonomous agents. Powered by AIsa.

One API key. 70+ models. OpenAI-compatible.

Replace 100+ API keys with one. Access GPT-4, Claude-3, Gemini, Grok, and more through a unified, OpenAI-compatible API.

🔥 What Can You Do?

Multi-Model Chat

"Chat with GPT-4 for reasoning, switch to Claude for creative writing"

Model Comparison

"Compare responses from GPT-4, Claude, and Gemini for the same question"

Vision Analysis

"Analyze this image with GPT-4o - what objects are in it?"

Cost Optimization

"Route simple queries to fast/cheap models, complex queries to GPT-4"

Fallback Strategy

"If GPT-4 fails, automatically try Claude, then Gemini"

Why LLM Router?

Feature LLM Router Direct APIs
API Keys 1 10+
SDK Compatibility OpenAI SDK Multiple SDKs
Billing Unified Per-provider
Model Switching Change string Code rewrite
Fallback Routing Built-in DIY
Cost Tracking Unified Fragmented

Supported Model Families

Family Developer Example Models
GPT OpenAI gpt-5.2, gpt-5, gpt-5-mini, gpt-4.1, gpt-4.1-mini, gpt-4o, gpt-4o-mini
Claude Anthropic claude-sonnet-4-5, claude-opus-4-1, claude-opus-4, claude-sonnet-4, claude-haiku-4-5
Gemini Google gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-3-pro-preview
Grok xAI grok-4, grok-3
Llama Meta llama-3.1-405b, llama-3.1-70b, llama-3.1-8b
Mistral Mistral AI mistral-large, mistral-medium, mixtral-8x7b

Note: Model availability may vary. Check marketplace.aisa.one/pricing for the full list of currently available models and pricing.

Quick Start

export AISA_API_KEY="your-key"

API Endpoints

OpenAI-Compatible Chat Completions

POST https://api.aisa.one/v1/chat/completions
Request
curl -X POST "https://api.aisa.one/v1/chat/completions" \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain quantum computing in simple terms."}
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'
Parameters
Parameter Type Required Description
model string Yes Model identifier (e.g., gpt-4.1, claude-sonnet-4-5)
messages array Yes Conversation messages
temperature number No Randomness (0-2, default: 1)
max_tokens integer No Maximum response tokens
stream boolean No Enable streaming (default: false)
top_p number No Nucleus sampling (0-1)
frequency_penalty number No Frequency penalty (-2 to 2)
presence_penalty number No Presence penalty (-2 to 2)
stop string/array No Stop sequences
Message Format
{
  "role": "user|assistant|system",
  "content": "message text or array for multimodal"
}
Response
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1234567890,
  "model": "gpt-4.1",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum computing uses..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 50,
    "completion_tokens": 200,
    "total_tokens": 250,
    "cost": 0.0025
  }
}

Streaming Response

curl -X POST "https://api.aisa.one/v1/chat/completions" \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "messages": [{"role": "user", "content": "Write a poem about AI."}],
    "stream": true
  }'

Streaming returns Server-Sent Events (SSE):

data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"In"}}]}
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":" circuits"}}]}
...
data: [DONE]

Vision / Image Analysis

Analyze images by passing image URLs or base64 data:

curl -X POST "https://api.aisa.one/v1/chat/completions" \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "What is in this image?"},
          {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
        ]
      }
    ]
  }'

Function Calling

Enable tools/functions for structured outputs:

curl -X POST "https://api.aisa.one/v1/chat/completions" \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4.1",
    "messages": [{"role": "user", "content": "What is the weather in Tokyo?"}],
    "functions": [
      {
        "name": "get_weather",
        "description": "Get current weather for a location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {"type": "string", "description": "City name"},
            "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
          },
          "required": ["location"]
        }
      }
    ],
    "function_call": "auto"
  }'

Google Gemini Format

For Gemini models, you can also use the native format:

POST https://api.aisa.one/v1/models/gemini-2.5-flash:generateContent
curl -X POST "https://api.aisa.one/v1/models/gemini-2.5-flash:generateContent" \
  -H "Authorization: Bearer $AISA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Explain machine learning."}]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1000
    }
  }'

Python Client

Installation

No installation required - uses standard library only.

CLI Usage

# Basic completion
python3 {baseDir}/scripts/llm_router_client.py chat --model gpt-4.1 --message "Hello, world!"

# With system prompt
python3 {baseDir}/scripts/llm_router_client.py chat --model claude-sonnet-4-5 --system "You are a poet" --message "Write about the moon"

# Streaming
python3 {baseDir}/scripts/llm_router_client.py chat --model gpt-4o --message "Tell me a story" --stream

# Multi-turn conversation
python3 {baseDir}/scripts/llm_router_client.py chat --model gpt-4.1 --messages '[{"role":"user","content":"Hi"},{"role":"assistant","content":"Hello!"},{"role":"user","content":"How are you?"}]'

# Vision analysis
python3 {baseDir}/scripts/llm_router_client.py vision --model gpt-4o --image "https://example.com/image.jpg" --prompt "Describe this image"

# List supported models
python3 {baseDir}/scripts/llm_router_client.py models

# Compare models
python3 {baseDir}/scripts/llm_router_client.py compare --models "gpt-4.1,claude-sonnet-4-5,gemini-2.5-flash" --message "What is 2+2?"

Python SDK Usage

from llm_router_client import LLMRouterClient

client = LLMRouterClient()  # Uses AISA_API_KEY env var

# Simple chat
response = client.chat(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response["choices"][0]["message"]["content"])

# With options
response = client.chat(
    model="claude-3-sonnet",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain relativity."}
    ],
    temperature=0.7,
    max_tokens=500
)

# Streaming
for chunk in client.chat_stream(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a story."}]
):
    print(chunk, end="", flush=True)

# Vision
response = client.vision(
    model="gpt-4o",
    image_url="https://example.com/image.jpg",
    prompt="What's in this image?"
)

# Compare models
results = client.compare_models(
    models=["gpt-4.1", "claude-sonnet-4-5", "gemini-2.5-flash"],
    message="Explain quantum computing"
)
for model, result in results.items():
    print(f"{model}: {result['response'][:100]}...")

Use Cases

1. Cost-Optimized Routing

Use cheaper models for simple tasks:

def smart_route(message: str) -> str:
    # Simple queries -> fast/cheap model
    if len(message) < 50:
        model = "gpt-3.5-turbo"
    # Complex reasoning -> powerful model
    else:
        model = "gpt-4.1"
    
    return client.chat(model=model, messages=[{"role": "user", "content": message}])

2. Fallback Strategy

Automatic fallback on failure:

def chat_with_fallback(message: str) -> str:
    models = ["gpt-4.1", "claude-sonnet-4-5", "gemini-2.5-flash"]
    
    for model in models:
        try:
            return client.chat(model=model, messages=[{"role": "user", "content": message}])
        except Exception:
            continue
    
    raise Exception("All models failed")

3. Model A/B Testing

Compare model outputs:

results = client.compare_models(
    models=["gpt-4.1", "claude-opus-4-1"],
    message="Analyze this quarterly report..."
)

# Log for analysis
for model, result in results.items():
    log_response(model=model, latency=result["latency"], cost=result["cost"])

4. Specialized Model Selection

Choose the best model for each task:

MODEL_MAP = {
    "code": "gpt-4.1",
    "creative": "claude-opus-4-1",
    "fast": "gemini-2.5-flash",
    "vision": "gpt-4o",
    "reasoning": "o1",
    "open_source": "llama-3.1-70b"
}

def route_by_task(task_type: str, message: str) -> str:
    model = MODEL_MAP.get(task_type, "gpt-4.1")
    return client.chat(model=model, messages=[{"role": "user", "content": message}])

Error Handling

Errors return JSON with error field:

{
  "error": {
    "code": "model_not_found",
    "message": "Model 'xyz' is not available"
  }
}

Common error codes:

  • 401 - Invalid or missing API key
  • 402 - Insufficient credits
  • 404 - Model not found
  • 429 - Rate limit exceeded
  • 500 - Server error

Best Practices

  1. Use streaming for long responses to improve UX
  2. Set max_tokens to control costs
  3. Implement fallback for production reliability
  4. Cache responses for repeated queries
  5. Monitor usage via response metadata
  6. Use appropriate models - don't use GPT-4 for simple tasks

OpenAI SDK Compatibility

Just change the base URL and key:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["AISA_API_KEY"],
    base_url="https://api.aisa.one/v1"
)

response = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

Pricing

Token-based pricing varies by model. Check marketplace.aisa.one/pricing for current rates.

Model Family Approximate Cost
GPT-4.1 / GPT-4o ~$0.01 / 1K tokens
Claude-3-Sonnet ~$0.01 / 1K tokens
Gemini-2.5-Flash ~$0.001 / 1K tokens
Grok-2 ~$0.01 / 1K tokens
Llama-3.1-70b ~$0.002 / 1K tokens
Mistral-Large ~$0.008 / 1K tokens

Every response includes usage.cost and usage.credits_remaining.

Get Started

  1. Sign up at aisa.one
  2. Get your API key from the dashboard
  3. Add credits (pay-as-you-go)
  4. Set environment variable: export AISA_API_KEY="your-key"

Full API Reference

See API Reference for complete endpoint documentation.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

llmai-gatewaymulti-modelopenai-compatiblecost-optimizationroutingstreaming-apivisionfunction-calling

同类 Skill