Chat Completions
대화 완성은 가장 많이 사용되는 인터페이스로, OpenAI 프로토콜과 완전히 호환됩니다.
POST https://api.4allapi.com/v1/chat/completions요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
model | string | 예 | 모델 이름, 모델 개요 참조 |
messages | array | 예 | 대화 메시지 배열, 요소에 role 및 content 포함 |
stream | boolean | 아니오 | 스트리밍 반환 여부, 스트리밍 출력 참조 |
temperature | number | 아니오 | 샘플링 온도 0–2, 값이 클수록 더 다양한 출력 |
top_p | number | 아니오 | 핵 샘플링 임계값, temperature와 택일하여 조정 |
max_tokens | number | 아니오 | 응답의 최대 토큰 수 |
stop | string/array | 아니오 | 정지 단어 |
presence_penalty | number | 아니오 | 주제 참신도 페널티 -2–2 |
frequency_penalty | number | 아니오 | 반복도 페널티 -2–2 |
tools | array | 아니오 | 도구/함수 호출 정의 (지원 모델) |
response_format | object | 아니오 | 예: {"type":"json_object"} JSON 출력 강제 |
messages의 role은 system / user / assistant / tool을 지원합니다.
content는 문자열이거나 멀티모달 배열(텍스트 + 이미지, 비전 이해 참조)일 수 있습니다.
요청 예시
curl https://api.4allapi.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $AIPROXY_KEY" \ -d '{ "model": "fable-5", "messages": [ {"role": "system", "content": "你是一个严谨的技术助手"}, {"role": "user", "content": "用一句话解释什么是 API 网关"} ], "temperature": 0.7, "max_tokens": 512 }'응답 구조
{ "id": "chatcmpl-xxx", "object": "chat.completion", "created": 1750000000, "model": "fable-5", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "API 网关是……" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 32, "completion_tokens": 41, "total_tokens": 73 }}usage 필드는 과금 기준이며, 자세한 내용은 과금 및 한도를 참조하세요.