コンテンツへスキップ
APIリファレンス
APIリファレンス

OpenAI Chat Completions

RunAPIのOpenAI互換Chat Completionsオペレーションを通じてリクエストを送信します。

01

概要

RunAPIのOpenAI互換のChat Completions操作を、互換性のあるモデルおよびプロトコルのリクエスト・レスポンス形式とともに使用してください。

クイックスタート

  1. APIキーを作成し、RUNAPI_API_KEYとして設定します。
  2. 互換性のあるモデルを選択し、ドキュメントに記載されたパスパラメーターとJSONボディを送信します。
  3. このオペレーションに示された JSON レスポンスまたはサーバー送信イベントを読み取り、プロトコルエラーを処理してください。

エンドポイント

POST /v1/chat/completions
ベースURL
https://runapi.ai
コントラクトバージョン
v1
推奨認証方式
Authorization: Bearer YOUR_API_TOKEN
02

認証情報の送信方法

RunAPIは以下に列挙された各キャリアを受け付けます。生成されたサンプルはプロトコルの推奨ヘッダーを使用します。

header - 推奨
Authorization: Bearer YOUR_API_TOKEN
header
x-api-key: YOUR_API_TOKEN
header
x-goog-api-key: YOUR_API_TOKEN
query
?key=YOUR_API_TOKEN
03

互換モデル

現在の料金、レート制限、商用利用の詳細については、モデルページを開いてください。

互換性のある 60 モデルを表示
04

リクエスト仕様

JSONボディ

公開プロトコルとRunAPIサポートの両方の証拠があるフィールドのみが記載されています。追加のJSONボディフィールドはそのまま渡されます。

JSON ボディフィールド9件
max_tokens["integer", "null"]
任意

サポートされているモデルに対して保持される互換性生成トークン制限。モデルサポートは異なる場合があります。

messagesarray
必須

OpenAI Chat Completions形式の会話メッセージ。

messages[].content["string", "array"]
任意
messages[].rolestring
必須
modelstring
必須

互換モデルカタログによって返されるRunAPIのモデル識別子。

stream["boolean", "null"]
任意

Chat Completionsのチャンクをサーバー送信イベントとして返します。

デフォルト: false
temperature["number", "null"]
任意

サンプリング温度。モデルによってサポート状況が異なる場合があります。

toolsarray
任意

モデルが呼び出せるツール。

top_p["number", "null"]
任意

核サンプリング確率。モデルによってサポート状況が異なる場合があります。

リクエスト例

JSON
{
  "messages": [
    {
      "content": "Summarize one practical improvement for an API deployment.",
      "role": "user"
    }
  ],
  "model": "gpt-5.4",
  "stream": false
}
05

同期レスポンス

HTTP 200

スキーマ

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion",
      "type": "string"
    },
    "usage": {
      "additionalProperties": true,
      "properties": {
        "completion_tokens": {
          "type": "integer"
        },
        "prompt_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ],
      "type": "object"
    }
  },
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices"
  ],
  "type": "object"
}

JSON
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "Hello! How can I help today?",
        "role": "assistant"
      }
    }
  ],
  "created": 1785196800,
  "id": "chatcmpl_example",
  "model": "gpt-5.4",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 8,
    "prompt_tokens": 12,
    "total_tokens": 20
  }
}
06

SSEイベント:chunk

text/event-stream

スキーマ

JSON
{
  "additionalProperties": true,
  "properties": {
    "choices": {
      "type": "array"
    },
    "created": {
      "type": "integer"
    },
    "id": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "object": {
      "const": "chat.completion.chunk",
      "type": "string"
    },
    "usage": {
      "oneOf": [
        {
          "additionalProperties": true,
          "properties": {
            "completion_tokens": {
              "type": "integer"
            },
            "prompt_tokens": {
              "type": "integer"
            },
            "total_tokens": {
              "type": "integer"
            }
          },
          "required": [
            "prompt_tokens",
            "completion_tokens",
            "total_tokens"
          ],
          "type": "object"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "object",
    "choices"
  ],
  "type": "object"
}

JSON
{
  "choices": [
    {
      "delta": {
        "content": "Hello"
      },
      "finish_reason": null,
      "index": 0
    }
  ],
  "id": "chatcmpl_example",
  "object": "chat.completion.chunk",
  "usage": null
}
07

プロトコルエラー: invalid_request

HTTP 400

スキーマ

JSON
{
  "additionalProperties": true,
  "properties": {
    "error": {
      "additionalProperties": true,
      "properties": {
        "code": {
          "type": [
            "string",
            "null"
          ]
        },
        "message": {
          "type": "string"
        },
        "param": {
          "type": [
            "string",
            "null"
          ]
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "message",
        "type"
      ],
      "type": "object"
    }
  },
  "required": [
    "error"
  ],
  "type": "object"
}

JSON
{
  "error": {
    "code": null,
    "message": "messages is required",
    "param": "messages",
    "type": "invalid_request_error"
  }
}
08

使用方法

スキーマ

JSON
{
  "additionalProperties": true,
  "properties": {
    "completion_tokens": {
      "type": "integer"
    },
    "prompt_tokens": {
      "type": "integer"
    },
    "total_tokens": {
      "type": "integer"
    }
  },
  "required": [
    "prompt_tokens",
    "completion_tokens",
    "total_tokens"
  ],
  "type": "object"
}

JSON
{
  "completion_tokens": 8,
  "prompt_tokens": 12,
  "total_tokens": 20
}
09

生成されたコードサンプル

各cURL、JavaScript、およびPythonのサンプルは、プロトコル固有のSDKを必要とせずに、このコントラクトから検証済みのリクエストを送信します。

インストール

Shell
pip install requests
PYTHON
import requests

response = requests.post(
    "https://runapi.ai/v1/chat/completions",
    headers={"Authorization": "Bearer YOUR_API_TOKEN", "Content-Type": "application/json"},
    json={"model": "gpt-5.4", "messages": [{"role": "user", "content": "Summarize one practical improvement for an API deployment."}], "stream": False}
)
response.raise_for_status()
print(response.json())