채팅 완성 생성
CometAPI POST /v1/chat/completions를 사용하여 스트리밍(Streaming), 구조화된 출력 및 함수 호출(Function Calling)을 지원하는 채팅 모델에 여러 메시지로 이루어진 대화를 전송하세요.
base_url="https://api.cometapi.com/v1" 및 CometAPI API 키로 구성하세요.
기본, 이미지, 스트리밍(Streaming), 구조화된 출력 예제에서는 gpt-6-astra를 사용합니다. 함수 호출(Function Calling) 예제에서는 gpt-5.6-sol를 사용하고, 로그 확률 예제에서는 gpt-4.1를 사용합니다.
메시지 역할
멀티모달(Multimodal) 입력 전송
텍스트와 함께 이미지를 전송하려면 콘텐츠 부분 배열을 사용하세요:image_url.detail을 사용하세요. 이 예에서는 high 값을 사용합니다.
응답 스트리밍
증분 출력을 받으려면stream을 true로 설정하세요. 응답은 다음 방식으로 전달됩니다 서버 전송 이벤트(SSE). 텍스트는 chat.completion.chunk 객체로 도착하며, 이 축약된 예제에는 최종 사용량 청크가 포함되어 있습니다:
구조화된 출력 요청
구조화된 출력을 요청하려면response_format을 사용하세요:
도구 및 함수 호출
함수 정의와 함께gpt-5.6-sol을 사용하세요:
finish_reason: "tool_calls" 및 message.tool_calls 배열을 반환합니다. 함수의 JSON으로 인코딩된 arguments를 파싱하고 함수를 실행한 다음, 어시스턴트 메시지와 일치하는 tool를 포함한 tool_call_id 결과 메시지를 추가하세요.
요청 파라미터 선택
모델별 파라미터
모델별 파라미터
reasoning_effort 및 max_completion_tokens을 사용하세요. Functions 및 Logprobs 예제에서는 각각 GPT-6 및 gpt-5.6-sol에 대한 요청 옵션을 보여 줍니다. gpt-4.1Claude 또는 Gemini 전용 요청 형식은 다음을 참조하세요 Anthropic 메시지 및 Gemini 콘텐츠 생성.max_tokens 및 max_completion_tokens
max_tokens 및 max_completion_tokens
max_completion_tokens을 사용하세요. 여기에는 추론과 표시되는 출력이 포함되므로 둘 모두를 위한 여유를 확보하세요. GPT-6 max_tokens은 레거시 파라미터입니다.지침 역할
지침 역할
developer을 사용하세요. 최종 사용자 콘텐츠는 GPT-6 user 메시지에 유지하고, 대화를 계속할 때는 이전 어시스턴트 응답을 보존하세요.자주 묻는 질문
속도 제한을 처리하는 방법은 무엇인가요?
429 Too Many Requests 발생 시 지수 백오프를 구현하세요:
대화 컨텍스트를 유지하는 방법은 무엇인가요?
전체 대화 기록을messages 배열에 포함하세요:
finish_reason의 의미는 무엇인가요?
비용을 제어하는 방법은 무엇인가요?
- 출력 길이를 제한하려면
max_completion_tokens을 사용하세요. - 모델 가격을 비교하고 워크로드 요구 사항에 맞는 모델을 선택하세요.
- 프롬프트(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-6-astra"
Conversation messages, including instructions, user input, assistant replies, and tool results.
If true, partial response tokens are delivered incrementally via server-sent events (SSE). The stream ends with a data: [DONE] message.
Sampling temperature. Omit this field for GPT-6 Astra.
0 <= x <= 2Nucleus sampling threshold. Omit this field for GPT-6 Astra. For sampling overrides, adjust either top_p or temperature.
0 <= x <= 1Number of completion choices to generate for each input message. Defaults to 1.
Stop string or list of up to four strings, for models that support stop sequences.
Legacy output-token limit. Use max_completion_tokens for the GPT-6 Astra examples.
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.
Maximum generated tokens, including visible output and reasoning. Leave enough room for both, as in the image-input example.
Specifies the output format. Use {"type": "json_object"} for JSON mode, or {"type": "json_schema", "json_schema": {...}} for strict structured output.
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.
Controls how the model selects tools. auto (default): model decides. none: no tools. required: must call a tool.
Return token log probabilities. Use gpt-4.1 as shown in the Logprobs example.
Number of most likely tokens to return at each position (0-20). Requires logprobs to be true.
0 <= x <= 20Reasoning 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.
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_example"
Object type. Non-streaming responses use chat.completion.
chat.completion "chat.completion"
Unix timestamp of creation.
1788763703
The model used (may include version suffix).
"gpt-6-astra"
Array of completion choices.
Token accounting for this request. Billing uses these counts.
Service tier that processed the request, when returned.
Model configuration fingerprint, when returned.