POST/api/gateway/usage/import

ローカルの過去の使用量をインポート

ローカルのCodexまたはClaude Codeのログ(メタデータのみ)からターンごとのトークン数を組織に帰属させ、現在のカタログ定価で料金を算出します。課金されることもクレジットから差し引かれることもありません。レコードIDごとにべき等です。不明なモデルはコスト0で保持され、unmatched_modelsに一覧表示されます。

認証: AuthorizationヘッダーにBearer形式のAPIキー

リクエストボディ

  • batch_idstring必須

    実行をグループ化します。同じレコードを再実行しても何も挿入されません。

  • recordsarray<object>必須
    records
    • modelstring必須

      ローカルログ上のモデルID。

    • input_tokensinteger必須

      新規(キャッシュされていない)入力。

    • output_tokensinteger必須

      推論を含む出力。

    • cached_tokensinteger

      キャッシュ入力。

      既定値: 0
    • reasoning_tokensinteger

      出力のうち推論部分(表示用)。

      既定値: 0
    • timestampstring必須

      ISO 8601形式のターン時刻。タイムゾーンなしの値はUTCとして扱います。

    • sourceenum必須
      "codex""claude-code"
    • event_idstring | null

      ログ内のターンごとの安定したIDで、重複排除ハッシュに組み込まれます。

  • org_idstring | null

    APIキーでは無視されます。キーは常に自身の組織にインポートします。

レスポンス

  • 201

    インポートしました。

    レスポンス
    • batch_idstring必須
    • receivedinteger必須
    • importedinteger必須

      新たに挿入されたレコード。

    • duplicatesinteger必須

      以前にインポート済みのレコード。

    • unmatched_modelsarray<string>必須
    • by_modelarray<object>必須

      このバッチ適用後の、組織のインポート済みの帰属データ全体。

      by_model
      • sourceenum必須
        "codex""claude-code"
      • modelstring必須

        一致した場合はカタログのスラッグ、それ以外は元のモデルID。

      • model_matchedboolean必須

        モデルがカタログ外の場合はfalse(価格0)。

      • request_countinteger必須
      • input_tokensinteger必須
      • output_tokensinteger必須
      • cached_input_tokensinteger必須
      • reasoning_tokensinteger必須
      • cost_usdnumber必須

        現在の定価による過去の帰属(ドル)。課金されることはありません。

    • totalsobject必須
      totals
      • request_countinteger必須
      • input_tokensinteger必須
      • output_tokensinteger必須
      • cost_usdnumber必須

        ドル。帰属のみです。

  • 400

    空のバッチ、10,000件を超えるレコード、または不正なタイムスタンプ。

    レスポンス
    • errorstring必須

      人が読めるメッセージ。

    • codestring

      エンドポイントが定義している場合の、安定した機械可読の理由(例:pro_required)。

    • actionstring

      エンドポイントが定義している場合の、安定した対処アクション。

    • detailsobject

      呼び出し元が対処するために必要な、顧客に提示して安全な文字列情報(推奨される識別子など)。

  • 401

    APIキーがない、不明、または失効しています。

    レスポンス
    • errorstring必須

      人が読めるメッセージ。

    • codestring

      エンドポイントが定義している場合の、安定した機械可読の理由(例:pro_required)。

    • actionstring

      エンドポイントが定義している場合の、安定した対処アクション。

    • detailsobject

      呼び出し元が対処するために必要な、顧客に提示して安全な文字列情報(推奨される識別子など)。

  • 403

    組織のAPIキーで呼び出されていません。

    レスポンス
    • errorstring必須

      人が読めるメッセージ。

    • codestring

      エンドポイントが定義している場合の、安定した機械可読の理由(例:pro_required)。

    • actionstring

      エンドポイントが定義している場合の、安定した対処アクション。

    • detailsobject

      呼び出し元が対処するために必要な、顧客に提示して安全な文字列情報(推奨される識別子など)。

  • 422

    ボディまたはクエリの検証に失敗しました。

    レスポンス
    • detailarray<object>必須
      detail
      • typestring
      • locarray<string | integer>
      • msgstring

リクエスト

curl -X POST 'https://api.experientiallabs.ai/api/gateway/usage/import' \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
  "batch_id": "laptop-2026-11-18",
  "records": [
    {
      "model": "claude-sonnet-4-6",
      "input_tokens": 1840,
      "output_tokens": 622,
      "cached_tokens": 41200,
      "reasoning_tokens": 0,
      "timestamp": "2026-11-12T18:04:11Z",
      "source": "claude-code",
      "event_id": "msg_01Hq8Xc2"
    },
    {
      "model": "gpt-5.5-codex",
      "input_tokens": 3120,
      "output_tokens": 904,
      "cached_tokens": 12800,
      "reasoning_tokens": 512,
      "timestamp": "2026-11-13T09:41:52Z",
      "source": "codex",
      "event_id": "sess-7f2a:14"
    }
  ]
}'

レスポンス

{
  "batch_id": "laptop-2026-11-18",
  "received": 2,
  "imported": 2,
  "duplicates": 0,
  "unmatched_models": [],
  "by_model": [
    {
      "source": "claude-code",
      "model": "claude-sonnet-4.6",
      "model_matched": true,
      "request_count": 1,
      "input_tokens": 1840,
      "output_tokens": 622,
      "cached_input_tokens": 41200,
      "reasoning_tokens": 0,
      "cost_usd": 0.027
    },
    {
      "source": "codex",
      "model": "gpt-5.5-codex",
      "model_matched": true,
      "request_count": 1,
      "input_tokens": 3120,
      "output_tokens": 904,
      "cached_input_tokens": 12800,
      "reasoning_tokens": 512,
      "cost_usd": 0.0167
    }
  ],
  "totals": {
    "request_count": 2,
    "input_tokens": 4960,
    "output_tokens": 1526,
    "cost_usd": 0.0437
  }
}

https://api.experientiallabs.ai/api/gateway/usage/import