0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Portkey から nRouter への移行を10分で試す (Hands-on)

0
Posted at

Portkey と nRouter はどちらも OpenAI 互換の LLM ゲートウェイです。この記事では、実際にクライアントの2行を変更して移行を試し、料金・ガバナンスの違いを確認する手順を紹介します。

前提

  • Python 3.10+ と openai パッケージ
  • nRouter の API キー (https://nrouter.ai で取得)

Step 1: クライアントの差し替え

from openai import OpenAI

client = OpenAI(
    base_url="https://api.nrouter.ai/v1",  # was: https://api.portkey.ai/v1
    api_key="YOUR_NROUTER_API_KEY",
)

resp = client.chat.completions.create(
    model="nrouter/auto",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)

メッセージ配列・ツール呼び出し・ストリーミングはそのまま動きます。OpenAI 互換なので既存コードの変更はこの2行だけです。

Step 2: 料金モデルの違いを確認する

nRouter はクレジットに対する一律 4% のプラットフォーム利用料です。$100 分のクレジットなら $104 が請求され、$100 分が利用できます。すべてのガバナンス機能 (ガードレール、評価、予算上限) が全プランに含まれます。

Portkey はガバナンス機能が Pro / Enterprise プランに配置されています。試用時は「実際に使うプラン」の料金で比較してください。ベースプランの試用では、運用時のガバナンス面は評価できません。

Step 3: 予算切れとレート制限を区別する

nRouter の失敗セマンティクス:

  • 組織の予算上限を使い切った場合 → 402 budget_exceeded (リトライ不可。人間の承認が必要)
  • 単一キーの上限 → 429 key_budget_exceeded (リトライ可能)
try:
    resp = client.chat.completions.create(...)
except Exception as e:
    if getattr(e, "status_code", None) == 402:
        notify_human("Budget exhausted")  # お金の判断。リトライしない
    elif getattr(e, "status_code", None) == 429:
        time.sleep(backoff)               # バックオフしてリトライ

正直な「Portkey に残るべき」リスト

  • セルフホスト / VPC 内運用が必須 → Portkey はオープンソースのゲートウェイを公開しています。nRouter はホステッドのみです。
  • SOC 2 Type II レポートが今すぐ必要 → nRouter は取得中です。
  • 利用モデルが nRouter のカタログに無い → 両方を確認してください。

ソース付きの完全な比較はこちら: Portkey alternative: nothing behind a plan tier

Portkey is a trademark of Portkey AI. nRouter is not affiliated with or endorsed by Portkey.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?