Grok 4.5 API
xAI 기반 Grok 4.5 LLM 모델의 전체 API 레퍼런스입니다.
모델 변형
이 API는 두 가지 Grok 4.5 모델 변형을 지원합니다.
빠른 비교
Grok 4.5 텍스트-투-텍스트
엔드포인트 {#}
POST /api/v1/chat/completions
요청 매개변수
필수
메시지 지원
선택 사항
요청 예시
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'grok-4.5-text-to-text',
messages: [
{
role: 'user',
content: 'Explain the key differences between REST and GraphQL APIs.'
}
],
stream: true,
max_tokens: 2048
})
});
Grok 4.5 이미지-투-텍스트
엔드포인트
POST /api/v1/chat/completions
요청 매개변수
필수
메시지 지원
선택 사항
요청 예시
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'grok-4.5-image-to-text',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe the image and extract any visible text.' },
{
type: 'image_url',
image_url: {
url: 'https://example.com/sample-image.jpg'
}
}
]
}
],
stream: true,
max_tokens: 2048
})
});
응답 형식
Grok 4.5 LLM 모델은 OpenAI 호환 컴플리션 응답을 반환합니다. stream: true이면 응답은 서버 전송 이벤트이며, stream: false이면 응답은 단일 JSON 객체입니다.
성공 응답
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.5-text-to-text","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.5-text-to-text","choices":[{"index":0,"delta":{"content":"Here is a concise explanation"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.5-text-to-text","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"grok-4.5-text-to-text","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
오류 응답
event: error
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
모범 사례
- 구조화된 메시지 사용: 컨텍스트를 하나의 프롬프트로 합치지 말고
messages[]를 통해 대화 기록을 전송하세요.
- 적합한 모델 변형 선택: 텍스트 전용 추론에는 텍스트-투-텍스트를 사용하고, 이미지 이해가 필요하면 이미지-투-텍스트를 사용하세요.
- SSE 이벤트 수신: 스트리밍 표시를 위해
choices[0].delta.content를 추가하고 data: [DONE]을 성공적인 완료로 처리하세요.
- 지원되는 입력만 전송: 텍스트-투-텍스트는 이미지 또는 파일 첨부를 지원하지 않습니다.