Chat Completions
대화 완성 응답을 생성합니다. 텍스트 생성, 멀티모달 입력, 함수 호출, 스트리밍 응답 등의 기능을 지원합니다.
새 프로젝트에는 Responses API 사용을 권장합니다. Responses API는 instructions와 input을 분리하므로 시스템 지시에 Prompt Caching이 자동으로 적용되어 캐시 적중률이 높아지고 비용과 지연 시간을 크게 줄일 수 있습니다. Chat Completions는 계속 장기 지원되며, 기존 연동은 이전할 필요가 없습니다.
엔드포인트
POST https://api.ofox.ai/v1/chat/completions요청 파라미터
Message 형식
interface Message {
role: 'system' | 'user' | 'assistant' | 'tool'
content: string | ContentPart[] // 텍스트 또는 멀티모달 콘텐츠
name?: string
tool_calls?: ToolCall[] // assistant 메시지의 도구 호출
tool_call_id?: string // tool 메시지의 호출 ID
}
// 멀티모달 콘텐츠
type ContentPart =
| { type: 'text'; text: string }
| { type: 'image_url'; image_url: { url: string; detail?: 'auto' | 'low' | 'high' } }요청 예시
cURL
Terminal
curl https://api.ofox.ai/v1/chat/completions \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6.1-sol",
"messages": [
{"role": "system", "content": "당신은 유용한 도우미입니다."},
{"role": "user", "content": "API Gateway란 무엇인지 설명해 주세요"}
],
"temperature": 0.7
}'응답 형식
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-6.1-sol",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "API Gateway(API 게이트웨이)란..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}스트리밍 응답
stream: true를 설정하여 SSE 스트리밍 응답을 활성화합니다:
Python
stream.py
stream = client.chat.completions.create(
model="openai/gpt-6.1-sol",
messages=[{"role": "user", "content": "이야기 하나 들려주세요"}],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)스트리밍 응답 형식
각 chunk는 SSE를 통해 전송됩니다:
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"안"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"녕"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]멀티모달 입력 (비전)
이미지를 전송하여 모델이 분석하도록 합니다:
response = client.chat.completions.create(
model="openai/gpt-6.1-sol",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "이 이미지에 무엇이 있나요?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)비전 기능을 지원하는 모델: openai/gpt-6.1-sol, anthropic/claude-sonnet-5.5, google/gemini-3.8-flash 등.
자세한 내용은 다음을 참조하세요: 비전 이해 가이드.
Function Calling
자세한 내용은 다음을 참조하세요: 함수 호출 가이드.
마지막 업데이트