Claude Sonnet 5.5 API
Anthropic이 제공하는 Claude Sonnet 5.5 LLM 모델의 전체 API 참조 문서입니다.
모델 종류
이 API는 두 가지 Claude Sonnet 5.5 모델을 지원합니다.
간단 비교
Claude Sonnet 5.5 Text to Text
엔드포인트 {#}
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: 'claude-sonnet-5.5-text-to-text',
messages: [
{
role: 'user',
content: 'Write a four-line modern poem about a programmer drinking coffee.'
}
],
stream: true,
max_tokens: 500,
})
});
Claude Sonnet 5.5 File Analysis
엔드포인트
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: 'claude-sonnet-5.5-file-analysis',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize the key points of this PDF.' },
{
type: 'file',
file: {
filename: 'gptproto.pdf',
file_data: 'https://tos.gptproto.com/resource/gptproto.pdf'
}
}
]
}
],
stream: true,
max_tokens: 1000,
})
});
응답 형식
Claude Sonnet 5.5 LLM 모델은 OpenAI 호환 완성 응답을 반환합니다. stream: true이면 서버 전송 이벤트(SSE)로 응답하고, stream: false이면 단일 JSON 객체로 응답합니다.
성공 응답
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{"content":"Here is a concise summary"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
오류 응답
event: error
data: {"error":{"message":"Authorization is empty","type":"invalid_request_error","code":"1001","param":null}}
모범 사례
- 구조화된 메시지 사용: 문맥을 하나의 프롬프트로 합치는 대신
messages[]를 통해 대화 기록을 전송합니다.
- 적절한 모델 선택: 텍스트만 사용하는 추론 및 작성에는 Text to Text를, 파일이나 이미지가 필요한 경우에는 File Analysis를 사용합니다.
- 필요에 따라
max_tokens 설정: 이 매개변수로 최대 출력 길이를 제어합니다.
- SSE 이벤트 처리: 스트리밍 표시를 위해
choices[0].delta.content를 이어 붙이고 data: [DONE]을 성공적인 완료로 처리합니다.
- 지원되는 입력만 전송: 현재 클라이언트에서 텍스트 모델은 지원되지 않는 파일 및 이미지 부분을 무시합니다.