Skip to main content
POST
CometAPI merutekan Chat Completions ke beberapa penyedia — termasuk OpenAI, Claude, dan Gemini — melalui satu antarmuka yang kompatibel dengan OpenAI. Beralihlah antar-model dengan mengubah parameter model; sebagian besar SDK yang kompatibel dengan OpenAI berfungsi dengan menetapkan base_url ke https://api.cometapi.com/v1.
Parameter permintaan dan field respons dapat sangat bervariasi antarpenyedia model. Periksa dokumentasi resmi penyedia di balik model yang Anda gunakan setiap kali Anda memerlukan daftar parameter lengkap atau perilaku khusus penyedia. Misalnya, reasoning_effort hanya berlaku untuk model reasoning (o-series, GPT-5.1+), dan beberapa model tidak mendukung logprobs atau n > 1.
Untuk model OpenAI Pro, model reasoning o-series, dan model Codex, gunakan endpoint Responses sebagai gantinya. Keluarga model ini memiliki dukungan yang lebih lengkap pada Responses API.

Peran pesan

Untuk model yang lebih baru (GPT-4.1, seri GPT-5, o-series), utamakan developer daripada system untuk pesan instruksi. Keduanya berfungsi, tetapi developer memberikan perilaku mengikuti instruksi yang lebih kuat.

Kirim input multimodal

Banyak model mendukung gambar dan audio bersama teks. Untuk mengirim pesan multimodal, gunakan format array untuk content:
Parameter detail mengontrol kedalaman analisis gambar:
  • low — lebih cepat, menggunakan lebih sedikit token (biaya tetap)
  • high — analisis mendetail, lebih banyak token digunakan
  • auto — model yang menentukan (default)

Stream respons

Untuk menerima output bertahap, tetapkan stream ke true. Respons dikirimkan sebagai Server-Sent Events (SSE), dengan setiap event berisi objek chat.completion.chunk:
Untuk menyertakan statistik penggunaan token dalam respons streaming, tetapkan stream_options.include_usage ke true. Data penggunaan muncul dalam chunk terakhir sebelum [DONE].

Minta output terstruktur

Untuk memaksa model mengembalikan JSON valid yang sesuai dengan schema tertentu, gunakan response_format:
Mode JSON Schema (json_schema) menjamin output sepenuhnya sesuai dengan schema Anda. Mode JSON Object (json_object) hanya menjamin JSON yang valid — strukturnya tidak dipaksakan.

Panggil tool dan function

Untuk mengaktifkan model agar dapat memanggil function eksternal, berikan definisi tool:
Saat model memutuskan untuk memanggil tool, respons akan memiliki finish_reason: "tool_calls" dan array message.tool_calls akan berisi nama function serta argumen. Kemudian, eksekusi function tersebut dan kirim kembali hasilnya sebagai pesan tool dengan tool_call_id yang cocok.

Catatan lintas penyedia

  • max_tokens — Parameter lama. Berfungsi dengan sebagian besar model, tetapi tidak lagi direkomendasikan untuk model OpenAI yang lebih baru.
  • max_completion_tokens — Parameter yang direkomendasikan untuk model GPT-4.1, seri GPT-5, dan model o-series. Diperlukan untuk model reasoning karena mencakup token output dan token reasoning.
CometAPI secara otomatis menangani pemetaan saat merutekan ke penyedia yang berbeda.
  • system — Peran instruksi tradisional. Berfungsi dengan semua model.
  • developer — Diperkenalkan bersama model o1. Memberikan kemampuan mengikuti instruksi yang lebih kuat untuk model yang lebih baru. Kembali ke perilaku system pada model yang lebih lama.
Gunakan developer untuk proyek baru yang menargetkan model GPT-4.1+ atau o-series.

FAQ

Bagaimana menangani rate limit?

Saat mengalami 429 Too Many Requests, terapkan exponential backoff:

Bagaimana mempertahankan konteks percakapan?

Sertakan seluruh riwayat percakapan dalam array messages:

Apa arti finish_reason ?

Bagaimana mengontrol biaya?

  1. Gunakan max_completion_tokens untuk membatasi panjang output.
  2. Gunakan gpt-5.6-terra untuk keseimbangan antara kecerdasan dan biaya, atau gpt-5.6-luna untuk beban kerja efisien berkapasitas tinggi.
  3. Jaga prompt tetap ringkas — hindari konteks yang berlebihan.
  4. Pantau penggunaan token di field respons usage.

Otorisasi

Authorization
string
header
wajib

Bearer token authentication. Use your CometAPI key.

Body

application/json
model
string
default:gpt-5.6-sol
wajib

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

Contoh:

"gpt-4.1"

messages
object[]
wajib

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
default: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.

Rentang yang diperlukan: 0 <= x <= 2
top_p
number
default: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.

Rentang yang diperlukan: 0 <= x <= 1
n
integer
default: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
default: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.

Rentang yang diperlukan: -2 <= x <= 2
frequency_penalty
number
default:0

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

Rentang yang diperlukan: -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
default:auto

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

logprobs
boolean
default: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.

Rentang yang diperlukan: 0 <= x <= 20
reasoning_effort
enum<string>

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

Opsi yang tersedia:
low,
medium,
high
stream_options
object

Options for streaming. Only valid when stream is true.

service_tier
enum<string>

Specifies the processing tier.

Opsi yang tersedia:
auto,
default,
flex,
priority

Respons

Successful chat completion response.

id
string

Unique completion identifier.

Contoh:

"chatcmpl-abc123"

object
enum<string>

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

Opsi yang tersedia:
chat.completion
Contoh:

"chat.completion"

created
integer

Unix timestamp of creation.

Contoh:

1774412483

model
string

The model used (may include version suffix).

Contoh:

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

Contoh:

"default"

system_fingerprint
string | null

Provider backend configuration fingerprint, when the provider reports one.

Contoh:

"fp_490a4ad033"