Skip to main content
POST
OpenAI 互換のチャット補完 API を通じて会話を送信します。SDK を base_url="https://api.cometapi.com/v1" と CometAPI API キーで設定します。 基本、画像、ストリーミング、構造化出力の例では gpt-6-astra を使用します。関数呼び出しの例では gpt-5.6-sol を、対数確率の例では gpt-4.1 を使用します。
パラメータ定義については、 OpenAI チャット補完リファレンス を参照してください。GPT-6 Astra のツール呼び出しには、 レスポンスを使用し、 OpenAI モデルガイダンス.

に従ってください。

developer Astra の例を使用する場合は、ユーザーメッセージの前に GPT-6 メッセージとしてアプリケーションの指示を配置します。

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

コンテンツパートの配列を使用して、テキストとともに画像を送信します。
画像処理の詳細を選択するには image_url.detail を使用します。この例では high を使用します。

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

増分出力を受け取るには、streamtrue に設定します。レスポンスは次の形式で配信されます Server-Sent Events(SSE)。テキストは chat.completion.chunk オブジェクトで届きます。この短縮された例には、最終的な使用量チャンクが含まれています:
ストリーミング(Streaming)レスポンスにトークン使用量統計を含めるには、stream_options.include_usagetrue に設定します。使用量データは [DONE] の前の最終チャンクに表示されます。チャンクの choices 配列は空の場合があるため、choices[0] にアクセスする前に確認してください。

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

構造化出力をリクエストするには、response_format を使用します:
JSON Schema モードでは必要な構造を指定します。JSON Object モードでは、スキーマを強制せずに有効な JSON をリクエストします。結果を使用する前に、拒否または長さ制限されたレスポンスがないか確認してください。

ツールと関数を呼び出す

関数定義とともに gpt-5.6-sol を使用します:
関数呼び出しでは、finish_reason: "tool_calls"message.tool_calls 配列が返されます。関数の JSON エンコード済みの arguments を解析し、関数を実行してから、assistant メッセージと、一致する tool を持つ tool_call_id 結果メッセージを追加します。

リクエストパラメータを選択する

Astra では reasoning_effortmax_completion_tokens を使用します。Functions と Logprobs の例では、それぞれ GPT-6、gpt-5.6-solgpt-4.1 のリクエストオプションを示しています。Claude または Gemini 固有のリクエスト形式については、次を参照してください Anthropic メッセージ および Gemini コンテンツ生成.
max_completion_tokens を使用して、GPT-6 Astra の例で生成されるトークン(Token)を制限します。これには推論と表示される出力が含まれるため、両方のための余裕を確保してください。max_tokens はレガシーパラメータです。
developer を GPT-6 Astra の例におけるアプリケーション指示に使用します。エンドユーザーのコンテンツは user メッセージに保持し、会話を継続する場合は以前の assistant の応答を維持してください。

よくある質問

レート制限にはどのように対処しますか?

429 Too Many Requests が発生した場合は、指数バックオフを実装します:

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

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

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

コストを管理するには?

  1. max_completion_tokens を使用して出力長を制限します。
  2. モデルの価格を比較し、ワークロード要件を満たすモデルを選択します。
  3. プロンプト(Prompt)を簡潔に保ち、冗長なコンテキストを避けます。
  4. usage レスポンスフィールドでトークン(Token)の使用量を監視します。

承認

Authorization
string
header
必須

Bearer token authentication. Use your CometAPI key.

ボディ

application/json
model
string
デフォルト:gpt-6-astra
必須

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

:

"gpt-6-astra"

messages
object[]
必須

Conversation messages, including instructions, user input, assistant replies, and tool results.

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

Sampling temperature. Omit this field for GPT-6 Astra.

必須範囲: 0 <= x <= 2
top_p
number

Nucleus sampling threshold. Omit this field for GPT-6 Astra. For sampling overrides, adjust either top_p or temperature.

必須範囲: 0 <= x <= 1
n
integer

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

stop

Stop string or list of up to four strings, for models that support stop sequences.

max_tokens
integer
非推奨

Legacy output-token limit. Use max_completion_tokens for the GPT-6 Astra examples.

presence_penalty
number

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

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

Maximum generated tokens, including visible output and reasoning. Leave enough room for both, as in the image-input example.

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[]

Function definitions for a model that supports tool calling on Chat Completions. The function example uses GPT-5.6 Sol; use Responses for GPT-6 Astra tool calls.

tool_choice

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

logprobs
boolean

Return token log probabilities. Use gpt-4.1 as shown in the Logprobs example.

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
string

Reasoning effort supported by the selected model. The GPT-6 Astra examples use low; the GPT-5.6 Sol function example uses none. See the model reference for other supported levels.

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_example"

object
enum<string>

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

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

"chat.completion"

created
integer

Unix timestamp of creation.

:

1788763703

model
string

The model used (may include version suffix).

:

"gpt-6-astra"

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

system_fingerprint
string | null

Model configuration fingerprint, when returned.

最終更新日 2026年9月8日