ARouter は主要な LLM プロバイダー向けに統一された API key と単一エンドポイントを提供します。すでに OpenAI 互換クライアントを使用している場合、移行に必要な変更は通常 base_url、api_key、そして任意でアプリ帰属ヘッダーの変更のみです。
1. API Key を取得する
ARouter ダッシュボード でサインアップして API key を作成します。
key の形式は lr_live_xxxxxxxxxxxx のようになります。
2. ARouter SDK をインストールする
公式 @arouter/sdk は任意の Node.js または TypeScript プロジェクトで動作し、npm、yarn、pnpm に対応しています。
import { ARouter } from "@arouter/sdk";
const client = new ARouter({
apiKey: "lr_live_xxxx",
baseURL: "https://api.arouter.ai",
});
const response = await client.chatCompletion({
model: "openai/gpt-5.4",
messages: [{ role: "user", content: "こんにちは!" }],
});
console.log(response.choices[0].message.content);
ストリーミング、key 管理、x402 支払いの例については Node.js / TypeScript SDK ガイド をご覧ください。
3. 既存の SDK を使用する
すでに OpenAI、Anthropic、または Go を使用していますか?変更が必要なのは base_url と api_key だけです。
Python (OpenAI)
Node.js (OpenAI)
Python (Anthropic)
Go
cURL
fetch
from openai import OpenAI
client = OpenAI(
base_url="https://api.arouter.ai/v1",
api_key="lr_live_xxxx",
default_headers={
"HTTP-Referer": "https://myapp.com", # 任意
"X-Title": "My AI App", # 任意
},
)
response = client.chat.completions.create(
model="openai/gpt-5.4",
messages=[{"role": "user", "content": "こんにちは!"}],
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.arouter.ai/v1",
apiKey: "lr_live_xxxx",
defaultHeaders: {
"HTTP-Referer": "https://myapp.com", // 任意
"X-Title": "My AI App", // 任意
},
});
const response = await client.chat.completions.create({
model: "openai/gpt-5.4",
messages: [{ role: "user", content: "こんにちは!" }],
});
console.log(response.choices[0].message.content);
import anthropic
client = anthropic.Anthropic(
base_url="https://api.arouter.ai",
api_key="lr_live_xxxx",
)
message = client.messages.create(
model="claude-sonnet-4.6",
max_tokens=1024,
messages=[{"role": "user", "content": "こんにちは!"}],
)
print(message.content[0].text)
package main
import (
"context"
"fmt"
"log"
"github.com/arouter-ai/arouter-go"
)
func main() {
client := arouter.NewClient("lr_live_xxxx",
arouter.WithBaseURL("https://api.arouter.ai/v1"),
arouter.WithHeader("HTTP-Referer", "https://myapp.com"),
arouter.WithHeader("X-Title", "My AI App"),
)
resp, err := client.CreateChatCompletion(context.Background(), arouter.ChatCompletionRequest{
Model: "openai/gpt-5.4",
Messages: []arouter.Message{
{Role: "user", Content: "こんにちは!"},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}
curl https://api.arouter.ai/v1/chat/completions \
-H "Authorization: Bearer lr_live_xxxx" \
-H "HTTP-Referer: https://myapp.com" \
-H "X-Title: My AI App" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-5.4",
"messages": [{"role": "user", "content": "こんにちは!"}]
}'
const response = await fetch('https://api.arouter.ai/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer lr_live_xxxx',
'Content-Type': 'application/json',
'HTTP-Referer': 'https://myapp.com', // 任意:ソーストラッキング
'X-Title': 'My AI App', // 任意:表示名
},
body: JSON.stringify({
model: 'openai/gpt-5.4',
messages: [{ role: 'user', content: 'こんにちは!' }],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);
HTTP-Referer と X-Title は任意です。ARouter ダッシュボードの分析でリクエストを特定のアプリやワークフローに帰属させたい場合は、これらのヘッダーを含めてください。
4. API を直接呼び出す
SDK をインストールしたくない場合は、任意の HTTP クライアントで ARouter を呼び出せます:
import json
import requests
response = requests.post(
"https://api.arouter.ai/v1/chat/completions",
headers={
"Authorization": "Bearer lr_live_xxxx",
"HTTP-Referer": "https://myapp.com", # 任意
"X-Title": "My AI App", # 任意
"Content-Type": "application/json",
},
data=json.dumps({
"model": "openai/gpt-5.4",
"messages": [{"role": "user", "content": "こんにちは!"}],
}),
)
print(response.json()["choices"][0]["message"]["content"])
5. 異なるプロバイダーを試す
ARouter では、model 文字列を変更するだけでプロバイダーを切り替えられます:
# OpenAI
response = client.chat.completions.create(model="openai/gpt-5.4", ...)
# Anthropic(OpenAI SDK 経由!)
response = client.chat.completions.create(model="anthropic/claude-sonnet-4.6", ...)
# Google Gemini
response = client.chat.completions.create(model="google/gemini-2.5-flash", ...)
# DeepSeek
response = client.chat.completions.create(model="deepseek/deepseek-v3.2", ...)
プロバイダープレフィックスを省略した場合(例:"gpt-5.4" のみ)、ARouter はデフォルトで OpenAI を使用します。
次のステップ
モデルルーティング
provider/model 形式とマルチモデルルーティングを理解する
請求とクレジット
料金、残高、クレジットルールを確認する
リクエスト帰属
ダッシュボード分析でトラフィックをアプリに帰属させる
ストリーミング
リアルタイムストリーミングレスポンスを有効にする
構造化出力
モデルに有効な JSON スキーマを返させる
プロンプトキャッシュ
繰り返しプロンプトのコストとレイテンシを削減する
Key 管理
チーム向けにスコープ付き key を作成する