CCDVF-D5.3 · Domain 5 · Model Selection & Optimization · 16.8% of CCD-F

Technical Fundamentals: SDKs, REST, and WebSockets.

6 min read·9 sections·Tier A

For standard model inference, the Messages API (POST /v1/messages) is the primary endpoint, tools, structured outputs, and streaming are request parameters on that same endpoint, not separate APIs or protocols. It is not the only endpoint Anthropic exposes: Message Batches, Token Counting, Models, Files, and Admin are separate, purpose-specific APIs alongside it. "Real-time" in the Claude API means HTTP streaming over Server-Sent Events, not a persistent WebSocket connection, an assumption worth checking before designing a chat or voice UI. Claude docs: streaming

Official Anthropic docsCCDVF-D5 (16.8%)CCD-F only
Technical Fundamentals: SDKs, REST, and WebSockets, hero illustration featuring Loop mascot in a warm gallery scene.
Domain CCDVF-D5Model Selection & Optimization · 16.8%
On this page
01 · Summary

TLDR

For standard model inference, the Messages API (POST /v1/messages) is the primary endpoint, tools, structured outputs, and streaming are request parameters on that same endpoint, not separate APIs or protocols. It is not the only endpoint Anthropic exposes: Message Batches, Token Counting, Models, Files, and Admin are separate, purpose-specific APIs alongside it. "Real-time" in the Claude API means HTTP streaming over Server-Sent Events, not a persistent WebSocket connection, an assumption worth checking before designing a chat or voice UI. Claude docs: streaming

7
Official SDK languages
CCDVF-D5
Exam domain
16.8%
Domain weight
SSE, not WebSocket
Streaming protocol
None
Public Anthropic WebSocket Messages API
02 · Definition

What it is

For standard model inference, whatever language or interface it's written in, a Claude integration ultimately calls the Messages API (POST /v1/messages) - the primary inference endpoint, not the only endpoint Anthropic exposes. Tools, structured outputs, and streaming are all request parameters on that same endpoint, not separate APIs. Anthropic's official SDKs, shipped for Python, TypeScript/JavaScript, Java, Go, Ruby, C#, and PHP, are thin, code-generated clients over that REST surface: typed request/response objects, retries, and pagination, but every inference call still resolves to a plain HTTPS request to /v1/messages.

Around that primary inference endpoint, Anthropic publishes a family of separate, purpose-specific APIs: the Message Batches API (POST /v1/messages/batches) for async, high-volume processing at a cost discount; the Token Counting API (POST /v1/messages/count_tokens); the Models API (GET /v1/models) for listing available models; the Files API (POST /v1/files) for uploading content reused across calls; and an Admin API for organization-level management (workspaces, API keys, usage). "One endpoint" is a useful simplification for the inference path specifically, not a claim that the Claude API surface has exactly one endpoint overall. The distinction to internalize for CCD-F: (1) SDK versus raw REST is a convenience layer over the Messages API, not a different protocol, and (2) "real-time" in the Claude API means HTTP streaming (Server-Sent Events) on that same Messages endpoint, not a persistent WebSocket connection, an assumption worth checking before designing a chat or voice UI around it.

03 · Mechanics

How it works

SDKs are wrappers, and the docs say so per language, not just in general. The TypeScript SDK page states it "provides convenient access to the Anthropic REST API from TypeScript or JavaScript." The Python SDK page states the same: "provides convenient access to the Anthropic REST API from Python applications... supports both synchronous and asynchronous operations, streaming." Anthropic also ships an ant CLI for shell scripting and typed flags, and separately, framework-compatibility layers (an OpenAI-SDK-compatible surface, an Apple Foundation Models Swift package) that expose Claude through another framework's API shape rather than the Messages API directly, distinct from the seven general-purpose client SDKs.

Streaming uses Server-Sent Events, not WebSockets. Setting "stream": true on a Messages API request incrementally streams the response using server-sent events; raw curl against a streaming request shows event: content_block_delta lines as plain HTTP chunks. SSE is one-way and HTTP-native: the client opens a normal HTTPS request and reads a chunked response, no bidirectional socket upgrade required. The SDKs' .stream() helpers (e.g. the Python and TypeScript clients) are convenience wrappers around parsing this same SSE stream, they don't open a different connection type underneath.

Tool-call arguments stream too, as partial JSON. Streamed tool-use blocks arrive as input_json_delta events containing partial JSON fragments; an application can show "thinking..." while arguments fill in, but should wait for content_block_stop before invoking the tool, to avoid executing on partial, malformed arguments.

