메인 콘텐츠로 건너뛰기

Documentation Index

Fetch the complete documentation index at: https://docs.apigo.ai/llms.txt

Use this file to discover all available pages before exploring further.

권장 엔드포인트

최소한의 요청

{
  "model": "claude-sonnet-4-20250514",
  "max_tokens": 1024,
  "stream": true,
  "messages": [
    {
      "role": "user",
      "content": [{ "type": "text", "text": "Explain SSE streaming while streaming the answer." }]
    }
  ]
}

cURL 예

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -N \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": [{ "type": "text", "text": "Explain SSE streaming while streaming the answer." }]
      }
    ]
  }'

파이썬 예제

from anthropic import Anthropic

client = Anthropic(api_key="<ANTHROPIC_API_KEY>")

with client.messages.stream(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [{"type": "text", "text": "Explain SSE streaming while streaming the answer."}],
        }
    ],
) as stream:
    for text in stream.text_stream:
        print(text, end="")

Node.js 예

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const stream = await client.messages.stream({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [{ type: "text", text: "Explain SSE streaming while streaming the answer." }]
    }
  ]
});

for await (const text of stream.textStream) {
  process.stdout.write(text);
}

모범 사례

  • Claude는 하나의 최종 JSON 페이로드가 아닌 SSE 이벤트를 반환합니다.
  • 스트리밍 출력을 구문 분석할 때 콘텐츠 블록 경계를 유지합니다.
  • 도구나 사고도 활성화하는 경우 이벤트 파서는 일반 텍스트 델타 이상의 기능을 지원해야 합니다.