채팅 완료
POST /v1/chat/completions 요청 및 응답.
채팅 완료
요청
POST https://apimaster.ai/v1/chat/completions
헤더
| 헤더 | 필수 | 비고 |
|---|---|---|
Authorization |
예 | Bearer YOUR_API_KEY |
Content-Type |
예 | application/json |
본문 (공통 필드)
| 필드 | 타입 | 비고 |
|---|---|---|
model |
string | 예: claude-sonnet-4-6 |
messages |
array | {role, content} |
max_tokens |
number | 최대 완료 토큰 수 |
temperature |
number | 선택 사항 |
stream |
boolean | SSE 스트리밍 |
예시
curl -s "https://apimaster.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "You are helpful."},
{"role": "user", "content": "Say hi in one word."}
],
"max_tokens": 64
}'
비스트리밍 응답
{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}
스트리밍
"stream": true를 사용하면 본문은 text/event-stream이며, 라인은 data: {json} 형태로 data: [DONE]까지 전송됩니다.
상태 코드
| 코드 | 의미 |
|---|---|
| 400 | 잘못된 매개변수 |
| 401 | 인증 실패 |
| 402 / 403 | 할당량 또는 권한 |
| 429 | 요청 제한 |
| 502 / 503 | 업스트림 오류 — 재시도 |