Command Palette

Search for a command to run...

Назад к скиллам
скилл № 72327

openrouter

Access 100+ AI models via OpenRouter. Route between providers, manage costs, and use fallbacks. Use for multi-model AI applications, cost optimization, and…

БесплатноБез исполняемых скриптов
majiayu000от majiayu000★ 31 звезда на GitHub

Установить openrouter в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

OpenRouter

Expert guidance for multi-provider AI model access.

Triggers

Use this skill when:

  • Accessing multiple AI model providers through one API
  • Building multi-model AI applications
  • Implementing cost optimization or model fallbacks
  • Working with OpenRouter for LLM provider abstraction
  • Routing requests between different AI providers
  • Keywords: openrouter, multi-model, model routing, fallback, provider abstraction

Installation

pip install openai  # Uses OpenAI-compatible API

Quick Start

from openai import OpenAI

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

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

print(response.choices[0].message.content)

Available Models

# Anthropic
model = "anthropic/claude-3.5-sonnet"
model = "anthropic/claude-3-opus"
model = "anthropic/claude-3-haiku"

# OpenAI
model = "openai/gpt-4o"
model = "openai/gpt-4-turbo"
model = "openai/gpt-3.5-turbo"

# Google
model = "google/gemini-pro-1.5"
model = "google/gemini-flash-1.5"

# Meta
model = "meta-llama/llama-3.1-405b-instruct"
model = "meta-llama/llama-3.1-70b-instruct"

# Mistral
model = "mistralai/mistral-large"
model = "mistralai/mixtral-8x7b-instruct"

# Free models (rate limited)
model = "meta-llama/llama-3.1-8b-instruct:free"

Request Headers

response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Hello!"}],
    extra_headers={
        "HTTP-Referer": "https://your-app.com",  # For rankings
        "X-Title": "Your App Name"  # For identification
    }
)

Streaming

stream = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Function Calling

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get weather for a city",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Weather in Paris?"}],
    tools=tools,
    tool_choice="auto"
)

if response.choices[0].message.tool_calls:
    for call in response.choices[0].message.tool_calls:
        print(f"Function: {call.function.name}")
        print(f"Args: {call.function.arguments}")

Provider Routing

# Route to specific provider
response = client.chat.completions.create(
    model="openai/gpt-4o",  # Explicit provider
    messages=[{"role": "user", "content": "Hello"}]
)

# Let OpenRouter choose best provider
response = client.chat.completions.create(
    model="gpt-4o",  # OpenRouter routes automatically
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={
        "provider": {
            "order": ["Azure", "OpenAI"],  # Preferred order
            "allow_fallbacks": True
        }
    }
)

Cost Control

# Set spending limit per request
response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={
        "max_price": {
            "prompt": 0.01,      # Max $/1K prompt tokens
            "completion": 0.03   # Max $/1K completion tokens
        }
    }
)

# Check usage
print(f"Prompt tokens: {response.usage.prompt_tokens}")
print(f"Completion tokens: {response.usage.completion_tokens}")

Fallbacks

# Define fallback models
response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={
        "route": "fallback",
        "models": [
            "anthropic/claude-3.5-sonnet",
            "openai/gpt-4o",
            "google/gemini-pro-1.5"
        ]
    }
)

Transforms

# Enable prompt transforms for better compatibility
response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={
        "transforms": ["middle-out"]  # Compress long prompts
    }
)

Get Model Info

import requests

# List all models
response = requests.get(
    "https://openrouter.ai/api/v1/models",
    headers={"Authorization": f"Bearer {api_key}"}
)

models = response.json()["data"]
for model in models[:5]:
    print(f"{model['id']}: ${model['pricing']['prompt']}/1K tokens")

Check Credits

import requests

response = requests.get(
    "https://openrouter.ai/api/v1/auth/key",
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • metadata.json

FAQ

Что делает скилл openrouter?

Access 100+ AI models via OpenRouter. Route between providers, manage costs, and use fallbacks. Use for multi-model AI applications, cost optimization, and LLM provider abstraction.

Как установить скилл openrouter?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл openrouter запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить openrouter с