Claude認定 対策ノート

講座 › 分野5 モデルの選択と最適化

5.2 技術的な基礎

配点 6.1%Technical Fundamentals

SDKはREST APIを包んで、ヘッダー・再試行・ストリーミング・型を引き受ける。長く続く双方向のやり取りにはWebSocketを使う設計もある。

未読

REST APIを包むSDK

図解:REST APIを包むSDK

Claude APIはREST形式のAPIで、公式のSDKがそれを包んでいます。SDKは、認証・版・content-type のヘッダーを自動で付け、一時的な失敗(接続、流量の上限、5xx)を指数関数的な間隔で既定で2回再試行します。再試行の回数は max_retries で変えられます。

出典:API overview
the SDK sends the authentication, version, and content-type headers automatically
https://platform.claude.com/docs/en/api/overview.md(取得 2026-11-17)
出典:Errors
The official SDK automatically retries transient failures (such as connection errors, rate limits, and 5xx server errors) with exponential backoff, twice by default
https://platform.claude.com/docs/en/api/errors.md(取得 2026-11-17)

同期・非同期とストリーミング

図解:同期・非同期とストリーミング

Python SDKは、同期と非同期の両方の呼び出し、ストリーミング、Amazon BedrockやGoogle Cloudとの連携に対応しています。SDKのストリーミングは、サーバー送信イベントで接続を保ちながら、届いた差分を組み立てて、最後に完成したメッセージを取り出せます。

出典:Python SDK
It supports both synchronous and asynchronous operations, streaming, and integrations with Amazon Bedrock
https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python.md(取得 2026-11-17)
出典:Streaming messages
keeps the HTTP connection alive with server-sent events
https://platform.claude.com/docs/en/build-with-claude/streaming.md(取得 2026-11-17)

WebSocket

図解:WebSocket

Agent SDKを本番で動かすとき、コンテナはHTTPまたはWebSocketの入口を公開し、利用者のセッションごとに長く続く問い合わせを割り当てます。SDKの子プロセス自体はネットワークで待ち受けず、アプリが入口でリクエストを受けて、内部でSDKを呼びます。

出典:Hosting the Agent SDK
The container exposes an HTTP or WebSocket endpoint and maps each active session to a long-lived query and the subprocess behind it.
https://code.claude.com/docs/en/agent-sdk/hosting.md(取得 2026-11-17)
出典:Hosting the Agent SDK
the subprocess itself does not listen on the network
https://code.claude.com/docs/en/agent-sdk/hosting.md(取得 2026-11-17)

ストリーミングのイベントの形と、ヘッドレスの出力

図解:ストリーミングのイベントの形と、ヘッドレスの出力

APIのストリーミングでは、各イベントに名前とJSONのデータが付きます。Claude Codeを -p で動かすときも、stream-json の形式を選ぶと、1行1つのJSONで途中経過を受け取れます。どちらも、届いた順に処理するプログラムを書く前提の形です。

出典:Streaming messages
Each server-sent event includes a named event type and associated JSON data.
https://platform.claude.com/docs/en/build-with-claude/streaming.md(取得 2026-11-17)
出典:Headless mode
`stream-json`: newline-delimited JSON for real-time streaming
https://code.claude.com/docs/en/headless.md(取得 2026-11-17)
試験のポイント