Expand description
Claude API Types - Complete request/response model for the Messages API
Every struct here maps 1:1 to the Claude API JSON schema.
Optional fields use skip_serializing_if to keep payloads clean.
Key design: ContentBlock is a tagged enum that handles ALL content types
(text, image, thinking, tool_use, tool_result) in both requests and responses.
Modules§
- models
- Current Claude model IDs (as of 2026-03)
Structs§
- Cache
Control - Prompt caching directive - attach to system blocks, messages, or tools
- Message
- A single message in the conversation (user or assistant)
- Messages
Request - The main request body sent to
POST /v1/messages - Messages
Response - Full response from
POST /v1/messages(non-streaming) - Metadata
- Optional metadata for tracking/billing purposes
- Output
Config - Controls output behavior: thinking effort and structured format
- System
Block - A system block with optional cache_control for prompt caching
- Tool
- A tool definition telling Claude what functions are available
- Usage
- Token usage statistics from the API
Enums§
- Content
Block - All possible content block types in request AND response messages.
- Effort
- How hard Claude should think. Default is
High.Maxis Opus 4.6 only. - Image
Source - How an image is provided: inline base64 or external URL
- Message
Content - Content can be a simple string or an array of typed blocks. The API accepts both forms; responses always use Blocks.
- Message
Role - Output
Format - Structured output format constraint
- Stop
Reason - Why Claude stopped generating
- System
Content - System prompt - either a plain string or structured blocks with cache_control.
Serde’s
untaggedtries String first, then Vec. - Thinking
Config - Controls Claude’s internal reasoning.
- Tool
Choice - Controls whether/how Claude selects tools
- Tool
Result Content - Content of a tool result - either a plain string or structured blocks