There is no public, Anthropic-hosted WebSocket Messages API. A developer-facing WebSocket endpoint analogous to OpenAI's Realtime API does not exist in Anthropic's official docs. The only WebSocket associated with "Claude" is an internal, undocumented voice-input feature inside the Claude Code CLI client itself, a coding-agent client implementation detail reverse-engineered by third parties, not a published API surface for third-party developers to build against.

Voice and real-time apps compose services rather than using one Claude WebSocket. Anthropic's own cookbook pairs a third-party speech-to-text/text-to-speech WebSocket (ElevenLabs) with ordinary REST calls to Claude for the reasoning turn. WebSockets sit in the audio layer of that architecture, not the model layer; Claude is still called over REST/SSE in the middle of the pipeline.

Technical Fundamentals: SDKs, REST, and WebSockets mechanics, painterly diagram featuring Loop mascot.
04 · In production

Where you'll see it

Streaming chat UI

Renders tokens as they arrive using stream: true and Server-Sent Events, consumed via an SDK's .stream() helper, with no WebSocket server built or maintained.

Low-latency voice assistant

Pairs a WebSocket to a speech vendor (ElevenLabs, per Anthropic's cookbook) for audio in/out with ordinary REST/SSE calls to Claude for the reasoning turn in the middle of the pipeline.

05 · Implementation

Code examples

Enabling SSE streaming on a Messages API requestbash
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" \
  -d '{
    "model": "claude-opus-4-8",
    "max_tokens": 1024,
    "stream": true,
    "messages": [{"role": "user", "content": "Hello"}]
  }'

# Response is plain HTTPS, chunked as Server-Sent Events, not a WebSocket upgrade:
# event: message_start
# data: {...}
#
# event: content_block_delta
# data: {"delta": {"type": "text_delta", "text": "Hi"}}
#
# event: message_stop
`stream: true` is a request parameter on the same POST /v1/messages endpoint; the client reads the chunked HTTP response as SSE events, no separate socket handshake.
06 · Compare

Side-by-side

LayerProtocolWho provides itUse it for
Messages API (raw REST)HTTPS POST /v1/messagesAnthropic-hosted endpointAny language, full control over the request
Official SDK (7 languages)Same REST endpoint, typed wrapperAnthropic client libraryIdiomatic types, retries, .stream() helper
Streaming (`stream: true`)Server-Sent Events over the same HTTPS connectionPart of the Messages API itselfToken-by-token UX; one-directional, HTTP-native
Voice/real-time pipelineWebSocket to a 3rd-party speech vendor + REST/SSE to ClaudeYou compose itLow-latency audio in/out, with Claude's reasoning turn still over REST
07 · When to use

Decision tree

01

Do you need typed request/response objects, retries, and a built-in streaming helper, rather than raw HTTP control?

