채팅 완성
CometAPI POST /v1/chat/completions를 사용해 여러 메시지로 이루어진 대화를 전송하고 스트리밍, temperature, max_tokens 제어와 함께 LLM 응답을 받을 수 있습니다.
CometAPI는 단일 OpenAI 호환 인터페이스를 통해 Chat Completions를 OpenAI, Claude, Gemini를 포함한 여러 provider로 라우팅합니다.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로 설정하면 동작합니다.
메시지 역할
| 역할 | 설명 |
|---|---|
system | assistant의 동작과 성격을 설정합니다. 대화 시작 부분에 배치됩니다. |
developer | 최신 모델(o1+)에서는 system을 대체합니다. 사용자 입력과 관계없이 모델이 따라야 하는 지침을 제공합니다. |
user | 최종 사용자로부터 온 메시지입니다. |
assistant | 이전 모델 응답으로, 대화 기록을 유지하는 데 사용됩니다. |
tool | tool/function 호출의 결과입니다. 원래 tool 호출과 일치하는 tool_call_id를 반드시 포함해야 합니다. |
멀티모달 입력 보내기
많은 모델은 텍스트와 함께 이미지와 오디오를 지원합니다. 멀티모달 메시지를 보내려면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만 보장하며, 구조는 강제되지 않습니다.도구와 함수 호출
모델이 외부 함수를 호출할 수 있도록 하려면 tool 정의를 제공하세요:finish_reason: "tool_calls"가 포함되고, message.tool_calls 배열에 함수 이름과 인수가 들어 있습니다. 그런 다음 함수를 실행하고, 일치하는 tool_call_id와 함께 결과를 tool 메시지로 다시 보내면 됩니다.
공급자 간 참고 사항
공급자별 parameter 지원
공급자별 parameter 지원
| 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+ | ❌ | ❌ (thinking 사용, Gemini 네이티브) |
max_tokens vs max_completion_tokens
max_tokens vs max_completion_tokens
max_tokens— 레거시 parameter입니다. 대부분의 모델에서 작동하지만, 최신 OpenAI 모델에서는 deprecated 되었습니다.max_completion_tokens— GPT-4.1, GPT-5 시리즈 및 o-series 모델에 권장되는 parameter입니다. 출력 토큰과 reasoning 토큰을 모두 포함하므로 reasoning 모델에는 필수입니다.
system vs developer role
system vs developer role
system— 전통적인 instruction role입니다. 모든 모델에서 작동합니다.developer— o1 모델과 함께 도입되었습니다. 최신 모델에서 더 강한 instruction-following을 제공합니다. 구형 모델에서는system동작으로 대체됩니다.
developer를 사용하세요.FAQ
rate limit은 어떻게 처리하나요?
429 Too Many Requests가 발생하면 지수 백오프를 구현하세요:
대화 컨텍스트는 어떻게 유지하나요?
messages 배열에 전체 대화 기록을 포함하세요:
finish_reason는 무엇을 의미하나요?
| 값 | 의미 |
|---|---|
stop | 자연스럽게 완료되었거나 중지 시퀀스에 도달했습니다. |
length | max_tokens 또는 max_completion_tokens 한도에 도달했습니다. |
tool_calls | 모델이 하나 이상의 tool/function 호출을 실행했습니다. |
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"