Skip to main content
POST
CometAPI は、OpenAI、Claude、Gemini などのチャット補完を、単一の OpenAI 互換インターフェースを通じて複数のプロバイダーにルーティングします。model パラメータを変更してモデルを切り替えます。ほとんどの OpenAI 互換 SDK は、base_urlhttps://api.cometapi.com/v1 に設定することで使用できます。
リクエストパラメータとレスポンスフィールドは、モデルプロバイダーによって大きく異なる場合があります。完全なパラメータ一覧やプロバイダー固有の動作が必要な場合は、使用するモデルの提供元の公式ドキュメントを確認してください。たとえば、reasoning_effort は推論モデル(o-series、GPT-5.1+)にのみ適用され、一部のモデルは logprobs または n > 1 をサポートしていません。
OpenAI Pro モデル、o-series 推論モデル、および Codex モデルでは、 レスポンス エンドポイントを代わりに使用してください。これらのモデルファミリーは、Responses API でより完全にサポートされています。

メッセージのロール

新しいモデル(GPT-4.1、GPT-5 シリーズ、o-series)では、指示メッセージに system ではなく developer を使用することを推奨します。どちらも使用できますが、developer のほうがより強力な指示追従動作を提供します。

マルチモーダル入力を送信する

多くのモデルは、テキストに加えて画像と音声をサポートしています。マルチモーダルメッセージを送信するには、content に配列形式を使用します。
detail パラメータは画像分析の詳細度を制御します。
  • low — より高速で、使用トークン数が少ない(固定コスト)
  • high — 詳細な分析で、より多くのトークンを消費
  • auto — モデルが決定(デフォルト)

レスポンスをストリーミングする

段階的な出力を受け取るには、streamtrue に設定します。レスポンスは Server-Sent Events(SSE))として配信され、各イベントには chat.completion.chunk オブジェクトが含まれます。
ストリーミングレスポンスにトークン使用量の統計を含めるには、stream_options.include_usagetrue に設定します。使用量データは、[DONE] の前の最後のチャンクに表示されます。

構造化出力をリクエストする

特定のスキーマに一致する有効な JSON をモデルに返させるには、response_format を使用します。
JSON Schema モード(json_schema)では、出力がスキーマに完全に一致することが保証されます。JSON Object モード(json_object)では有効な JSON のみが保証され、構造は強制されません。

ツールと関数を呼び出す

モデルが外部関数を呼び出せるようにするには、ツール定義を指定します。
モデルがツールを呼び出すと判断した場合、レスポンスには finish_reason: "tool_calls" が含まれ、message.tool_calls 配列には関数名と引数が格納されます。次に関数を実行し、一致する tool_call_id を含む tool メッセージとして結果を送り返します。

プロバイダー間の注意事項

  • max_tokens — 従来のパラメータです。ほとんどのモデルで動作しますが、新しい OpenAI モデルでは非推奨です。
  • max_completion_tokens — GPT-4.1、GPT-5 シリーズ、および o-series モデルに推奨されるパラメータです。出力トークンと推論トークンの両方を含むため、推論モデルでは必須です。
CometAPI は、異なるプロバイダーへのルーティング時にマッピングを自動的に処理します。
  • system — 従来の指示用ロールです。すべてのモデルで動作します。
  • developer — o1 モデルで導入されました。新しいモデルに対してより強力な指示追従を提供します。古いモデルでは system の動作にフォールバックします。
GPT-4.1+ または o-series モデルを対象とする新規プロジェクトでは、developer を使用してください。

よくある質問

レート制限を処理するには?

429 Too Many Requests が発生した場合は、指数バックオフを実装してください。

会話コンテキストを維持するには?

会話履歴全体を messages 配列に含めます。

finish_reason とは何を意味しますか?

コストを管理するには?

  1. 出力長を制限するには max_completion_tokens を使用します。
  2. 知能とコストのバランスには gpt-5.6-terra を使用し、効率的な大量ワークロードには gpt-5.6-luna を使用します。
  3. プロンプトは簡潔にし、重複したコンテキストを避けてください。
  4. usage レスポンスフィールドでトークン使用量を監視します。

承認

Authorization
string
header
必須

Bearer token authentication. Use your CometAPI key.

ボディ

application/json
model
string
デフォルト:gpt-5.6-sol
必須

Model ID to use for this request. See the Models page for current options.

:

"gpt-4.1"

messages
object[]
必須

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).

stream
boolean

If true, partial response tokens are delivered incrementally via server-sent events (SSE). The stream ends with a data: [DONE] message.

temperature
number
デフォルト:1

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 <= 2
top_p
number
デフォルト:1

Nucleus 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 <= 1
n
integer
デフォルト:1

Number of completion choices to generate for each input message. Defaults to 1.

stop
string

Up to 4 sequences where the API will stop generating further tokens. Can be a string or an array of strings.

max_tokens
integer

Maximum number of tokens to generate in the completion. The total of input + output tokens is capped by the model's context length.

presence_penalty
number
デフォルト:0

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 <= 2
frequency_penalty
number
デフォルト:0

Number between -2.0 and 2.0. Positive values penalize tokens proportionally to how often they have appeared, reducing verbatim repetition.

必須範囲: -2 <= x <= 2
logit_bias
object

A 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.

user
string

A unique identifier for your end-user. Helps with abuse detection and monitoring.

max_completion_tokens
integer

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.

response_format
object

Specifies the output format. Use {"type": "json_object"} for JSON mode, or {"type": "json_schema", "json_schema": {...}} for strict structured output.

tools
object[]

A list of tools the model may call. Currently supports function type tools.

tool_choice
デフォルト:auto

Controls how the model selects tools. auto (default): model decides. none: no tools. required: must call a tool.

logprobs
boolean
デフォルト:false

Whether to return log probabilities of the output tokens.

top_logprobs
integer

Number of most likely tokens to return at each position (0-20). Requires logprobs to be true.

必須範囲: 0 <= x <= 20
reasoning_effort
enum<string>

Controls the reasoning effort for o-series and GPT-5.1+ models.

利用可能なオプション:
low,
medium,
high
stream_options
object

Options for streaming. Only valid when stream is true.

service_tier
enum<string>

Specifies the processing tier.

利用可能なオプション:
auto,
default,
flex,
priority

レスポンス

Successful chat completion response.

id
string

Unique completion identifier.

:

"chatcmpl-abc123"

object
enum<string>

Object type. Non-streaming responses use chat.completion.

利用可能なオプション:
chat.completion
:

"chat.completion"

created
integer

Unix timestamp of creation.

:

1774412483

model
string

The model used (may include version suffix).

:

"gpt-5.4-2026-03-05"

choices
object[]

Array of completion choices.

usage
object

Token accounting for this request. Billing uses these counts.

service_tier
string

Service tier that processed the request, when the provider reports one.

:

"default"

system_fingerprint
string | null

Provider backend configuration fingerprint, when the provider reports one.

:

"fp_490a4ad033"