Communitygithub.com

ASoudy/AGS

OpenRouter API - 1つのAPIで400以上のAIモデルに統合アクセス

AGS とは?

このスキルは、OpenRouter APIを介した400以上のAIモデルへの統合アクセスを提供します。開発者は、OpenAI互換のSDKを使用して、単一のエンドポイントから複数のプロバイダーにリクエストを送信でき、自動ルーティングとフォールバックにより信頼性と柔軟性が向上します。主な機能には、モデルフォールバック構成、自動ルーター(openrouter/auto)、ストリーミングレスポンス、JSONモードでの構造化出力、および温度やtop_pなどの高度なサンプリングパラメータが含まれます。OpenRouterは全プロバイダー間でAPIスキーマを正規化するため、OpenAI SDKからの移行が容易で、LangChainやVercel AI SDKなどのフレームワークと互換性があります。ベストプラクティスとしては、本番環境では常にフォールバックを実装し、タスクタイプに応じて適切な温度を設定し、コスト制御のためにmax_tokensを設定し、チャットアプリケーションではストリーミングを有効にし、構造化出力が必要な場合はJSONモードを使用することを推奨します。

対応✓Claude Code✓Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/ASoudy/AGS/tree/HEAD/claude_skills_libraries/landing-page-mastery/skills/openrouter

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

OpenRouter スキル

OpenRouter API 開発に関する包括的な支援を提供します。単一のエンドポイントを通じて数百もの AI モデルに統合アクセスでき、インテリジェントルーティング、自動フォールバック、標準化されたインターフェースを備えています。

このスキルを使用するタイミング

このスキルは以下の場合にトリガーされるべきです:

  • 統合インターフェースを通じて複数の AI モデルプロバイダーに API 呼び出しを行う場合
  • モデルフォールバック戦略や自動ルーティングを実装する場合
  • OpenAI 互換の SDK を使用しているが、複数のプロバイダーをターゲットとする場合
  • 高度なサンプリングパラメータ(temperature、top_p、ペナルティ)を設定する場合
  • ストリーミングレスポンスや構造化 JSON 出力を設定する場合
  • 異なる AI モデル間でのコスト比較を行う場合
  • 自動プロバイダーフェイルオーバーが必要なアプリケーションを構築する場合
  • 異なるモデル間で関数/ツール呼び出しを実装する場合
  • OpenRouter 固有の機能(ルーティング、フォールバック、ゼロ補完保険)に関する質問がある場合

クイックリファレンス

基本的なチャット補完 (Python)

from openai import OpenAI

client = OpenAI(
  base_url="https://openrouter.ai/api/v1",
  api_key="<OPENROUTER_API_KEY>",
)

completion = client.chat.completions.create(
  model="openai/gpt-4o",
  messages=[{"role": "user", "content": "What is the meaning of life?"}]
)
print(completion.choices[0].message.content)

基本的なチャット補完 (JavaScript/TypeScript)

import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: 'https://openrouter.ai/api/v1',
  apiKey: '<OPENROUTER_API_KEY>',
});

const completion = await openai.chat.completions.create({
  model: 'openai/gpt-4o',
  messages: [{"role": 'user', "content": 'What is the meaning of life?'}],
});
console.log(completion.choices[0].message);

cURL リクエスト

curl https://openrouter.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -d '{
    "model": "openai/gpt-4o",
    "messages": [{"role": "user", "content": "What is the meaning of life?"}]
  }'

モデルフォールバック設定 (Python)

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    extra_body={
        "models": ["anthropic/claude-3.5-sonnet", "gryphe/mythomax-l2-13b"],
    },
    messages=[{"role": "user", "content": "Your prompt here"}]
)

モデルフォールバック設定 (TypeScript)

const completion = await client.chat.completions.create({
    model: 'openai/gpt-4o',
    models: ['anthropic/claude-3.5-sonnet', 'gryphe/mythomax-l2-13b'],
    messages: [{ role: 'user', content: 'Your prompt here' }],
});

自動ルーター (動的モデル選択)

completion = client.chat.completions.create(
    model="openrouter/auto",  # プロンプトに最適なモデルを自動選択
    messages=[{"role": "user", "content": "Your prompt here"}]
)

高度なパラメータの例

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Write a creative story"}],
    temperature=0.8,           # 創造性を高めるために高く (0.0-2.0)
    max_tokens=500,            # レスポンス長を制限
    top_p=0.9,                 # 核サンプリング (0.0-1.0)
    frequency_penalty=0.5,     # 繰り返しを減らす (-2.0-2.0)
    presence_penalty=0.3       # トピックの多様性を促進 (-2.0-2.0)
)

