Chat Completions
대화 완성 응답을 생성합니다. 텍스트 생성, 멀티모달 입력, 함수 호출, 스트리밍 응답 등의 기능을 지원합니다.
엔드포인트
POST https://api.ofox.ai/v1/chat/completions요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
model | string | ✅ | 모델 식별자, 예: openai/gpt-4o |
messages | array | ✅ | 메시지 배열 |
temperature | number | — | 샘플링 온도 0-2, 기본값 1 |
max_tokens | number | — | 최대 생성 토큰 수 |
stream | boolean | — | 스트리밍 응답 활성화 여부 |
top_p | number | — | 핵 샘플링 파라미터 |
frequency_penalty | number | — | 빈도 패널티 -2에서 2 |
presence_penalty | number | — | 존재 패널티 -2에서 2 |
tools | array | — | 사용 가능한 도구 정의 (Function Calling) |
tool_choice | string/object | — | 도구 선택 전략 |
response_format | object | — | 응답 형식 (JSON Mode) |
provider | object | — | OfoxAI 확장: 라우팅 및 폴백 설정 |
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-4o",
"messages": [
{"role": "system", "content": "당신은 유용한 도우미입니다."},
{"role": "user", "content": "API Gateway란 무엇인지 설명해 주세요"}
],
"temperature": 0.7
}'응답 형식
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1703123456,
"model": "openai/gpt-4o",
"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-4o",
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-4o",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "이 이미지에 무엇이 있나요?"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
)비전 기능을 지원하는 모델: openai/gpt-4o, anthropic/claude-sonnet-4.5, google/gemini-3-flash-preview 등.
자세한 내용은 다음을 참조하세요: 비전 이해 가이드.
Function Calling
자세한 내용은 다음을 참조하세요: 함수 호출 가이드.
Last updated on