OpenRouterを使用した自動AIルーティング
中級
これはEngineering, Building Blocks, AI, IT Ops分野の自動化ワークフローで、7個のノードを含みます。主にAgent, ChatTrigger, LmChatOpenRouter, OutputParserStructuredなどのノードを使用、AI技術を活用したスマート自動化を実現。 OpenRouterを活用した動のAIモデルルーティングによるクエリ最適化
前提条件
- •AIサービスAPIキー(OpenAI、Anthropicなど)
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
"id": "uNLWQ7BSozpoehpU",
"meta": {
"instanceId": "a4bfc93e975ca233ac45ed7c9227d84cf5a2329310525917adaf3312e10d5462",
"templateCredsSetupCompleted": true
},
"name": "Automated AI Routing with OpenRouter",
"tags": [],
"nodes": [
{
"id": "25903a04-24d2-41f9-bf34-5d6234e642e5",
"name": "チャットメッセージ受信時",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-180,
-180
],
"webhookId": "a0032740-26d8-491b-93f9-2250906d0e17",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "fabffdee-3c1e-47db-a4e9-f6473a6e9257",
"name": "OpenRouter Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
0,
40
],
"parameters": {
"options": {}
},
"credentials": {
"openRouterApi": {
"id": "pb06rfB4xmxzVe3Q",
"name": "OpenRouter"
}
},
"typeVersion": 1
},
{
"id": "c53fe672-92cb-4d88-b4f6-f413fb00ad6a",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
220,
40
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"prompt\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"model\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}"
},
"typeVersion": 1.2
},
{
"id": "d60a9d61-c611-4813-bf85-e8f8faaa21b6",
"name": "OpenRouter Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
380,
40
],
"parameters": {
"model": "={{ $json.output.model }}",
"options": {}
},
"credentials": {
"openRouterApi": {
"id": "pb06rfB4xmxzVe3Q",
"name": "OpenRouter"
}
},
"typeVersion": 1
},
{
"id": "ef9ceacb-55e4-4795-aa18-976997ec3717",
"name": "付箋ノート",
"type": "n8n-nodes-base.stickyNote",
"position": [
-180,
-420
],
"parameters": {
"width": 840,
"height": 180,
"content": "## Dynamic Model Selector for Optimal AI Responses\n\nThe **Agent Decisioner** is a dynamic, AI-powered routing system that automatically selects the most appropriate large language model (LLM) to respond to a user's query based on the query’s content and purpose.\n\nThis workflow ensures **dynamic, optimized AI responses** by intelligently routing queries to the best-suited model."
},
"typeVersion": 1
},
{
"id": "4d688ad7-b463-4e72-9b79-4b9142f022d2",
"name": "ルーティングエージェント",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
40,
-180
],
"parameters": {
"options": {
"systemMessage": "=You are a **Routing Agent**.\n\nYour task is to analyze user queries and determine the most appropriate model to handle each specific use case.\n\n## Available Models\n\nYou have access to the following models:\n\n1. **perplexity/sonar**\n2. **openai/gpt-4o-mini**\n3. **anthropic/claude-3.7-sonnet**\n4. **meta-llama/llama-3-70b-instruct**\n5. **google/gemini-2.5-pro-preview**\n6. **qwen/qwen-qwq-32b**\n7. **openai/codex-mini**\n8. **openai/o1-pro**\n\n## Model Strengths\n\n### 1. perplexity/sonar\n- Built-in web search capability\n- Provides citations and customizable sources\n- Ideal for retrieving live, up-to-date information from the web\n\n### 2. openai/gpt-4o-mini\n- Cost-efficient language model optimized for advanced reasoning tasks\n- Excels in science and mathematics\n- Best suited for problems requiring careful, well-thought-out responses involving multiple variables or connections\n\n### 3. anthropic/claude-3.7-sonnet\n- High proficiency in coding tasks, scoring ~94% on SWE-Bench Verified\n- Enhances data science expertise by navigating unstructured data and utilizing multiple tools for insights\n- Handles very long documents and maintains coherence over extended conversations or analyses\n- Performs well in creative writing tasks such as storytelling, dialogue generation, and summarization\n- Tends to produce responses that are more aligned with safety and ethical guidelines\n\n### 4. meta-llama/llama-3-70b-instruct\n- Strong performance in coding and reasoning tasks\n- Suitable for complex programming and technical problem-solving\n- Supports long context windows, making it ideal for extended analyses\n\n### 5. google/gemini-2.5-pro-preview\n- Advanced multimodal capabilities, handling both text and images\n- Excels in tasks requiring integration of visual and textual information\n- Ideal for complex problem-solving involving diverse data types\n\n### 6. qwen/qwen-qwq-32b\n- Specialized in reasoning and problem-solving tasks\n- Effective in handling logical puzzles and complex analytical queries\n\n### 7. openai/codex-mini\n- Optimized for code generation and completion tasks\n- Suitable for lightweight coding tasks and quick code snippets\n\n### 8. openai/o1-pro\n- Designed for complex reasoning with enhanced computational resources\n- Performs well in STEM-related tasks, including physics, chemistry, and biology\n- Capable of handling large context windows, making it suitable for in-depth analyses\n\n## Output Format\n\nYour output must always be a valid JSON object in the following format:\n\n```json\n{\n \"prompt\": \"user query goes here\",\n \"model\": \"selected-model-name\"\n}\n```\n\n- The **\"prompt\"** field should contain the exact query to be sent to the selected model.\n- The **\"model\"** field should contain the model name (one of: perplexity/sonar, openai/gpt-4o-mini, anthropic/claude-3.7-sonnet, meta-llama/llama-3-70b-instruct, google/gemini-2.5-pro-preview, qwen/qwen-qwq-32b, openai/codex-mini, openai/o1-pro).\n\n**Important:** Only return the JSON object. Do not include any explanations or additional text."
},
"hasOutputParser": true
},
"typeVersion": 1.9
},
{
"id": "94c49c22-9697-4230-ba35-5159041cfdc7",
"name": "AIエージェント",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
400,
-180
],
"parameters": {
"text": "={{ $json.output.prompt }}",
"options": {},
"promptType": "define"
},
"typeVersion": 1.9
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "f1562281-3e44-4f7d-a585-90c54a65e888",
"connections": {
"4d688ad7-b463-4e72-9b79-4b9142f022d2": {
"main": [
[
{
"node": "94c49c22-9697-4230-ba35-5159041cfdc7",
"type": "main",
"index": 0
}
]
]
},
"fabffdee-3c1e-47db-a4e9-f6473a6e9257": {
"ai_languageModel": [
[
{
"node": "4d688ad7-b463-4e72-9b79-4b9142f022d2",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"d60a9d61-c611-4813-bf85-e8f8faaa21b6": {
"ai_languageModel": [
[
{
"node": "94c49c22-9697-4230-ba35-5159041cfdc7",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"c53fe672-92cb-4d88-b4f6-f413fb00ad6a": {
"ai_outputParser": [
[
{
"node": "4d688ad7-b463-4e72-9b79-4b9142f022d2",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"25903a04-24d2-41f9-bf34-5d6234e642e5": {
"main": [
[
{
"node": "4d688ad7-b463-4e72-9b79-4b9142f022d2",
"type": "main",
"index": 0
}
]
]
}
}
}よくある質問
このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
中級 - エンジニアリング, ビルディングブロック, 人工知能, IT運用
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
エージェント AI Anthropic Opus4 および Sonnet4
Anthropic AIエージェント:Claude Sonnet 4 と Opus 4、思考機能と web 検索ツール付き
Agent
Http Request Tool
Tool Think
+
Agent
Http Request Tool
Tool Think
11 ノードDavide
エンジニアリング
狭い: OpenAI CSV 分析
OpenAI ダイバーによる Google Sheets データの分析
Agent
Google Sheets Tool
Chat Trigger
+
Agent
Google Sheets Tool
Chat Trigger
6 ノードozkary
エンジニアリング
Claude 3.7 Sonnet AI エージェント(ウェブ検索とサイエンス機能付き)
Anthropicのweb検索と考え機能付きClaude 3.7 Sonnet AIチャットボットエージェント
Agent
Http Request Tool
Tool Think
+
Agent
Http Request Tool
Tool Think
7 ノードDavide
ビルディングブロック
データエンジニア AI Agent v3
スプレッドシート向けのAIデータ分析アシスタント、NocoDBプラットフォームを基に
Set
Noco Db Tool
Http Request
+
Set
Noco Db Tool
Http Request
10 ノードDerek Cheung
エンジニアリング
非常に簡単な人間が介入する AI メールと IMAP
非常にシンプルな「人間が介入する巡回」型メール返信システム――AI と IMAP プロトコルを活用
If
Set
Markdown
+
If
Set
Markdown
16 ノードDavide
ビルディングブロック
AI スマートアシスタント: Supabase ストレージと Google Drive ファイルとの対話
AIワンチャットボット:SupabaseストレージとGoogle Driveのファイルと対話
If
Set
Wait
+
If
Set
Wait
62 ノードMark Shcherbakov
エンジニアリング
ワークフロー情報
難易度
中級
ノード数7
カテゴリー4
ノードタイプ5
作成者
Davide
@n3witaliaFull-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at info@n3w.it or add me on Linkedin.com/in/davideboizza
外部リンク
n8n.ioで表示 →
このワークフローを共有