講座 › 分野2 アプリケーションと統合
2.3 Claude APIの仕組み
配点 6.8%Claude API Mechanics
Messages APIは状態を持たない。会話の履歴は毎回送る。ストリーミング、画像、思考、キャッシュ、バッチを、要件に合わせて組み合わせる。
未読
Messages API:状態を持たない 読了

Claude APIは、api.anthropic.com にあるREST形式のAPIです。Messages APIは状態を持たないので、会話を続けるときは、それまでの履歴を毎回すべて送ります。履歴のアシスタントの発言は、実際にClaudeが言ったものでなくてもかまいません。
出典:API overview
The Claude API is a RESTful API at `https://api.anthropic.com`https://platform.claude.com/docs/en/api/overview.md(取得 2026-11-17)
出典:Working with the Messages API
The Messages API is stateless, which means that you always send the full conversational history to the API.https://platform.claude.com/docs/en/build-with-claude/working-with-mes…(取得 2026-11-17)
ストリーミング 読了

"stream": true を指定すると、応答をサーバー送信イベント(SSE)で少しずつ受け取れます。各イベントには名前と、JSONのデータが付きます。文章、ツール使用、思考の差分が順に届くので、利用者を待たせない画面を作れます。
出典:Streaming messages
you can set `"stream": true` to incrementally stream the response using server-sent eventshttps://platform.claude.com/docs/en/build-with-claude/streaming.md(取得 2026-11-17)
出典: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)
画像・PDF・ファイル 読了

Claudeは画像を読み取って分析できます。同じファイルを何度も使うときは、Files APIで一度だけアップロードし、file_id で参照します。毎回データを送り直す必要がなくなります。
出典:Vision
Claude's vision capabilities allow it to process and analyze imageshttps://platform.claude.com/docs/en/build-with-claude/vision.md(取得 2026-11-17)
出典:Files API
Upload files once, reference them by file_id in Messages requestshttps://platform.claude.com/docs/en/build-with-claude/files.md(取得 2026-11-17)
キャッシュとバッチ 読了

プロンプトキャッシュは、繰り返し送る先頭部分(ツール定義、システムプロンプト、メッセージの順)を再利用し、処理時間と費用を減らします。Message Batches APIは、大量のリクエストをまとめて非同期に処理し、費用を半分にします。多くは1時間以内に終わり、遅くとも24時間で結果を取り出せます。
出典:Prompt caching
Prompt caching covers the full prefix: `tools`, `system`, and `messages` (in that order)https://platform.claude.com/docs/en/build-with-claude/prompt-caching.m…(取得 2026-11-17)
出典:Batch processing
with most batches completing within 1 hourhttps://platform.claude.com/docs/en/build-with-claude/batch-processing…(取得 2026-11-17)
出典:Batch processing
cutting costs by 50 percent and increasing throughputhttps://platform.claude.com/docs/en/build-with-claude/batch-processing…(取得 2026-11-17)
リアルタイムかバッチか、他社経由の呼び出し 読了

利用者がその場で待つ処理はリアルタイムのAPI、すぐに結果が要らない大量の処理はバッチ、と使い分けます。Claudeは、Amazon BedrockやGoogle Cloudなどの他社の基盤経由でも呼び出せます。SDKは、それらとの連携も用意しています。
出典:Batch processing
Instead of processing requests one at a time with immediate responses, batch processing allows you to submit multiple requests together for asynchronous processing.https://platform.claude.com/docs/en/build-with-claude/batch-processing…(取得 2026-11-17)
出典:Python SDK
It supports both synchronous and asynchronous operations, streaming, and integrations with Amazon Bedrockhttps://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python.md(取得 2026-11-17)
試験のポイント
- 会話の続きは「前回の履歴を送る」。API側は覚えていない。
出典:Working with the Messages API
You can use this pattern to build up a conversation over time.
https://platform.claude.com/docs/en/build-with-claude/working-with-mes…(取得 2026-11-17) - コスト最優先・翌日でよい大量処理はバッチ(半額、24時間以内)。
出典:Batch processing
You can access batch results when all messages have completed or after 24 hours, whichever comes first.
https://platform.claude.com/docs/en/build-with-claude/batch-processing…(取得 2026-11-17)