openai_protocol/
messages.rs

1//! Anthropic Messages API protocol definitions
2//!
3//! This module provides Rust types for the Anthropic Messages API.
4//! See: https://docs.anthropic.com/en/api/messages
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11// ============================================================================
12// Request Types
13// ============================================================================
14
15/// Request to create a message using the Anthropic Messages API.
16///
17/// This is the main request type for `/v1/messages` endpoint.
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct CreateMessageRequest {
20    /// The model that will complete your prompt.
21    pub model: String,
22
23    /// Input messages for the conversation.
24    pub messages: Vec<InputMessage>,
25
26    /// The maximum number of tokens to generate before stopping.
27    pub max_tokens: u32,
28
29    /// An object describing metadata about the request.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub metadata: Option<Metadata>,
32
33    /// Service tier for the request (auto or standard_only).
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub service_tier: Option<ServiceTier>,
36
37    /// Custom text sequences that will cause the model to stop generating.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub stop_sequences: Option<Vec<String>>,
40
41    /// Whether to incrementally stream the response using server-sent events.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub stream: Option<bool>,
44
45    /// System prompt for providing context and instructions.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub system: Option<SystemContent>,
48
49    /// Amount of randomness injected into the response (0.0 to 1.0).
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub temperature: Option<f64>,
52
53    /// Configuration for extended thinking.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub thinking: Option<ThinkingConfig>,
56
57    /// How the model should use the provided tools.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub tool_choice: Option<ToolChoice>,
60
61    /// Definitions of tools that the model may use.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub tools: Option<Vec<Tool>>,
64
65    /// Only sample from the top K options for each subsequent token.
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub top_k: Option<u32>,
68
69    /// Use nucleus sampling.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub top_p: Option<f64>,
72
73    // Beta features
74    /// Container configuration for code execution (beta).
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub container: Option<ContainerConfig>,
77
78    /// MCP servers to be utilized in this request (beta).
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub mcp_servers: Option<Vec<McpServerConfig>>,
81}
82
83impl CreateMessageRequest {
84    /// Check if the request is for streaming
85    pub fn is_stream(&self) -> bool {
86        self.stream.unwrap_or(false)
87    }
88
89    /// Get the model name
90    pub fn get_model(&self) -> &str {
91        &self.model
92    }
93}
94
95/// Request metadata
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct Metadata {
98    /// An external identifier for the user who is associated with the request.
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub user_id: Option<String>,
101}
102
103/// Service tier options
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(rename_all = "snake_case")]
106pub enum ServiceTier {
107    Auto,
108    StandardOnly,
109}
110
111/// System content can be a string or an array of text blocks
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(untagged)]
114pub enum SystemContent {
115    String(String),
116    Blocks(Vec<TextBlock>),
117}
118
119/// A single input message in a conversation
120#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct InputMessage {
122    /// The role of the message sender (user or assistant)
123    pub role: Role,
124
125    /// The content of the message
126    pub content: InputContent,
127}
128
129/// Role of a message sender
130#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
131#[serde(rename_all = "lowercase")]
132pub enum Role {
133    User,
134    Assistant,
135}
136
137/// Input content can be a string or an array of content blocks
138#[derive(Debug, Clone, Serialize, Deserialize)]
139#[serde(untagged)]
140pub enum InputContent {
141    String(String),
142    Blocks(Vec<InputContentBlock>),
143}
144
145// ============================================================================
146// Input Content Blocks
147// ============================================================================
148
149/// Input content block types
150#[derive(Debug, Clone, Serialize, Deserialize)]
151#[serde(tag = "type", rename_all = "snake_case")]
152pub enum InputContentBlock {
153    /// Text content
154    Text(TextBlock),
155    /// Image content
156    Image(ImageBlock),
157    /// Document content
158    Document(DocumentBlock),
159    /// Tool use block (for assistant messages)
160    ToolUse(ToolUseBlock),
161    /// Tool result block (for user messages)
162    ToolResult(ToolResultBlock),
163    /// Thinking block
164    Thinking(ThinkingBlock),
165    /// Redacted thinking block
166    RedactedThinking(RedactedThinkingBlock),
167    /// Server tool use block
168    ServerToolUse(ServerToolUseBlock),
169    /// Search result block
170    SearchResult(SearchResultBlock),
171    /// Web search tool result block
172    WebSearchToolResult(WebSearchToolResultBlock),
173}
174
175/// Text content block
176#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct TextBlock {
178    /// The text content
179    pub text: String,
180
181    /// Cache control for this block
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub cache_control: Option<CacheControl>,
184
185    /// Citations for this text block
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub citations: Option<Vec<Citation>>,
188}
189
190/// Image content block
191#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct ImageBlock {
193    /// The image source
194    pub source: ImageSource,
195
196    /// Cache control for this block
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub cache_control: Option<CacheControl>,
199}
200
201/// Image source (base64 or URL)
202#[derive(Debug, Clone, Serialize, Deserialize)]
203#[serde(tag = "type", rename_all = "snake_case")]
204pub enum ImageSource {
205    Base64 { media_type: String, data: String },
206    Url { url: String },
207}
208
209/// Document content block
210#[derive(Debug, Clone, Serialize, Deserialize)]
211pub struct DocumentBlock {
212    /// The document source
213    pub source: DocumentSource,
214
215    /// Cache control for this block
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub cache_control: Option<CacheControl>,
218
219    /// Optional title for the document
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub title: Option<String>,
222
223    /// Optional context for the document
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub context: Option<String>,
226
227    /// Citations configuration
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub citations: Option<CitationsConfig>,
230}
231
232/// Document source (base64, text, or URL)
233#[derive(Debug, Clone, Serialize, Deserialize)]
234#[serde(tag = "type", rename_all = "snake_case")]
235pub enum DocumentSource {
236    Base64 { media_type: String, data: String },
237    Text { data: String },
238    Url { url: String },
239    Content { content: Vec<InputContentBlock> },
240}
241
242/// Tool use block (in assistant messages)
243#[derive(Debug, Clone, Serialize, Deserialize)]
244pub struct ToolUseBlock {
245    /// Unique identifier for this tool use
246    pub id: String,
247
248    /// Name of the tool being used
249    pub name: String,
250
251    /// Input arguments for the tool
252    pub input: Value,
253
254    /// Cache control for this block
255    #[serde(skip_serializing_if = "Option::is_none")]
256    pub cache_control: Option<CacheControl>,
257}
258
259/// Tool result block (in user messages)
260#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct ToolResultBlock {
262    /// The ID of the tool use this is a result for
263    pub tool_use_id: String,
264
265    /// The result content (string or blocks)
266    #[serde(skip_serializing_if = "Option::is_none")]
267    pub content: Option<ToolResultContent>,
268
269    /// Whether this result indicates an error
270    #[serde(skip_serializing_if = "Option::is_none")]
271    pub is_error: Option<bool>,
272
273    /// Cache control for this block
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub cache_control: Option<CacheControl>,
276}
277
278/// Tool result content (string or blocks)
279#[derive(Debug, Clone, Serialize, Deserialize)]
280#[serde(untagged)]
281pub enum ToolResultContent {
282    String(String),
283    Blocks(Vec<ToolResultContentBlock>),
284}
285
286/// Content blocks allowed in tool results
287#[derive(Debug, Clone, Serialize, Deserialize)]
288#[serde(tag = "type", rename_all = "snake_case")]
289pub enum ToolResultContentBlock {
290    Text(TextBlock),
291    Image(ImageBlock),
292    Document(DocumentBlock),
293    SearchResult(SearchResultBlock),
294}
295
296/// Thinking block
297#[derive(Debug, Clone, Serialize, Deserialize)]
298pub struct ThinkingBlock {
299    /// The thinking content
300    pub thinking: String,
301
302    /// Signature for the thinking block
303    pub signature: String,
304}
305
306/// Redacted thinking block
307#[derive(Debug, Clone, Serialize, Deserialize)]
308pub struct RedactedThinkingBlock {
309    /// The encrypted/redacted data
310    pub data: String,
311}
312
313/// Server tool use block
314#[derive(Debug, Clone, Serialize, Deserialize)]
315pub struct ServerToolUseBlock {
316    /// Unique identifier for this tool use
317    pub id: String,
318
319    /// Name of the server tool
320    pub name: String,
321
322    /// Input arguments for the tool
323    pub input: Value,
324
325    /// Cache control for this block
326    #[serde(skip_serializing_if = "Option::is_none")]
327    pub cache_control: Option<CacheControl>,
328}
329
330/// Search result block
331#[derive(Debug, Clone, Serialize, Deserialize)]
332pub struct SearchResultBlock {
333    /// Source URL or identifier
334    pub source: String,
335
336    /// Title of the search result
337    pub title: String,
338
339    /// Content of the search result
340    pub content: Vec<TextBlock>,
341
342    /// Cache control for this block
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub cache_control: Option<CacheControl>,
345
346    /// Citations configuration
347    #[serde(skip_serializing_if = "Option::is_none")]
348    pub citations: Option<CitationsConfig>,
349}
350
351/// Web search tool result block
352#[derive(Debug, Clone, Serialize, Deserialize)]
353pub struct WebSearchToolResultBlock {
354    /// The tool use ID this result is for
355    pub tool_use_id: String,
356
357    /// The search results or error
358    pub content: WebSearchToolResultContent,
359
360    /// Cache control for this block
361    #[serde(skip_serializing_if = "Option::is_none")]
362    pub cache_control: Option<CacheControl>,
363}
364
365/// Web search tool result content
366#[derive(Debug, Clone, Serialize, Deserialize)]
367#[serde(untagged)]
368pub enum WebSearchToolResultContent {
369    Results(Vec<WebSearchResultBlock>),
370    Error(WebSearchToolResultError),
371}
372
373/// Web search result block
374#[derive(Debug, Clone, Serialize, Deserialize)]
375pub struct WebSearchResultBlock {
376    /// Title of the search result
377    pub title: String,
378
379    /// URL of the search result
380    pub url: String,
381
382    /// Encrypted content
383    pub encrypted_content: String,
384
385    /// Page age (if available)
386    #[serde(skip_serializing_if = "Option::is_none")]
387    pub page_age: Option<String>,
388}
389
390/// Web search tool result error
391#[derive(Debug, Clone, Serialize, Deserialize)]
392pub struct WebSearchToolResultError {
393    #[serde(rename = "type")]
394    pub error_type: String,
395    pub error_code: WebSearchToolResultErrorCode,
396}
397
398/// Web search tool result error codes
399#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(rename_all = "snake_case")]
401pub enum WebSearchToolResultErrorCode {
402    InvalidToolInput,
403    Unavailable,
404    MaxUsesExceeded,
405    TooManyRequests,
406    QueryTooLong,
407}
408
409/// Cache control configuration
410#[derive(Debug, Clone, Serialize, Deserialize)]
411#[serde(tag = "type", rename_all = "snake_case")]
412pub enum CacheControl {
413    Ephemeral,
414}
415
416/// Citations configuration
417#[derive(Debug, Clone, Serialize, Deserialize)]
418pub struct CitationsConfig {
419    #[serde(skip_serializing_if = "Option::is_none")]
420    pub enabled: Option<bool>,
421}
422
423/// Citation types
424#[derive(Debug, Clone, Serialize, Deserialize)]
425#[serde(tag = "type", rename_all = "snake_case")]
426pub enum Citation {
427    CharLocation(CharLocationCitation),
428    PageLocation(PageLocationCitation),
429    ContentBlockLocation(ContentBlockLocationCitation),
430    WebSearchResultLocation(WebSearchResultLocationCitation),
431    SearchResultLocation(SearchResultLocationCitation),
432}
433
434/// Character location citation
435#[derive(Debug, Clone, Serialize, Deserialize)]
436pub struct CharLocationCitation {
437    pub cited_text: String,
438    pub document_index: u32,
439    pub document_title: Option<String>,
440    pub start_char_index: u32,
441    pub end_char_index: u32,
442    #[serde(skip_serializing_if = "Option::is_none")]
443    pub file_id: Option<String>,
444}
445
446/// Page location citation
447#[derive(Debug, Clone, Serialize, Deserialize)]
448pub struct PageLocationCitation {
449    pub cited_text: String,
450    pub document_index: u32,
451    pub document_title: Option<String>,
452    pub start_page_number: u32,
453    pub end_page_number: u32,
454}
455
456/// Content block location citation
457#[derive(Debug, Clone, Serialize, Deserialize)]
458pub struct ContentBlockLocationCitation {
459    pub cited_text: String,
460    pub document_index: u32,
461    pub document_title: Option<String>,
462    pub start_block_index: u32,
463    pub end_block_index: u32,
464}
465
466/// Web search result location citation
467#[derive(Debug, Clone, Serialize, Deserialize)]
468pub struct WebSearchResultLocationCitation {
469    pub cited_text: String,
470    pub url: String,
471    pub title: Option<String>,
472    pub encrypted_index: String,
473}
474
475/// Search result location citation
476#[derive(Debug, Clone, Serialize, Deserialize)]
477pub struct SearchResultLocationCitation {
478    pub cited_text: String,
479    pub search_result_index: u32,
480    pub source: String,
481    pub title: Option<String>,
482    pub start_block_index: u32,
483    pub end_block_index: u32,
484}
485
486// ============================================================================
487// Tool Definitions
488// ============================================================================
489
490/// Tool definition
491#[derive(Debug, Clone, Serialize, Deserialize)]
492#[serde(untagged)]
493pub enum Tool {
494    /// Custom tool definition
495    Custom(CustomTool),
496    /// Bash tool (computer use)
497    Bash(BashTool),
498    /// Text editor tool (computer use)
499    TextEditor(TextEditorTool),
500    /// Web search tool
501    WebSearch(WebSearchTool),
502}
503
504/// Custom tool definition
505#[derive(Debug, Clone, Serialize, Deserialize)]
506pub struct CustomTool {
507    /// Name of the tool
508    pub name: String,
509
510    /// Optional type (defaults to "custom")
511    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
512    pub tool_type: Option<String>,
513
514    /// Description of what this tool does
515    #[serde(skip_serializing_if = "Option::is_none")]
516    pub description: Option<String>,
517
518    /// JSON schema for the tool's input
519    pub input_schema: InputSchema,
520
521    /// Cache control for this tool
522    #[serde(skip_serializing_if = "Option::is_none")]
523    pub cache_control: Option<CacheControl>,
524}
525
526/// JSON Schema for tool input
527#[derive(Debug, Clone, Serialize, Deserialize)]
528pub struct InputSchema {
529    #[serde(rename = "type")]
530    pub schema_type: String,
531
532    #[serde(skip_serializing_if = "Option::is_none")]
533    pub properties: Option<HashMap<String, Value>>,
534
535    #[serde(skip_serializing_if = "Option::is_none")]
536    pub required: Option<Vec<String>>,
537
538    /// Additional properties can be stored here
539    #[serde(flatten)]
540    pub additional: HashMap<String, Value>,
541}
542
543/// Bash tool for computer use
544#[derive(Debug, Clone, Serialize, Deserialize)]
545pub struct BashTool {
546    #[serde(rename = "type")]
547    pub tool_type: String, // "bash_20250124"
548
549    pub name: String, // "bash"
550
551    #[serde(skip_serializing_if = "Option::is_none")]
552    pub cache_control: Option<CacheControl>,
553}
554
555/// Text editor tool for computer use
556#[derive(Debug, Clone, Serialize, Deserialize)]
557pub struct TextEditorTool {
558    #[serde(rename = "type")]
559    pub tool_type: String, // "text_editor_20250124", etc.
560
561    pub name: String, // "str_replace_editor"
562
563    #[serde(skip_serializing_if = "Option::is_none")]
564    pub cache_control: Option<CacheControl>,
565}
566
567/// Web search tool
568#[derive(Debug, Clone, Serialize, Deserialize)]
569pub struct WebSearchTool {
570    #[serde(rename = "type")]
571    pub tool_type: String, // "web_search_20250305"
572
573    pub name: String, // "web_search"
574
575    #[serde(skip_serializing_if = "Option::is_none")]
576    pub allowed_domains: Option<Vec<String>>,
577
578    #[serde(skip_serializing_if = "Option::is_none")]
579    pub blocked_domains: Option<Vec<String>>,
580
581    #[serde(skip_serializing_if = "Option::is_none")]
582    pub max_uses: Option<u32>,
583
584    #[serde(skip_serializing_if = "Option::is_none")]
585    pub user_location: Option<UserLocation>,
586
587    #[serde(skip_serializing_if = "Option::is_none")]
588    pub cache_control: Option<CacheControl>,
589}
590
591/// User location for web search
592#[derive(Debug, Clone, Serialize, Deserialize)]
593pub struct UserLocation {
594    #[serde(rename = "type")]
595    pub location_type: String, // "approximate"
596
597    #[serde(skip_serializing_if = "Option::is_none")]
598    pub city: Option<String>,
599
600    #[serde(skip_serializing_if = "Option::is_none")]
601    pub region: Option<String>,
602
603    #[serde(skip_serializing_if = "Option::is_none")]
604    pub country: Option<String>,
605
606    #[serde(skip_serializing_if = "Option::is_none")]
607    pub timezone: Option<String>,
608}
609
610// ============================================================================
611// Tool Choice
612// ============================================================================
613
614/// How the model should use the provided tools
615#[derive(Debug, Clone, Serialize, Deserialize)]
616#[serde(tag = "type", rename_all = "snake_case")]
617pub enum ToolChoice {
618    /// The model will automatically decide whether to use tools
619    Auto {
620        #[serde(skip_serializing_if = "Option::is_none")]
621        disable_parallel_tool_use: Option<bool>,
622    },
623    /// The model will use any available tools
624    Any {
625        #[serde(skip_serializing_if = "Option::is_none")]
626        disable_parallel_tool_use: Option<bool>,
627    },
628    /// The model will use the specified tool
629    Tool {
630        name: String,
631        #[serde(skip_serializing_if = "Option::is_none")]
632        disable_parallel_tool_use: Option<bool>,
633    },
634    /// The model will not use tools
635    None,
636}
637
638// ============================================================================
639// Thinking Configuration
640// ============================================================================
641
642/// Configuration for extended thinking
643#[derive(Debug, Clone, Serialize, Deserialize)]
644#[serde(tag = "type", rename_all = "snake_case")]
645pub enum ThinkingConfig {
646    /// Enable extended thinking
647    Enabled {
648        /// Budget in tokens for thinking (minimum 1024)
649        budget_tokens: u32,
650    },
651    /// Disable extended thinking
652    Disabled,
653}
654
655// ============================================================================
656// Response Types
657// ============================================================================
658
659/// Response message from the API
660#[derive(Debug, Clone, Serialize, Deserialize)]
661pub struct Message {
662    /// Unique object identifier
663    pub id: String,
664
665    /// Object type (always "message")
666    #[serde(rename = "type")]
667    pub message_type: String,
668
669    /// Conversational role (always "assistant")
670    pub role: String,
671
672    /// Content generated by the model
673    pub content: Vec<ContentBlock>,
674
675    /// The model that generated the message
676    pub model: String,
677
678    /// The reason the model stopped generating
679    pub stop_reason: Option<StopReason>,
680
681    /// Which custom stop sequence was generated (if any)
682    pub stop_sequence: Option<String>,
683
684    /// Billing and rate-limit usage
685    pub usage: Usage,
686}
687
688/// Output content block types
689#[derive(Debug, Clone, Serialize, Deserialize)]
690#[serde(tag = "type", rename_all = "snake_case")]
691pub enum ContentBlock {
692    /// Text content
693    Text {
694        text: String,
695        #[serde(skip_serializing_if = "Option::is_none")]
696        citations: Option<Vec<Citation>>,
697    },
698    /// Tool use by the model
699    ToolUse {
700        id: String,
701        name: String,
702        input: Value,
703    },
704    /// Thinking content
705    Thinking { thinking: String, signature: String },
706    /// Redacted thinking content
707    RedactedThinking { data: String },
708    /// Server tool use
709    ServerToolUse {
710        id: String,
711        name: String,
712        input: Value,
713    },
714    /// Web search tool result
715    WebSearchToolResult {
716        tool_use_id: String,
717        content: WebSearchToolResultContent,
718    },
719}
720
721/// Stop reasons
722#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
723#[serde(rename_all = "snake_case")]
724pub enum StopReason {
725    /// The model reached a natural stopping point
726    EndTurn,
727    /// We exceeded the requested max_tokens
728    MaxTokens,
729    /// One of the custom stop_sequences was generated
730    StopSequence,
731    /// The model invoked one or more tools
732    ToolUse,
733    /// We paused a long-running turn
734    PauseTurn,
735    /// Streaming classifiers intervened
736    Refusal,
737}
738
739/// Billing and rate-limit usage
740#[derive(Debug, Clone, Serialize, Deserialize)]
741pub struct Usage {
742    /// The number of input tokens used
743    pub input_tokens: u32,
744
745    /// The number of output tokens used
746    pub output_tokens: u32,
747
748    /// The number of input tokens used to create the cache entry
749    #[serde(skip_serializing_if = "Option::is_none")]
750    pub cache_creation_input_tokens: Option<u32>,
751
752    /// The number of input tokens read from the cache
753    #[serde(skip_serializing_if = "Option::is_none")]
754    pub cache_read_input_tokens: Option<u32>,
755
756    /// Breakdown of cached tokens by TTL
757    #[serde(skip_serializing_if = "Option::is_none")]
758    pub cache_creation: Option<CacheCreation>,
759
760    /// Server tool usage information
761    #[serde(skip_serializing_if = "Option::is_none")]
762    pub server_tool_use: Option<ServerToolUsage>,
763
764    /// Service tier used for the request
765    #[serde(skip_serializing_if = "Option::is_none")]
766    pub service_tier: Option<String>,
767}
768
769/// Cache creation breakdown
770#[derive(Debug, Clone, Serialize, Deserialize)]
771pub struct CacheCreation {
772    #[serde(flatten)]
773    pub tokens_by_ttl: HashMap<String, u32>,
774}
775
776/// Server tool usage information
777#[derive(Debug, Clone, Serialize, Deserialize)]
778pub struct ServerToolUsage {
779    pub web_search_requests: u32,
780}
781
782// ============================================================================
783// Streaming Event Types
784// ============================================================================
785
786/// Server-sent event wrapper
787#[derive(Debug, Clone, Serialize, Deserialize)]
788#[serde(tag = "type", rename_all = "snake_case")]
789pub enum MessageStreamEvent {
790    /// Start of a new message
791    MessageStart { message: Message },
792    /// Update to a message
793    MessageDelta {
794        delta: MessageDelta,
795        usage: MessageDeltaUsage,
796    },
797    /// End of a message
798    MessageStop,
799    /// Start of a content block
800    ContentBlockStart {
801        index: u32,
802        content_block: ContentBlock,
803    },
804    /// Update to a content block
805    ContentBlockDelta {
806        index: u32,
807        delta: ContentBlockDelta,
808    },
809    /// End of a content block
810    ContentBlockStop { index: u32 },
811    /// Ping event (for keep-alive)
812    Ping,
813    /// Error event
814    Error { error: ErrorResponse },
815}
816
817/// Message delta for streaming updates
818#[derive(Debug, Clone, Serialize, Deserialize)]
819pub struct MessageDelta {
820    #[serde(skip_serializing_if = "Option::is_none")]
821    pub stop_reason: Option<StopReason>,
822
823    #[serde(skip_serializing_if = "Option::is_none")]
824    pub stop_sequence: Option<String>,
825}
826
827/// Usage delta for streaming updates
828#[derive(Debug, Clone, Serialize, Deserialize)]
829pub struct MessageDeltaUsage {
830    pub output_tokens: u32,
831
832    #[serde(skip_serializing_if = "Option::is_none")]
833    pub input_tokens: Option<u32>,
834
835    #[serde(skip_serializing_if = "Option::is_none")]
836    pub cache_creation_input_tokens: Option<u32>,
837
838    #[serde(skip_serializing_if = "Option::is_none")]
839    pub cache_read_input_tokens: Option<u32>,
840
841    #[serde(skip_serializing_if = "Option::is_none")]
842    pub server_tool_use: Option<ServerToolUsage>,
843}
844
845/// Content block delta for streaming updates
846#[derive(Debug, Clone, Serialize, Deserialize)]
847#[serde(tag = "type", rename_all = "snake_case")]
848pub enum ContentBlockDelta {
849    /// Text delta
850    TextDelta { text: String },
851    /// JSON input delta (for tool use)
852    InputJsonDelta { partial_json: String },
853    /// Thinking delta
854    ThinkingDelta { thinking: String },
855    /// Signature delta
856    SignatureDelta { signature: String },
857    /// Citations delta
858    CitationsDelta { citation: Citation },
859}
860
861// ============================================================================
862// Error Types
863// ============================================================================
864
865/// Error response
866#[derive(Debug, Clone, Serialize, Deserialize)]
867pub struct ErrorResponse {
868    #[serde(rename = "type")]
869    pub error_type: String,
870
871    pub message: String,
872}
873
874/// API error types
875#[derive(Debug, Clone, Serialize, Deserialize)]
876#[serde(tag = "type", rename_all = "snake_case")]
877pub enum ApiError {
878    InvalidRequestError { message: String },
879    AuthenticationError { message: String },
880    BillingError { message: String },
881    PermissionError { message: String },
882    NotFoundError { message: String },
883    RateLimitError { message: String },
884    TimeoutError { message: String },
885    ApiError { message: String },
886    OverloadedError { message: String },
887}
888
889// ============================================================================
890// Count Tokens Types
891// ============================================================================
892
893/// Request to count tokens in a message
894#[derive(Debug, Clone, Serialize, Deserialize)]
895pub struct CountMessageTokensRequest {
896    /// The model to use for token counting
897    pub model: String,
898
899    /// Input messages
900    pub messages: Vec<InputMessage>,
901
902    /// System prompt
903    #[serde(skip_serializing_if = "Option::is_none")]
904    pub system: Option<SystemContent>,
905
906    /// Thinking configuration
907    #[serde(skip_serializing_if = "Option::is_none")]
908    pub thinking: Option<ThinkingConfig>,
909
910    /// Tool choice
911    #[serde(skip_serializing_if = "Option::is_none")]
912    pub tool_choice: Option<ToolChoice>,
913
914    /// Tool definitions
915    #[serde(skip_serializing_if = "Option::is_none")]
916    pub tools: Option<Vec<Tool>>,
917}
918
919/// Response from token counting
920#[derive(Debug, Clone, Serialize, Deserialize)]
921pub struct CountMessageTokensResponse {
922    pub input_tokens: u32,
923}
924
925// ============================================================================
926// Model Info Types
927// ============================================================================
928
929/// Model information
930#[derive(Debug, Clone, Serialize, Deserialize)]
931pub struct ModelInfo {
932    /// Object type (always "model")
933    #[serde(rename = "type")]
934    pub model_type: String,
935
936    /// Model ID
937    pub id: String,
938
939    /// Display name
940    pub display_name: String,
941
942    /// When the model was created
943    pub created_at: String,
944}
945
946/// List of models response
947#[derive(Debug, Clone, Serialize, Deserialize)]
948pub struct ListModelsResponse {
949    pub data: Vec<ModelInfo>,
950    pub has_more: bool,
951    pub first_id: Option<String>,
952    pub last_id: Option<String>,
953}
954
955// ============================================================================
956// Beta Features - Container & MCP Configuration
957// ============================================================================
958
959/// Container configuration for code execution (beta)
960#[derive(Debug, Clone, Serialize, Deserialize)]
961pub struct ContainerConfig {
962    /// Container ID for reuse across requests
963    #[serde(skip_serializing_if = "Option::is_none")]
964    pub id: Option<String>,
965
966    /// Skills to be loaded in the container
967    #[serde(skip_serializing_if = "Option::is_none")]
968    pub skills: Option<Vec<String>>,
969}
970
971/// MCP server configuration (beta)
972#[derive(Debug, Clone, Serialize, Deserialize)]
973pub struct McpServerConfig {
974    /// Name of the MCP server
975    pub name: String,
976
977    /// MCP server URL
978    pub url: String,
979
980    /// Authorization token (if required)
981    #[serde(skip_serializing_if = "Option::is_none")]
982    pub authorization_token: Option<String>,
983
984    /// Tool configuration for this server
985    #[serde(skip_serializing_if = "Option::is_none")]
986    pub tool_configuration: Option<McpToolConfiguration>,
987}
988
989/// MCP tool configuration
990#[derive(Debug, Clone, Serialize, Deserialize)]
991pub struct McpToolConfiguration {
992    /// Whether to allow all tools
993    #[serde(skip_serializing_if = "Option::is_none")]
994    pub enabled: Option<bool>,
995
996    /// Allowed tool names
997    #[serde(skip_serializing_if = "Option::is_none")]
998    pub allowed_tools: Option<Vec<String>>,
999}
1000
1001// ============================================================================
1002// Beta Features - MCP Tool Types
1003// ============================================================================
1004
1005/// MCP tool use block (beta) - for assistant messages
1006#[derive(Debug, Clone, Serialize, Deserialize)]
1007pub struct McpToolUseBlock {
1008    /// Unique identifier for this tool use
1009    pub id: String,
1010
1011    /// Name of the tool being used
1012    pub name: String,
1013
1014    /// Name of the MCP server
1015    pub server_name: String,
1016
1017    /// Input arguments for the tool
1018    pub input: Value,
1019
1020    /// Cache control for this block
1021    #[serde(skip_serializing_if = "Option::is_none")]
1022    pub cache_control: Option<CacheControl>,
1023}
1024
1025/// MCP tool result block (beta) - for user messages
1026#[derive(Debug, Clone, Serialize, Deserialize)]
1027pub struct McpToolResultBlock {
1028    /// The ID of the tool use this is a result for
1029    pub tool_use_id: String,
1030
1031    /// The result content
1032    #[serde(skip_serializing_if = "Option::is_none")]
1033    pub content: Option<ToolResultContent>,
1034
1035    /// Whether this result indicates an error
1036    #[serde(skip_serializing_if = "Option::is_none")]
1037    pub is_error: Option<bool>,
1038
1039    /// Cache control for this block
1040    #[serde(skip_serializing_if = "Option::is_none")]
1041    pub cache_control: Option<CacheControl>,
1042}
1043
1044/// MCP toolset definition (beta)
1045#[derive(Debug, Clone, Serialize, Deserialize)]
1046pub struct McpToolset {
1047    #[serde(rename = "type")]
1048    pub toolset_type: String, // "mcp_toolset"
1049
1050    /// Name of the MCP server to configure tools for
1051    pub mcp_server_name: String,
1052
1053    /// Default configuration applied to all tools from this server
1054    #[serde(skip_serializing_if = "Option::is_none")]
1055    pub default_config: Option<McpToolDefaultConfig>,
1056
1057    /// Configuration overrides for specific tools
1058    #[serde(skip_serializing_if = "Option::is_none")]
1059    pub configs: Option<HashMap<String, McpToolConfig>>,
1060
1061    /// Cache control for this toolset
1062    #[serde(skip_serializing_if = "Option::is_none")]
1063    pub cache_control: Option<CacheControl>,
1064}
1065
1066/// Default configuration for MCP tools
1067#[derive(Debug, Clone, Serialize, Deserialize)]
1068pub struct McpToolDefaultConfig {
1069    /// Whether tools are enabled
1070    #[serde(skip_serializing_if = "Option::is_none")]
1071    pub enabled: Option<bool>,
1072
1073    /// Whether to defer loading
1074    #[serde(skip_serializing_if = "Option::is_none")]
1075    pub defer_loading: Option<bool>,
1076}
1077
1078/// Per-tool MCP configuration
1079#[derive(Debug, Clone, Serialize, Deserialize)]
1080pub struct McpToolConfig {
1081    /// Whether this tool is enabled
1082    #[serde(skip_serializing_if = "Option::is_none")]
1083    pub enabled: Option<bool>,
1084
1085    /// Whether to defer loading
1086    #[serde(skip_serializing_if = "Option::is_none")]
1087    pub defer_loading: Option<bool>,
1088}
1089
1090// ============================================================================
1091// Beta Features - Code Execution Types
1092// ============================================================================
1093
1094/// Code execution tool (beta)
1095#[derive(Debug, Clone, Serialize, Deserialize)]
1096pub struct CodeExecutionTool {
1097    #[serde(rename = "type")]
1098    pub tool_type: String, // "code_execution_20250522" or "code_execution_20250825"
1099
1100    pub name: String, // "code_execution"
1101
1102    /// Allowed callers for this tool
1103    #[serde(skip_serializing_if = "Option::is_none")]
1104    pub allowed_callers: Option<Vec<String>>,
1105
1106    /// Whether to defer loading
1107    #[serde(skip_serializing_if = "Option::is_none")]
1108    pub defer_loading: Option<bool>,
1109
1110    /// Whether to use strict mode
1111    #[serde(skip_serializing_if = "Option::is_none")]
1112    pub strict: Option<bool>,
1113
1114    /// Cache control for this tool
1115    #[serde(skip_serializing_if = "Option::is_none")]
1116    pub cache_control: Option<CacheControl>,
1117}
1118
1119/// Code execution result block (beta)
1120#[derive(Debug, Clone, Serialize, Deserialize)]
1121pub struct CodeExecutionResultBlock {
1122    /// Stdout output
1123    pub stdout: String,
1124
1125    /// Stderr output
1126    pub stderr: String,
1127
1128    /// Return code
1129    pub return_code: i32,
1130
1131    /// Output files
1132    pub content: Vec<CodeExecutionOutputBlock>,
1133}
1134
1135/// Code execution output file reference
1136#[derive(Debug, Clone, Serialize, Deserialize)]
1137pub struct CodeExecutionOutputBlock {
1138    #[serde(rename = "type")]
1139    pub block_type: String, // "code_execution_output"
1140
1141    /// File ID
1142    pub file_id: String,
1143}
1144
1145/// Code execution tool result block (beta)
1146#[derive(Debug, Clone, Serialize, Deserialize)]
1147pub struct CodeExecutionToolResultBlock {
1148    /// The ID of the tool use this is a result for
1149    pub tool_use_id: String,
1150
1151    /// The result content (success or error)
1152    pub content: CodeExecutionToolResultContent,
1153
1154    /// Cache control for this block
1155    #[serde(skip_serializing_if = "Option::is_none")]
1156    pub cache_control: Option<CacheControl>,
1157}
1158
1159/// Code execution tool result content
1160#[derive(Debug, Clone, Serialize, Deserialize)]
1161#[serde(untagged)]
1162pub enum CodeExecutionToolResultContent {
1163    Success(CodeExecutionResultBlock),
1164    Error(CodeExecutionToolResultError),
1165}
1166
1167/// Code execution tool result error
1168#[derive(Debug, Clone, Serialize, Deserialize)]
1169pub struct CodeExecutionToolResultError {
1170    #[serde(rename = "type")]
1171    pub error_type: String, // "code_execution_tool_result_error"
1172
1173    pub error_code: CodeExecutionToolResultErrorCode,
1174}
1175
1176/// Code execution error codes
1177#[derive(Debug, Clone, Serialize, Deserialize)]
1178#[serde(rename_all = "snake_case")]
1179pub enum CodeExecutionToolResultErrorCode {
1180    Unavailable,
1181    CodeExecutionExceededTimeout,
1182    ContainerExpired,
1183    InvalidToolInput,
1184}
1185
1186/// Bash code execution result block (beta)
1187#[derive(Debug, Clone, Serialize, Deserialize)]
1188pub struct BashCodeExecutionResultBlock {
1189    /// Stdout output
1190    pub stdout: String,
1191
1192    /// Stderr output
1193    pub stderr: String,
1194
1195    /// Return code
1196    pub return_code: i32,
1197
1198    /// Output files
1199    pub content: Vec<BashCodeExecutionOutputBlock>,
1200}
1201
1202/// Bash code execution output file reference
1203#[derive(Debug, Clone, Serialize, Deserialize)]
1204pub struct BashCodeExecutionOutputBlock {
1205    #[serde(rename = "type")]
1206    pub block_type: String, // "bash_code_execution_output"
1207
1208    /// File ID
1209    pub file_id: String,
1210}
1211
1212/// Bash code execution tool result block (beta)
1213#[derive(Debug, Clone, Serialize, Deserialize)]
1214pub struct BashCodeExecutionToolResultBlock {
1215    /// The ID of the tool use this is a result for
1216    pub tool_use_id: String,
1217
1218    /// The result content (success or error)
1219    pub content: BashCodeExecutionToolResultContent,
1220
1221    /// Cache control for this block
1222    #[serde(skip_serializing_if = "Option::is_none")]
1223    pub cache_control: Option<CacheControl>,
1224}
1225
1226/// Bash code execution tool result content
1227#[derive(Debug, Clone, Serialize, Deserialize)]
1228#[serde(untagged)]
1229pub enum BashCodeExecutionToolResultContent {
1230    Success(BashCodeExecutionResultBlock),
1231    Error(BashCodeExecutionToolResultError),
1232}
1233
1234/// Bash code execution tool result error
1235#[derive(Debug, Clone, Serialize, Deserialize)]
1236pub struct BashCodeExecutionToolResultError {
1237    #[serde(rename = "type")]
1238    pub error_type: String, // "bash_code_execution_tool_result_error"
1239
1240    pub error_code: BashCodeExecutionToolResultErrorCode,
1241}
1242
1243/// Bash code execution error codes
1244#[derive(Debug, Clone, Serialize, Deserialize)]
1245#[serde(rename_all = "snake_case")]
1246pub enum BashCodeExecutionToolResultErrorCode {
1247    Unavailable,
1248    CodeExecutionExceededTimeout,
1249    ContainerExpired,
1250    InvalidToolInput,
1251}
1252
1253/// Text editor code execution tool result block (beta)
1254#[derive(Debug, Clone, Serialize, Deserialize)]
1255pub struct TextEditorCodeExecutionToolResultBlock {
1256    /// The ID of the tool use this is a result for
1257    pub tool_use_id: String,
1258
1259    /// The result content
1260    pub content: TextEditorCodeExecutionToolResultContent,
1261
1262    /// Cache control for this block
1263    #[serde(skip_serializing_if = "Option::is_none")]
1264    pub cache_control: Option<CacheControl>,
1265}
1266
1267/// Text editor code execution result content
1268#[derive(Debug, Clone, Serialize, Deserialize)]
1269#[serde(untagged)]
1270pub enum TextEditorCodeExecutionToolResultContent {
1271    CreateResult(TextEditorCodeExecutionCreateResultBlock),
1272    StrReplaceResult(TextEditorCodeExecutionStrReplaceResultBlock),
1273    ViewResult(TextEditorCodeExecutionViewResultBlock),
1274    Error(TextEditorCodeExecutionToolResultError),
1275}
1276
1277/// Text editor create result block
1278#[derive(Debug, Clone, Serialize, Deserialize)]
1279pub struct TextEditorCodeExecutionCreateResultBlock {
1280    #[serde(rename = "type")]
1281    pub block_type: String, // "text_editor_code_execution_create_result"
1282}
1283
1284/// Text editor str_replace result block
1285#[derive(Debug, Clone, Serialize, Deserialize)]
1286pub struct TextEditorCodeExecutionStrReplaceResultBlock {
1287    #[serde(rename = "type")]
1288    pub block_type: String, // "text_editor_code_execution_str_replace_result"
1289
1290    /// Snippet of content around the replacement
1291    #[serde(skip_serializing_if = "Option::is_none")]
1292    pub snippet: Option<String>,
1293}
1294
1295/// Text editor view result block
1296#[derive(Debug, Clone, Serialize, Deserialize)]
1297pub struct TextEditorCodeExecutionViewResultBlock {
1298    #[serde(rename = "type")]
1299    pub block_type: String, // "text_editor_code_execution_view_result"
1300
1301    /// Content of the viewed file
1302    pub content: String,
1303}
1304
1305/// Text editor code execution tool result error
1306#[derive(Debug, Clone, Serialize, Deserialize)]
1307pub struct TextEditorCodeExecutionToolResultError {
1308    #[serde(rename = "type")]
1309    pub error_type: String,
1310
1311    pub error_code: TextEditorCodeExecutionToolResultErrorCode,
1312}
1313
1314/// Text editor code execution error codes
1315#[derive(Debug, Clone, Serialize, Deserialize)]
1316#[serde(rename_all = "snake_case")]
1317pub enum TextEditorCodeExecutionToolResultErrorCode {
1318    Unavailable,
1319    InvalidToolInput,
1320    FileNotFound,
1321    ContainerExpired,
1322}
1323
1324// ============================================================================
1325// Beta Features - Web Fetch Types
1326// ============================================================================
1327
1328/// Web fetch tool (beta)
1329#[derive(Debug, Clone, Serialize, Deserialize)]
1330pub struct WebFetchTool {
1331    #[serde(rename = "type")]
1332    pub tool_type: String, // "web_fetch_20250305" or similar
1333
1334    pub name: String, // "web_fetch"
1335
1336    /// Allowed callers for this tool
1337    #[serde(skip_serializing_if = "Option::is_none")]
1338    pub allowed_callers: Option<Vec<String>>,
1339
1340    /// Maximum number of uses
1341    #[serde(skip_serializing_if = "Option::is_none")]
1342    pub max_uses: Option<u32>,
1343
1344    /// Cache control for this tool
1345    #[serde(skip_serializing_if = "Option::is_none")]
1346    pub cache_control: Option<CacheControl>,
1347}
1348
1349/// Web fetch result block (beta)
1350#[derive(Debug, Clone, Serialize, Deserialize)]
1351pub struct WebFetchResultBlock {
1352    #[serde(rename = "type")]
1353    pub block_type: String, // "web_fetch_result"
1354
1355    /// The URL that was fetched
1356    pub url: String,
1357
1358    /// The document content
1359    pub content: DocumentBlock,
1360
1361    /// When the content was retrieved
1362    #[serde(skip_serializing_if = "Option::is_none")]
1363    pub retrieved_at: Option<String>,
1364}
1365
1366/// Web fetch tool result block (beta)
1367#[derive(Debug, Clone, Serialize, Deserialize)]
1368pub struct WebFetchToolResultBlock {
1369    /// The ID of the tool use this is a result for
1370    pub tool_use_id: String,
1371
1372    /// The result content (success or error)
1373    pub content: WebFetchToolResultContent,
1374
1375    /// Cache control for this block
1376    #[serde(skip_serializing_if = "Option::is_none")]
1377    pub cache_control: Option<CacheControl>,
1378}
1379
1380/// Web fetch tool result content
1381#[derive(Debug, Clone, Serialize, Deserialize)]
1382#[serde(untagged)]
1383pub enum WebFetchToolResultContent {
1384    Success(WebFetchResultBlock),
1385    Error(WebFetchToolResultError),
1386}
1387
1388/// Web fetch tool result error
1389#[derive(Debug, Clone, Serialize, Deserialize)]
1390pub struct WebFetchToolResultError {
1391    #[serde(rename = "type")]
1392    pub error_type: String, // "web_fetch_tool_result_error"
1393
1394    pub error_code: WebFetchToolResultErrorCode,
1395}
1396
1397/// Web fetch error codes
1398#[derive(Debug, Clone, Serialize, Deserialize)]
1399#[serde(rename_all = "snake_case")]
1400pub enum WebFetchToolResultErrorCode {
1401    InvalidToolInput,
1402    Unavailable,
1403    MaxUsesExceeded,
1404    TooManyRequests,
1405    UrlNotAllowed,
1406    FetchFailed,
1407    ContentTooLarge,
1408}
1409
1410// ============================================================================
1411// Beta Features - Tool Search Types
1412// ============================================================================
1413
1414/// Tool search tool (beta)
1415#[derive(Debug, Clone, Serialize, Deserialize)]
1416pub struct ToolSearchTool {
1417    #[serde(rename = "type")]
1418    pub tool_type: String, // "tool_search_tool_regex" or "tool_search_tool_bm25"
1419
1420    pub name: String,
1421
1422    /// Allowed callers for this tool
1423    #[serde(skip_serializing_if = "Option::is_none")]
1424    pub allowed_callers: Option<Vec<String>>,
1425
1426    /// Cache control for this tool
1427    #[serde(skip_serializing_if = "Option::is_none")]
1428    pub cache_control: Option<CacheControl>,
1429}
1430
1431/// Tool reference block (beta) - returned by tool search
1432#[derive(Debug, Clone, Serialize, Deserialize)]
1433pub struct ToolReferenceBlock {
1434    #[serde(rename = "type")]
1435    pub block_type: String, // "tool_reference"
1436
1437    /// Tool name
1438    pub tool_name: String,
1439
1440    /// Tool description
1441    #[serde(skip_serializing_if = "Option::is_none")]
1442    pub description: Option<String>,
1443}
1444
1445/// Tool search result block (beta)
1446#[derive(Debug, Clone, Serialize, Deserialize)]
1447pub struct ToolSearchResultBlock {
1448    #[serde(rename = "type")]
1449    pub block_type: String, // "tool_search_tool_search_result"
1450
1451    /// Tool name
1452    pub tool_name: String,
1453
1454    /// Relevance score
1455    #[serde(skip_serializing_if = "Option::is_none")]
1456    pub score: Option<f64>,
1457}
1458
1459/// Tool search tool result block (beta)
1460#[derive(Debug, Clone, Serialize, Deserialize)]
1461pub struct ToolSearchToolResultBlock {
1462    /// The ID of the tool use this is a result for
1463    pub tool_use_id: String,
1464
1465    /// The search results
1466    pub content: Vec<ToolSearchResultBlock>,
1467
1468    /// Cache control for this block
1469    #[serde(skip_serializing_if = "Option::is_none")]
1470    pub cache_control: Option<CacheControl>,
1471}
1472
1473// ============================================================================
1474// Beta Features - Container Upload Types
1475// ============================================================================
1476
1477/// Container upload block (beta)
1478#[derive(Debug, Clone, Serialize, Deserialize)]
1479pub struct ContainerUploadBlock {
1480    #[serde(rename = "type")]
1481    pub block_type: String, // "container_upload"
1482
1483    /// File ID
1484    pub file_id: String,
1485
1486    /// File name
1487    pub file_name: String,
1488
1489    /// File path in container
1490    #[serde(skip_serializing_if = "Option::is_none")]
1491    pub file_path: Option<String>,
1492}
1493
1494// ============================================================================
1495// Beta Features - Memory Tool Types
1496// ============================================================================
1497
1498/// Memory tool (beta)
1499#[derive(Debug, Clone, Serialize, Deserialize)]
1500pub struct MemoryTool {
1501    #[serde(rename = "type")]
1502    pub tool_type: String, // "memory_20250818"
1503
1504    pub name: String, // "memory"
1505
1506    /// Allowed callers for this tool
1507    #[serde(skip_serializing_if = "Option::is_none")]
1508    pub allowed_callers: Option<Vec<String>>,
1509
1510    /// Whether to defer loading
1511    #[serde(skip_serializing_if = "Option::is_none")]
1512    pub defer_loading: Option<bool>,
1513
1514    /// Whether to use strict mode
1515    #[serde(skip_serializing_if = "Option::is_none")]
1516    pub strict: Option<bool>,
1517
1518    /// Input examples
1519    #[serde(skip_serializing_if = "Option::is_none")]
1520    pub input_examples: Option<Vec<Value>>,
1521
1522    /// Cache control for this tool
1523    #[serde(skip_serializing_if = "Option::is_none")]
1524    pub cache_control: Option<CacheControl>,
1525}
1526
1527// ============================================================================
1528// Beta Features - Computer Use Tool Types
1529// ============================================================================
1530
1531/// Computer use tool (beta)
1532#[derive(Debug, Clone, Serialize, Deserialize)]
1533pub struct ComputerUseTool {
1534    #[serde(rename = "type")]
1535    pub tool_type: String, // "computer_20241022" or "computer_20250124"
1536
1537    pub name: String, // "computer"
1538
1539    /// Display width
1540    pub display_width_px: u32,
1541
1542    /// Display height
1543    pub display_height_px: u32,
1544
1545    /// Display number (optional)
1546    #[serde(skip_serializing_if = "Option::is_none")]
1547    pub display_number: Option<u32>,
1548
1549    /// Allowed callers for this tool
1550    #[serde(skip_serializing_if = "Option::is_none")]
1551    pub allowed_callers: Option<Vec<String>>,
1552
1553    /// Cache control for this tool
1554    #[serde(skip_serializing_if = "Option::is_none")]
1555    pub cache_control: Option<CacheControl>,
1556}
1557
1558// ============================================================================
1559// Beta Features - Extended Input Content Block Enum
1560// ============================================================================
1561
1562/// Beta input content block types (extends InputContentBlock)
1563#[derive(Debug, Clone, Serialize, Deserialize)]
1564#[serde(tag = "type", rename_all = "snake_case")]
1565pub enum BetaInputContentBlock {
1566    // Standard types
1567    Text(TextBlock),
1568    Image(ImageBlock),
1569    Document(DocumentBlock),
1570    ToolUse(ToolUseBlock),
1571    ToolResult(ToolResultBlock),
1572    Thinking(ThinkingBlock),
1573    RedactedThinking(RedactedThinkingBlock),
1574    ServerToolUse(ServerToolUseBlock),
1575    SearchResult(SearchResultBlock),
1576    WebSearchToolResult(WebSearchToolResultBlock),
1577
1578    // Beta MCP types
1579    McpToolUse(McpToolUseBlock),
1580    McpToolResult(McpToolResultBlock),
1581
1582    // Beta code execution types
1583    CodeExecutionToolResult(CodeExecutionToolResultBlock),
1584    BashCodeExecutionToolResult(BashCodeExecutionToolResultBlock),
1585    TextEditorCodeExecutionToolResult(TextEditorCodeExecutionToolResultBlock),
1586
1587    // Beta web fetch types
1588    WebFetchToolResult(WebFetchToolResultBlock),
1589
1590    // Beta tool search types
1591    ToolSearchToolResult(ToolSearchToolResultBlock),
1592    ToolReference(ToolReferenceBlock),
1593
1594    // Beta container types
1595    ContainerUpload(ContainerUploadBlock),
1596}
1597
1598/// Beta output content block types (extends ContentBlock)
1599#[derive(Debug, Clone, Serialize, Deserialize)]
1600#[serde(tag = "type", rename_all = "snake_case")]
1601pub enum BetaContentBlock {
1602    // Standard types
1603    Text {
1604        text: String,
1605        #[serde(skip_serializing_if = "Option::is_none")]
1606        citations: Option<Vec<Citation>>,
1607    },
1608    ToolUse {
1609        id: String,
1610        name: String,
1611        input: Value,
1612    },
1613    Thinking {
1614        thinking: String,
1615        signature: String,
1616    },
1617    RedactedThinking {
1618        data: String,
1619    },
1620    ServerToolUse {
1621        id: String,
1622        name: String,
1623        input: Value,
1624    },
1625    WebSearchToolResult {
1626        tool_use_id: String,
1627        content: WebSearchToolResultContent,
1628    },
1629
1630    // Beta MCP types
1631    McpToolUse {
1632        id: String,
1633        name: String,
1634        server_name: String,
1635        input: Value,
1636    },
1637    McpToolResult {
1638        tool_use_id: String,
1639        #[serde(skip_serializing_if = "Option::is_none")]
1640        content: Option<ToolResultContent>,
1641        #[serde(skip_serializing_if = "Option::is_none")]
1642        is_error: Option<bool>,
1643    },
1644
1645    // Beta code execution types
1646    CodeExecutionToolResult {
1647        tool_use_id: String,
1648        content: CodeExecutionToolResultContent,
1649    },
1650    BashCodeExecutionToolResult {
1651        tool_use_id: String,
1652        content: BashCodeExecutionToolResultContent,
1653    },
1654    TextEditorCodeExecutionToolResult {
1655        tool_use_id: String,
1656        content: TextEditorCodeExecutionToolResultContent,
1657    },
1658
1659    // Beta web fetch types
1660    WebFetchToolResult {
1661        tool_use_id: String,
1662        content: WebFetchToolResultContent,
1663    },
1664
1665    // Beta tool search types
1666    ToolSearchToolResult {
1667        tool_use_id: String,
1668        content: Vec<ToolSearchResultBlock>,
1669    },
1670    ToolReference {
1671        tool_name: String,
1672        #[serde(skip_serializing_if = "Option::is_none")]
1673        description: Option<String>,
1674    },
1675
1676    // Beta container types
1677    ContainerUpload {
1678        file_id: String,
1679        file_name: String,
1680        #[serde(skip_serializing_if = "Option::is_none")]
1681        file_path: Option<String>,
1682    },
1683}
1684
1685/// Beta tool definition (extends Tool)
1686#[derive(Debug, Clone, Serialize, Deserialize)]
1687#[serde(untagged)]
1688pub enum BetaTool {
1689    // Standard tools
1690    Custom(CustomTool),
1691    Bash(BashTool),
1692    TextEditor(TextEditorTool),
1693    WebSearch(WebSearchTool),
1694
1695    // Beta tools
1696    CodeExecution(CodeExecutionTool),
1697    McpToolset(McpToolset),
1698    WebFetch(WebFetchTool),
1699    ToolSearch(ToolSearchTool),
1700    Memory(MemoryTool),
1701    ComputerUse(ComputerUseTool),
1702}
1703
1704/// Server tool names for beta features
1705#[derive(Debug, Clone, Serialize, Deserialize)]
1706#[serde(rename_all = "snake_case")]
1707pub enum BetaServerToolName {
1708    WebSearch,
1709    WebFetch,
1710    CodeExecution,
1711    BashCodeExecution,
1712    TextEditorCodeExecution,
1713    ToolSearchToolRegex,
1714    ToolSearchToolBm25,
1715}
1716
1717/// Server tool caller types (beta)
1718#[derive(Debug, Clone, Serialize, Deserialize)]
1719#[serde(tag = "type", rename_all = "snake_case")]
1720pub enum ServerToolCaller {
1721    /// Direct caller (the model itself)
1722    Direct,
1723    /// Code execution caller
1724    #[serde(rename = "code_execution_20250825")]
1725    CodeExecution20250825,
1726}