API ReferenceText APIs
OpenAI Chat API
このプラットフォームでは、OpenAI Chat Completions API と互換性のあるチャットエンドポイントを提供しています。
このドキュメントはクライアント側で統合を行う開発者向けに、公開リクエストパス、認証方式、主要パラメータ、代表的なリクエスト例を説明するものです。フィールド名と JSON 構造は、できるだけ OpenAI Chat Completions API のネイティブ仕様に寄せています。
概要:
- エンドポイント:
POST /v1/chat/completions - 機能カテゴリ: チャット / テキスト生成
- レスポンス形式:
stream = falseまたは省略時: 通常の JSON レスポンスstream = true時:text/event-streamの SSE レスポンス
- プロトコル上の特徴: リクエストボディは OpenAI Chat Completions のネイティブ構造に従い、余分な
inputラッパーは使いません
現在の対象範囲:
- 対象は
POST /v1/chat/completionsのみです POST /v1/responsesにも対応していますが、こちらは/docs/api-reference/text/openai-response-apiで別途説明しています- embeddings、images、audio など、その他の OpenAI エンドポイントはこのページでは扱いません
1. API 概要
- HTTP メソッド:
POST - リクエストパス:
/v1/chat/completions - Content-Type:
application/json - レスポンス形式:
- 非ストリーミング:
application/json - ストリーミング:
text/event-stream
- 非ストリーミング:
2. 認証とヘッダー
ヘッダー例:
Authorization: Bearer YOUR_REACH_API_KEY
Content-Type: application/jsonAuthorization または x-api-key のいずれかを指定してください。
ヘッダー詳細:
| Header | 必須 | 説明 |
|---|---|---|
Authorization | いいえ | Bearer sk-xxxxxx 形式のプラットフォーム API キー |
x-api-key | いいえ | プラットフォーム API キーをこのヘッダーで直接渡すこともできます |
Content-Type | はい | application/json である必要があります |
3. リクエストボディ
リクエストボディは、OpenAI Chat Completions API の標準的なオブジェクト構造に従います。
{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Please introduce yourself in one sentence."
}
],
"temperature": 0.2,
"stream": false
}3.1 トップレベルパラメータ
| Field | Type | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル ID |
messages | array<object> | はい | チャットメッセージ配列。少なくとも 1 件必要です |
temperature | number | いいえ | サンプリング温度 |
top_p | number | いいえ | Nucleus Sampling パラメータ |
n | integer | いいえ | 候補生成数 |
max_tokens | integer | いいえ | 出力トークン上限 |
max_completion_tokens | integer | いいえ | 一部モデルで使える新しい出力トークン上限 |
stop | string or array<string> | いいえ | 停止シーケンス |
stream | boolean | いいえ | SSE ストリーミングで返すかどうか |
stream_options | object | いいえ | include_usage などの追加ストリーミング設定 |
tools | array<object> | いいえ | ツール定義 |
tool_choice | string or object | いいえ | ツール呼び出し戦略 |
parallel_tool_calls | boolean | いいえ | 並列ツール呼び出しを許可するか |
response_format | object | いいえ | 構造化出力設定 |
presence_penalty | number | いいえ | 話題新規性のペナルティ |
frequency_penalty | number | いいえ | 繰り返し抑制ペナルティ |
logit_bias | object | いいえ | トークンバイアス設定 |
user | string | いいえ | エンドユーザー識別子 |
3.2 messages パラメータ
各メッセージは次の構造を使います。
| Field | Type | 必須 | 説明 |
|---|---|---|---|
role | string | はい | ロール。代表値: system, user, assistant, tool |
content | string or array<object> | はい | メッセージ内容。プレーンテキストまたはコンテンツブロック配列 |
name | string | いいえ | 任意のロール名 |
tool_call_id | string | いいえ | role = tool のときにツール呼び出しと紐付ける ID |
テキスト例:
{
"role": "user",
"content": "Write a product introduction in no more than 50 words."
}コンテンツブロック例:
{
"role": "user",
"content": [
{
"type": "text",
"text": "Please describe this image."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.example.com/demo.png"
}
}
]
}4. リクエスト例
4.1 非ストリーミングの標準リクエスト
curl -X POST "https://direct.reachapi.ai/v1/chat/completions" -H "Authorization: Bearer YOUR_REACH_API_KEY" -H "Content-Type: application/json" -d '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Introduce ReachAPI in one sentence."
}
],
"temperature": 0.2
}'4.2 ストリーミングリクエスト
curl -X POST "https://direct.reachapi.ai/v1/chat/completions" -H "Authorization: Bearer YOUR_REACH_API_KEY" -H "Content-Type: application/json" -d '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Summarize today'''s priorities in three lines."
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'4.3 ツール定義付きリクエスト
curl -X POST "https://direct.reachapi.ai/v1/chat/completions" -H "Authorization: Bearer YOUR_REACH_API_KEY" -H "Content-Type: application/json" -d '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Help me check the weather in Shanghai."
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}'5. 正常レスポンス
非ストリーミングレスポンスの例:
{
"id": "chatcmpl_123",
"object": "chat.completion",
"created": 1710000000,
"model": "YOUR_MODEL_ID",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello, I am a model-powered assistant."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 18,
"total_tokens": 30
}
}6. ストリーミングレスポンス
stream = true の場合、OpenAI 形式の SSE イベントが返ります。
data: {"id":"chatcmpl_123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}
data: {"id":"chatcmpl_123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"}}]}
data: [DONE]7. エラーレスポンス
OpenAI 互換のエラー例:
{
"error": {
"message": "Field `messages` is required",
"type": "invalid_request_error",
"param": null,
"code": "MISSING_REQUIRED_FIELD"
}
}代表的なエラーケース:
- リクエストボディに
modelがない - リクエストボディに
messagesがない - JSON ペイロードが不正
- 認証に失敗した
8. 互換性に関する注意
- このドキュメントでは、よく使われるフィールドと代表的なペイロードのみを掲載しています。実際のフィールド名や構造は OpenAI Chat Completions API に従います。
- このエンドポイントは Chat Completions のパスのみを対象としており、OpenAI API 全体を表すものではありません。
- 新しいフィールドや実験的フィールドを使う場合は、接続先ゲートウェイで実際に利用可能か確認してください。
9. 対応モデルと参考価格
以下の価格は統一価格ドキュメントをもとに整理したもので、現在掲載している GPT 系テキストモデルに適用されます。価格確認日は 2026-04-17 です。詳細な価格ルールは gpt.md を参照してください。
| Model | Input | Cached input | Output |
|---|---|---|---|
gpt-5.4 | $2.50 / 1M tokens | $0.25 / 1M tokens | $15.00 / 1M tokens |
gpt-5.3-codex | $1.75 / 1M tokens | $0.175 / 1M tokens | $14.00 / 1M tokens |
gpt-5.2 | $1.75 / 1M tokens | $0.175 / 1M tokens | $14.00 / 1M tokens |
gpt-5.1-codex | $1.25 / 1M tokens | $0.125 / 1M tokens | $10.00 / 1M tokens |
gpt-5.1 | $1.25 / 1M tokens | $0.125 / 1M tokens | $10.00 / 1M tokens |
gpt-5 | $1.25 / 1M tokens | $0.125 / 1M tokens | $10.00 / 1M tokens |
gpt-5.4-mini | $0.75 / 1M tokens | $0.075 / 1M tokens | $4.50 / 1M tokens |
gpt-5-mini | $0.25 / 1M tokens | $0.025 / 1M tokens | $2.00 / 1M tokens |
補足:
Cached inputは、キャッシュヒットした入力トークンの単価です- 有効モデルの一覧は将来変わる可能性があるため、現在有効なモデルはダッシュボードまたは商品設定を正としてください
10. 参考資料
- OpenAI Chat Completions API: https://platform.openai.com/docs/api-reference/chat/create
- OpenAI text generation guide: https://platform.openai.com/docs/guides/text?api-mode=chat
- OpenAI API errors: https://platform.openai.com/docs/guides/error-codes/api-errors
- Unified platform pricing document:
gpt.md