YesUse an official SDK (Python, TypeScript, Java, Go, Ruby, C#, or PHP), it wraps the same REST endpoint with idiomatic types.
NoCall POST /v1/messages directly; nothing an SDK offers is unavailable at the raw REST layer.
02

Do you need token-by-token, low-latency text output in a UI?

YesSet stream: true and consume Server-Sent Events, either raw or via an SDK's .stream() helper; no WebSocket server is required.
NoA normal blocking POST request is sufficient.
03

Do you need bidirectional, persistent, low-latency audio (voice input/output)?

YesA WebSocket to a speech vendor (e.g. ElevenLabs) is the right layer for the audio; Claude is still called over REST/SSE for the reasoning turn in the middle of that pipeline.
NoNo WebSocket is needed anywhere in this architecture.
04

Are you assuming Anthropic hosts a public WebSocket endpoint for Claude text messaging, comparable to OpenAI's Realtime API?

YesThat assumption doesn't hold, no such published, developer-facing endpoint exists; design around REST/SSE instead.
NoCorrect; proceed with the REST/SSE Messages API as the text/reasoning layer.
08 · On the exam

Question patterns

Technical Fundamentals: SDKs, REST, and WebSockets exam trap, painterly cautionary scene featuring Loop mascot.
A team building a Claude-powered chat UI plans to stand up a dedicated WebSocket server so responses can render token-by-token. Is that infrastructure necessary?
No. Set stream: true on a normal Messages API POST and consume the response as Server-Sent Events (or via an SDK's .stream() helper); token-by-token rendering doesn't require a WebSocket at all. Named distractor: "yes, WebSockets are required for any low-latency streaming UX", wrong, SSE over a standard HTTPS request already delivers that.
A team building a low-latency voice assistant assumes a single WebSocket connection to Claude can carry both the audio stream and the reasoning turn. What's the correct architecture?
Compose two layers: a WebSocket to a speech vendor (e.g. ElevenLabs, per Anthropic's own cookbook pattern) for audio in/out, and ordinary REST/SSE calls to Claude for the text reasoning turn in the middle. Named distractor: "use Anthropic's Realtime WebSocket API for both", no such public, developer-facing endpoint exists.
A developer asks whether the official Python SDK talks to Claude over a different protocol than a raw `curl` call to the same endpoint. What's the answer?
No difference in protocol. Both the Python SDK page and the TypeScript SDK page state the library provides "convenient access to the Anthropic REST API"; the SDK is a typed wrapper, every call still resolves to the same HTTPS request. Named distractor: "the SDK uses a persistent binary protocol for lower latency", no such protocol exists in the official SDKs.
A developer searches Anthropic's docs for a WebSocket-based "Realtime API," similar to OpenAI's, to reduce round-trip overhead in a chat app. What should they conclude?
No such public, Anthropic-hosted WebSocket Messages API exists in official docs; the closest thing is an internal, undocumented voice-input feature inside the Claude Code CLI client, which is a client implementation detail, not a published third-party API. Named distractor: "reverse-engineer the Claude Code CLI's internal voice websocket for production use", that's an undocumented internal feature, not a supported integration path.
During a streaming response that includes a tool call, an application wants to start showing the tool's arguments to the user as they arrive, then execute the tool once arguments are complete. What event handling is correct?
Read input_json_delta events to display partial JSON as it streams in, but wait for content_block_stop before actually invoking the tool, to avoid executing on incomplete or malformed partial arguments. Named distractor: "invoke the tool as soon as the first input_json_delta event arrives", that risks running the tool with a partial, invalid argument object.
09 · FAQ

Frequently asked

Does the official SDK talk to Claude over a different protocol than raw REST calls?
No. Anthropic's SDK docs state each library provides "convenient access to the Anthropic REST API"; it's a typed wrapper, every call still resolves to the same HTTPS POST /v1/messages request.
Is there an official Anthropic WebSocket API for real-time voice, comparable to OpenAI's Realtime API?
No. No such public, developer-facing WebSocket endpoint appears in Anthropic's official docs; voice apps built on Claude pair a third-party speech-vendor WebSocket with REST/SSE calls to Claude for the reasoning turn.
10 · Practice with AI

Work this with your AI

Work this concept hands-on with Claude Code, Codex, or claude.ai. Copy a prompt, paste it into your assistant, and practise in tandem. Each one keeps you active (explain it back, get drilled, or build) rather than just reading.

  • Drill it like the exam (scenario MCQs)
    Practice in the exam's scenario-MCQ format with trap awareness.
  • Explain it back (Feynman)
    Build durable, transferable understanding of a concept you can half-state.
  • Test me, adapting the difficulty
    Active recall practice on a concept you think you know.
  • Check my prerequisites first
    Before studying a concept that keeps not sticking.
  • Find the high-leverage 20%
    When a domain feels too big and you are short on time.
Self-check

Test yourself

Three diagnostic questions on this primitive. Reveal each answer when you have a guess. Want a full 60-question mock? Open the mock hub →

Q1A team building a Claude-powered chat UI plans to stand up a dedicated WebSocket server so responses can render token-by-token. Is that infrastructure necessary?
No. Set stream: true on a normal Messages API POST and consume the response as Server-Sent Events (or via an SDK's .stream() helper); token-by-token rendering doesn't require a WebSocket at all. Named distractor: "yes, WebSockets are required for any low-latency streaming UX", wrong, SSE over a standard HTTPS request already delivers that.
Q2A team building a low-latency voice assistant assumes a single WebSocket connection to Claude can carry both the audio stream and the reasoning turn. What's the correct architecture?
Compose two layers: a WebSocket to a speech vendor (e.g. ElevenLabs, per Anthropic's own cookbook pattern) for audio in/out, and ordinary REST/SSE calls to Claude for the text reasoning turn in the middle. Named distractor: "use Anthropic's Realtime WebSocket API for both", no such public, developer-facing endpoint exists.
Q3A developer asks whether the official Python SDK talks to Claude over a different protocol than a raw `curl` call to the same endpoint. What's the answer?
No difference in protocol. Both the Python SDK page and the TypeScript SDK page state the library provides "convenient access to the Anthropic REST API"; the SDK is a typed wrapper, every call still resolves to the same HTTPS request. Named distractor: "the SDK uses a persistent binary protocol for lower latency", no such protocol exists in the official SDKs.
Last reviewed: 2026-05-04·Refresh cadence: monthly
CCDVF-D5.3 · CCDVF-D5 · Model Selection & Optimization

Technical Fundamentals: SDKs, REST, and WebSockets, complete.

You've covered the full ten-section breakdown for this primitive, definition, mechanics, code, false positives, comparison, decision tree, exam patterns, and FAQ. One technical primitive down on the path to CCA-F.

More platforms →