ストリーミングレスポンス

stream = client.chat.completions.create(
    model="openai/gpt-4o",
    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='')

JSON モード (構造化出力)

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{
        "role": "user",
        "content": "Extract person's name, age, and city from: John is 30 and lives in NYC"
    }],
    response_format={"type": "json_object"}
)

シードを使用した決定論的な出力

completion = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Generate a random number"}],
    seed=42,            # 同じシード = 同じ出力 (サポートされている場合)
    temperature=0.0     # 決定論的サンプリング
)

主要な概念

モデルルーティング

OpenRouter はインテリジェントなルーティング機能を提供します:

  • 自動ルーター (openrouter/auto): NotDiamond を使用して、プロンプトに基づいて最適なモデルを自動選択
  • フォールバックモデル: プライマリが失敗した場合に自動的に再試行する複数のモデルを指定
  • プロバイダールーティング: 信頼性を高めるためにプロバイダー間で自動ルーティング

認証

  • API キーを使用した Bearer トークン認証を使用
  • API キーはプログラムで管理可能
  • OpenAI SDK の認証パターンと互換性あり

モデル命名規則

モデルは provider/model-name の形式を使用:

  • openai/gpt-4o - OpenAI の GPT-4 Optimized
  • anthropic/claude-3.5-sonnet - Anthropic の Claude 3.5 Sonnet
  • google/gemini-2.0-flash-exp:free - Google の無料 Gemini モデル
  • openrouter/auto - 自動ルーティングシステム

サンプリングパラメータ

Temperature (0.0-2.0、デフォルト: 1.0)

  • 低いほど、予測可能で焦点が絞られた応答
  • 高いほど、創造的で多様な応答
  • 事実に基づくタスクには低め (0.0-0.3)、クリエイティブな作業には高め (0.8-1.5) を使用

Top P (0.0-1.0、デフォルト: 1.0)

  • 可能性の高いトークンの割合に選択肢を制限
  • 可能性の低いオプションを動的にフィルタリング
  • 一貫性と多様性のバランス

Frequency/Presence Penalties (-2.0-2.0、デフォルト: 0.0)

  • Frequency: 使用頻度に比例してトークンの繰り返しを抑制
  • Presence: 回数でスケーリングされない単純なペナルティ
  • 正の値は繰り返しを減らし、負の値は再利用を促進

Max Tokens (整数)

  • 最大応答長を設定
  • コンテキスト長からプロンプト長を引いた値を超えることはできない
  • コストの制御と簡潔な応答の強制に使用

レスポンス形式

  • 標準 JSON: デフォルトのチャット補完形式
  • ストリーミング: stream: true を使用した Server-Sent Events (SSE)
  • JSON モード: response_format: {"type": "json_object"} で有効な JSON を保証
  • 構造化出力: スキーマ検証済みの JSON 応答

高度な機能

  • ツール/関数呼び出し: モデルを外部 API に接続
  • マルチモーダル入力: 画像、PDF、音声のサポート
  • プロンプトキャッシュ: 繰り返しのプロンプトでコスト削減
  • ウェブ検索統合: ウェブデータによる応答の強化
  • ゼロ補完保険: 失敗した応答に対する保護
  • Logprobs: 信頼度分析のためのトークン確率へのアクセス

リファレンスファイル

このスキルには、references/ に包括的なドキュメントが含まれています:

  • llms-full.md - メタデータ付きの利用可能なモデルの完全なリスト
  • llms-small.md - 人気モデルの厳選サブセット
  • llms.md - 標準モデルリスト

詳細なモデル情報が必要な場合は、view を使用して特定のリファレンスファイルを参照してください。

このスキルの使用

初心者向け

  1. 基本的なチャット補完の例 (上記 Python/JavaScript/cURL) から始める
  2. 簡単な統合のために標準の OpenAI SDK を使用
  3. openai/gpt-4o や anthropic/claude-3.5-sonnet のようなシンプルなモデル名を試す
  4. 最初はパラメータをシンプルに (モデルとメッセージのみ)

中級者向け

  1. 信頼性を高めるためにモデルフォールバック配列を実装
  2. サンプリングパラメータ (temperature、top_p) を試す
  3. 会話型アプリで UX を向上させるためにストリーミングを使用
  4. 自動モデル選択のために openrouter/auto を試す
  5. 構造化データ抽出のために JSON モードを実装

