Skip to main content
POST
Send conversations through the OpenAI-compatible Chat Completions API. Configure your SDK with base_url="https://api.cometapi.com/v1" and your CometAPI API key. The basic, image, streaming, and structured-output examples use gpt-6-astra. The function-calling example uses gpt-5.6-sol, and the log-probability example uses gpt-4.1.
Use the OpenAI Chat Completions reference for parameter definitions. For GPT-6 Astra tool calling, use Responses, following the OpenAI model guidance.

Message roles

Place application instructions in a developer message before user messages when using the GPT-6 Astra examples.

Send multimodal input

Use an array of content parts to send an image with text:
Use image_url.detail to select image processing detail. This example uses high.

Stream responses

To receive incremental output, set stream to true. The response is delivered as Server-Sent Events (SSE). Text arrives in chat.completion.chunk objects; this abbreviated example includes the final usage chunk:
To include token usage statistics in streaming responses, set stream_options.include_usage to true. The usage data appears in a final chunk before [DONE]. Chunks can have an empty choices array; check it before accessing choices[0].

Request structured output

Use response_format to request structured output:
JSON Schema mode specifies the required structure. JSON Object mode requests valid JSON without enforcing your schema. Check for a refusal or a length-limited response before consuming the result.

Call tools and functions

Use gpt-5.6-sol with a function definition:
A function call returns finish_reason: "tool_calls" and a message.tool_calls array. Parse the function’s JSON-encoded arguments, execute your function, then append the assistant message and a tool result message with its matching tool_call_id.

Choose request parameters

Use reasoning_effort and max_completion_tokens with GPT-6 Astra. The Functions and Logprobs examples show the request options for gpt-5.6-sol and gpt-4.1, respectively.For Claude- or Gemini-specific request formats, see Anthropic Messages and Gemini Generate content.
Use max_completion_tokens to limit generated tokens for the GPT-6 Astra examples. This includes reasoning and visible output, so allow room for both. max_tokens is a legacy parameter.
Use developer for application instructions in the GPT-6 Astra examples. Keep end-user content in user messages and preserve previous assistant replies when continuing a conversation.

FAQ

How to handle rate limits?

When encountering 429 Too Many Requests, implement exponential backoff:

How to maintain conversation context?

Include the full conversation history in the messages array:

What does finish_reason mean?

How to control costs?

  1. Use max_completion_tokens to cap output length.
  2. Compare model pricing and choose a model that meets your workload requirements.
  3. Keep prompts concise — avoid redundant context.
  4. Monitor token usage in the usage response field.

Authorizations

Authorization
string
header
required

Bearer token authentication. Use your CometAPI key.

Body

application/json
model
string
default:gpt-6-astra
required

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

Example:

"gpt-6-astra"

messages
object[]
required

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.

Required range: 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.

Required range: 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
deprecated

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.

Required range: -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.

Required range: -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.

Required range: 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.

Available options:
auto,
default,
flex,
priority

Response

Successful chat completion response.

id
string

Unique completion identifier.

Example:

"chatcmpl_example"

object
enum<string>

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

Available options:
chat.completion
Example:

"chat.completion"

created
integer

Unix timestamp of creation.

Example:

1788763703

model
string

The model used (may include version suffix).

Example:

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

Last modified on September 7, 2026