Lab 01 - Claude API Production Adapter
labSection: Labs & PracticeUpdated 2026-11-15
Goal: build a reliable provider adapter behind a clean application port, with a fake client for tests.
Scope: TypeScript or Python SDK; custom API client optional. No real credentials in Git.
Deliverables
- A
generate()port and a provider adapter mapping typed request/response blocks. - A tool dispatcher that pairs
tool_usetotool_result, including parallel requests andis_errorresponses. - An SSE consumer that handles
message_start, content deltas, stop reasons, late error events and disconnects. - A bounded retry policy with max attempts, timeouts, jitter and a test confirming no retry of invalid requests.
- A fixture demonstrating that partial generated JSON is rejected; usage/cost telemetry.
Acceptance tests
- ☐ Client tool is invoked once and answered using matching ID.
- ☐ Two parallel tools return in one valid result turn.
- ☐ A malformed tool input triggers an error without side effects.
- ☐ An SSE stream failing after HTTP 200 is marked incomplete.
- ☐ Idempotent retries terminate within the budget.
Related: Messages API Contract · Tool Schema and Tool Result Lifecycle · Streaming SSE and Recovery · Retries Timeouts and Idempotency.