上級者向け

  1. 複数のサンプリングパラメータを組み合わせて調整
  2. フォールバックチェーンを使用したカスタムルーティングロジックの実装
  3. 信頼度スコアリングのためのログプロブの使用
  4. ツール/関数呼び出し機能の活用
  5. タスクごとに適切なモデルを選択してコストを最適化
  6. プロンプトキャッシュ戦略の実装
  7. 再現可能なテストのためのシードパラメータの使用

一般的なパターン

フォールバックを使用したエラーハンドリング

try:
    completion = client.chat.completions.create(
        model="openai/gpt-4o",
        extra_body={
            "models": [
                "anthropic/claude-3.5-sonnet",
                "google/gemini-2.0-flash-exp:free"
            ]
        },
        messages=[{"role": "user", "content": "Your prompt"}]
    )
except Exception as e:
    print(f"All models failed: {e}")

コスト最適化ルーティング

# 単純なタスクには安価なモデルを使用
simple_completion = client.chat.completions.create(
    model="google/gemini-2.0-flash-exp:free",
    messages=[{"role": "user", "content": "Simple question"}]
)

# 複雑なタスクにはプレミアムモデルを使用
complex_completion = client.chat.completions.create(
    model="openai/o1",
    messages=[{"role": "user", "content": "Complex reasoning task"}]
)

コンテキストに応じた温度設定

# 事実に基づく応答には低い温度
factual = client.chat.completions.create(
    model="openai/gpt-4o",
    temperature=0.2,
    messages=[{"role": "user", "content": "What is the capital of France?"}]
)

# クリエイティブなコンテンツには高い温度
creative = client.chat.completions.create(
    model="openai/gpt-4o",
    temperature=1.2,
    messages=[{"role": "user", "content": "Write a unique story opening"}]
)

リソース

公式ドキュメント

主要なエンドポイント

  • チャット補完: POST https://openrouter.ai/api/v1/chat/completions
  • モデル一覧取得: GET https://openrouter.ai/api/v1/models
  • 生成情報取得: GET https://openrouter.ai/api/v1/generation

注意事項

  • OpenRouter はすべてのプロバイダー間で API スキーマを正規化
  • 簡単な移行のために OpenAI 互換の API 形式を使用
  • モデルがレート制限またはダウンしている場合の自動プロバイダーフォールバック
  • 価格は実際に使用されたモデルに基づく (フォールバック時に重要)
  • レスポンスには、リクエストを処理したモデルに関するメタデータが含まれる
  • すべてのモデルは Server-Sent Events によるストリーミングをサポート
  • 人気のフレームワーク (LangChain、Vercel AI SDK など) と互換性あり

ベストプラクティス

  1. 本番アプリケーションでは常にフォールバックを実装
  2. タスクの種類に基づいて適切な温度を使用 (事実には低く、創造的には高く)
  3. max_tokens を設定してコストと応答長を制御
  4. チャットアプリケーションではストリーミングを有効化してユーザーエクスペリエンスを向上
  5. 構造化出力が必要な場合は JSON モードを使用
  6. 開発中は再現可能な結果を得るためにシードパラメータでテスト
  7. タスクごとに適切なモデルを選択してコストを監視
  8. どのモデルが最適かわからない場合は自動ルーティングを使用
  9. レート制限と失敗に対して適切なエラーハンドリングを実装
  10. 繰り返しのリクエストではコスト削減のためにプロンプトをキャッシュ

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ASoudy/AGS

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

ASoudy/AGS

Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

ASoudy/AGS

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support.

ASoudy/AGS

One sentence - what this skill does and when to invoke it

ASoudy/AGS

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

ASoudy/AGS

Internationalization and localization patterns. Detecting hardcoded strings, managing translations, locale files, RTL support.

ASoudy/AGS

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

ASoudy/AGS

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

ASoudy/AGS

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

ASoudy/AGS

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

ASoudy/AGS

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

ASoudy/AGS

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

ASoudy/AGS

Next.js App Router principles. Server Components, data fetching, routing patterns.

ASoudy/AGS

Expert integration of Supabase Auth with Next.js App Router

ASoudy/AGS

React and Next.js 14+ application development with App Router, Server Components, TypeScript, Tailwind CSS, and modern frontend patterns.

ASoudy/AGS

Best practices for Remotion - Video creation in React

ASoudy/AGS

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

ASoudy/AGS

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

ASoudy/AGS

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

ASoudy/AGS

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

関連スキル