openrouter-pricing-basics
OpenRouterの料金体系を理解し、コスト計算と支出の最適化ができます。予算設定、モデルコストの比較、支出管理が必要な場合に利用してください。以下のキーワードで起動します:「openrouter pricing」「openrouter cost」「model pricing」「openrouter budget」「how much does openrouter cost」。
description の原文を見る
Understand OpenRouter pricing, calculate costs, and optimize spend. Use when budgeting, comparing model costs, or tracking spend. Triggers: 'openrouter pricing', 'openrouter cost', 'model pricing', 'openrouter budget', 'how much does openrouter cost'.
SKILL.md 本文
OpenRouter 料金基本ガイド
概要
OpenRouter はトークンごとに課金され、プロンプト (入力) とコンプリーション (出力) トークンで異なるレートが設定されています。料金は API のモデル内でトークンあたりの価格として表示されます (100 万トークンあたりの料金にするには 1M を掛けます)。クレジットは前払いで、処理手数料が 5.5% かかります (最小 $0.80)。無料モデルはテストと低頻度の使用に利用できます。
料金の仕組み
- クレジットを購入 openrouter.ai/credits で (5.5% 手数料、最小 $0.80)
- 各リクエスト で
(prompt_tokens * prompt_rate) + (completion_tokens * completion_rate)が差し引かれます - 残高を確認
GET /api/v1/auth/keyまたはダッシュボードで確認できます - 自動トップアップ はサービス中断を防ぐために利用できます
モデルの料金を照会
# すべてのモデルの料金を取得
curl -s https://openrouter.ai/api/v1/models | jq '.data[] | select(.id == "anthropic/claude-3.5-sonnet") | {
id: .id,
prompt_per_M: ((.pricing.prompt | tonumber) * 1000000),
completion_per_M: ((.pricing.completion | tonumber) * 1000000),
context: .context_length
}'
# → { "id": "anthropic/claude-3.5-sonnet", "prompt_per_M": 3, "completion_per_M": 15, "context": 200000 }
コスト ティア (代表例)
| ティア | モデル例 | プロンプト/100万 | コンプリーション/100万 | ユースケース |
|---|---|---|---|---|
| 無料 | google/gemma-2-9b-it:free | $0.00 | $0.00 | テスト、プロトタイピング |
| バジェット | meta-llama/llama-3.1-8b-instruct | $0.06 | $0.06 | シンプルな Q&A、分類 |
| 中級 | openai/gpt-4o-mini | $0.15 | $0.60 | 汎用 |
| スタンダード | anthropic/claude-3.5-sonnet | $3.00 | $15.00 | 複雑な推論、コード |
| プレミアム | openai/o1 | $15.00 | $60.00 | 深い推論 |
リクエストのコストを計算
def estimate_cost(model_id: str, prompt_tokens: int, completion_tokens: int) -> float:
"""単一リクエストのコストを計算します。"""
import requests
models = requests.get("https://openrouter.ai/api/v1/models").json()["data"]
model = next((m for m in models if m["id"] == model_id), None)
if not model:
raise ValueError(f"Model {model_id} not found")
prompt_rate = float(model["pricing"]["prompt"]) # トークンあたりのコスト
completion_rate = float(model["pricing"]["completion"])
return (prompt_tokens * prompt_rate) + (completion_tokens * completion_rate)
# 例: Claude 3.5 Sonnet、プロンプト 1000 + コンプリーション 500 トークン
cost = estimate_cost("anthropic/claude-3.5-sonnet", 1000, 500)
print(f"Estimated cost: ${cost:.6f}") # ~$0.0105
リクエストごとの実際のコストを追跡
import requests
# 方法 1: レスポンスの使用量から (推定値)
response = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet",
messages=[{"role": "user", "content": "Hello"}],
max_tokens=100,
)
# response.usage.prompt_tokens, response.usage.completion_tokens
# 方法 2: 生成エンドポイントを照会 (OpenRouter からの正確なコスト)
gen = requests.get(
f"https://openrouter.ai/api/v1/generation?id={response.id}",
headers={"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}"},
).json()
print(f"Exact cost: ${gen['data']['total_cost']}")
print(f"Tokens: {gen['data']['tokens_prompt']} prompt + {gen['data']['tokens_completion']} completion")
クレジット残高を確認
curl -s https://openrouter.ai/api/v1/auth/key \
-H "Authorization: Bearer $OPENROUTER_API_KEY" | jq '{
credits_used: .data.usage,
credit_limit: .data.limit,
remaining: ((.data.limit // 0) - .data.usage),
is_free_tier: .data.is_free_tier
}'
バリアントで費用を削減
# :floor バリアントはモデルの最も安いプロバイダーを選択します
response = client.chat.completions.create(
model="anthropic/claude-3.5-sonnet:floor", # 最も安いプロバイダー
messages=[{"role": "user", "content": "Hello"}],
max_tokens=100,
)
# :free バリアントは無料プロバイダーを使用します (利用可能な場合)
response = client.chat.completions.create(
model="google/gemma-2-9b-it:free",
messages=[{"role": "user", "content": "Hello"}],
max_tokens=100,
)
特別な料金
| 項目 | 料金 |
|---|---|
| 推論トークン | コンプリーション レートで出力トークンとして課金 |
| 画像入力 | pricing.image に記載されている画像ごとの課金 |
| リクエストごとの手数料 | 一部のモデルはリクエストごとの固定手数料を請求 (pricing.request) |
| BYOK | 最初の 100 万リクエスト/月は無料。その後、通常のプロバイダー コストの 5% |
| 無料モデルの制限 | 50 リクエスト/日 (無料ユーザー)、1000 リクエスト/日 ($10 以上のクレジット保有者) |
エラー処理
| HTTP | 原因 | 対処方法 |
|---|---|---|
| 402 | クレジット不足 | openrouter.ai/credits でトップアップするか、:free モデルを使用します |
| 402 | キーのクレジット制限に達した | キーの制限を増やすか、別のキーを使用します |
エンタープライズに関する考慮事項
- ダッシュボードまたはプロビジョニング API を使用してキーごとのクレジット制限を設定し、影響範囲を分離します
- 正確なコスト監査のためにリクエストごとに
/api/v1/generation?id=を照会します :floorバリアントを使用して最も安いプロバイダーを自動的に選択します- シンプルなタスクをバジェット モデルにルーティングし、複雑なタスクをプレミアム モデルにルーティングします (openrouter-model-routing を参照)
- すべてのリクエストで
max_tokensを設定してコンプリーション コストに上限を設定します - 本番環境でサービス中断を防ぐため、自動トップアップを有効にします
参考資料
- Examples | Errors
- Pricing | Credits | Models API
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- jeremylongshore
- ライセンス
- MIT
- 最終更新
- 2026/5/12
Source: https://github.com/jeremylongshore/claude-code-plugins-plus-skills / ライセンス: MIT