Scripts2026年3月29日·1 分钟阅读

OpenRouter — Unified API for 200+ AI Models

Single API to access 200+ AI models from OpenAI, Anthropic, Google, Meta, Mistral, and more. OpenAI-compatible format, automatic fallbacks, and usage-based pricing.

TO
TokRepo精选 · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

export OPENROUTER_API_KEY=sk-or-...
curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -d '{"model": "anthropic/claude-sonnet-4-20250514", "messages": [{"role": "user", "content": "Hello"}]}'

介绍

OpenRouter provides a single API endpoint to access 200+ AI models from every major provider. Use the OpenAI-compatible format you already know — just change the base URL and pick any model.

Best for: Model comparison, fallback routing, accessing multiple providers, cost optimization Works with: Any tool supporting OpenAI API format


Features

  • 200+ models from OpenAI, Anthropic, Google, Meta, Mistral, Cohere, etc.
  • OpenAI-compatible — drop-in replacement, change one line of code
  • Automatic fallbacks — if a model is down, route to alternatives
  • Usage-based pricing — pay per token, no subscriptions
  • Rate limiting — built-in handling across providers

Usage with Python

from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="sk-or-...",
)

response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-20250514",
    messages=[{"role": "user", "content": "Hello"}],
)

🙏

来源与感谢

Created by OpenRouter. openrouter.ai — Unified AI model access

相关资产