チャット補完
CometAPI の POST /v1/chat/completions を使用して複数メッセージの会話を送信し、ストリーミング、temperature、max_tokens の制御付きで LLM の応答を取得します。
CometAPI は、OpenAI、Claude、Gemini を含む複数のプロバイダーに対して、単一の OpenAI 互換インターフェースを通じてチャット補完をルーティングします。Documentation Index
Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
Use this file to discover all available pages before exploring further.
model パラメータを変更することでモデルを切り替えられます。ほとんどの OpenAI 互換 SDK は、base_url を https://api.cometapi.com/v1 に設定することで利用できます。
メッセージの役割
| Role | Description |
|---|---|
system | アシスタントの動作と性格を設定します。会話の先頭に配置されます。 |
developer | 新しいモデル(o1+)では system の代わりになります。ユーザー入力に関係なくモデルが従うべき指示を提供します。 |
user | エンドユーザーからのメッセージです。 |
assistant | 会話履歴を維持するために使用される、以前のモデル応答です。 |
tool | ツール/関数呼び出しの結果です。元のツール呼び出しに一致する tool_call_id を含める必要があります。 |
マルチモーダル(Multimodal)入力を送信する
多くのモデルは、テキストに加えて画像や音声もサポートしています。マルチモーダルメッセージを送信するには、content に配列形式を使用します。
detail パラメータは画像解析の深さを制御します。
low— 高速で、使用するトークン数が少ない(固定コスト)high— 詳細な解析で、より多くのトークンを消費auto— モデルが決定(デフォルト)
レスポンスをストリーミング(Streaming)する
増分出力を受け取るには、stream を true に設定します。レスポンスは Server-Sent Events (SSE) として配信され、各イベントには chat.completion.chunk オブジェクトが含まれます。
構造化出力をリクエストする
特定のスキーマに一致する有効な JSON をモデルに必ず返させるには、response_format を使用します:
json_schema)は、出力がスキーマに正確に一致することを保証します。JSON Object モード(json_object)は、有効な JSON であることのみを保証し、構造までは強制しません。ツールと関数を呼び出す
モデルが外部関数を呼び出せるようにするには、ツール定義を指定します:finish_reason: "tool_calls" が含まれ、message.tool_calls 配列には関数名と引数が格納されます。次に、その関数を実行し、対応する tool_call_id を持つ tool メッセージとして結果を返します。
プロバイダー間の注意事項
プロバイダー間でのパラメータ対応状況
プロバイダー間でのパラメータ対応状況
| Parameter | OpenAI GPT | Claude (via compat) | Gemini (via compat) |
|---|---|---|---|
temperature | 0–2 | 0–1 | 0–2 |
top_p | 0–1 | 0–1 | 0–1 |
n | 1–128 | 1 のみ | 1–8 |
stop | 最大 4 | 最大 4 | 最大 5 |
tools | ✅ | ✅ | ✅ |
response_format | ✅ | ✅ (json_schema) | ✅ |
logprobs | ✅ | ❌ | ❌ |
reasoning_effort | o-series, GPT-5.1+ | ❌ | ❌(Gemini ネイティブでは thinking を使用) |
max_tokens と max_completion_tokens の違い
max_tokens と max_completion_tokens の違い
max_tokens— 従来のパラメータです。ほとんどのモデルで動作しますが、新しい OpenAI モデルでは非推奨です。max_completion_tokens— GPT-4.1、GPT-5 シリーズ、および o-series モデルで推奨されるパラメータです。出力トークンと推論トークンの両方を含むため、reasoning モデルでは必須です。
system と developer role の違い
system と developer role の違い
system— 従来の instruction role です。すべてのモデルで動作します。developer— o1 モデルで導入されました。新しいモデルでは、より強力な指示追従を提供します。古いモデルではsystemと同様の動作にフォールバックします。
developer を使用してください。FAQ
レート制限はどのように処理すればよいですか?
429 Too Many Requests が発生した場合は、指数バックオフを実装します。
会話コンテキストはどのように維持すればよいですか?
会話履歴全体をmessages 配列に含めます。
finish_reason は何を意味しますか?
| Value | 意味 |
|---|---|
stop | 自然に完了したか、stop sequence に到達しました。 |
length | max_tokens または max_completion_tokens の上限に達しました。 |
tool_calls | モデルが1つ以上のツール/関数呼び出しを実行しました。 |
content_filter | コンテンツポリシーにより出力がフィルタリングされました。 |
コストはどのように管理すればよいですか?
- 出力長を制限するために
max_completion_tokensを使用します。 - コスト効率の高いモデルを選択します(例: より単純なタスクには
gpt-5.4-miniまたはgpt-5.4-nano)。 - プロンプト(Prompt)は簡潔に保ち、冗長なコンテキストは避けます。
usageレスポンスフィールドでトークン(Token)の使用量を監視します。
承認
Bearer token authentication. Use your CometAPI key.
ボディ
Model ID to use for this request. See the Models page for current options.
"gpt-4.1"
A list of messages forming the conversation. Each message has a role (system, user, assistant, or developer) and content (text string or multimodal content array).
If true, partial response tokens are delivered incrementally via server-sent events (SSE). The stream ends with a data: [DONE] message.
Sampling temperature between 0 and 2. Higher values (e.g., 0.8) produce more random output; lower values (e.g., 0.2) make output more focused and deterministic. Recommended to adjust this or top_p, but not both.
0 <= x <= 2Nucleus sampling parameter. The model considers only the tokens whose cumulative probability reaches top_p. For example, 0.1 means only the top 10% probability tokens are considered. Recommended to adjust this or temperature, but not both.
0 <= x <= 1Number of completion choices to generate for each input message. Defaults to 1.
Up to 4 sequences where the API will stop generating further tokens. Can be a string or an array of strings.
Maximum number of tokens to generate in the completion. The total of input + output tokens is capped by the model's context length.
Number between -2.0 and 2.0. Positive values penalize tokens based on whether they have already appeared, encouraging the model to explore new topics.
-2 <= x <= 2Number between -2.0 and 2.0. Positive values penalize tokens proportionally to how often they have appeared, reducing verbatim repetition.
-2 <= x <= 2A JSON object mapping token IDs to bias values from -100 to 100. The bias is added to the model's logits before sampling. Values between -1 and 1 subtly adjust likelihood; -100 or 100 effectively ban or force selection of a token.
A unique identifier for your end-user. Helps with abuse detection and monitoring.
An upper bound for the number of tokens to generate, including visible output tokens and reasoning tokens. Use this instead of max_tokens for GPT-4.1+, GPT-5 series, and o-series models.
Specifies the output format. Use {"type": "json_object"} for JSON mode, or {"type": "json_schema", "json_schema": {...}} for strict structured output.
A list of tools the model may call. Currently supports function type tools.
Controls how the model selects tools. auto (default): model decides. none: no tools. required: must call a tool.
Whether to return log probabilities of the output tokens.
Number of most likely tokens to return at each position (0-20). Requires logprobs to be true.
0 <= x <= 20Controls the reasoning effort for o-series and GPT-5.1+ models.
low, medium, high Options for streaming. Only valid when stream is true.
Specifies the processing tier.
auto, default, flex, priority レスポンス
Successful chat completion response.
Unique completion identifier.
"chatcmpl-abc123"
chat.completion "chat.completion"
Unix timestamp of creation.
1774412483
The model used (may include version suffix).
"gpt-5.4-2025-07-16"
Array of completion choices.
"default"
"fp_490a4ad033"