Skip to main content

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