1use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use validator::Validate;
11
12use crate::validated::Normalizable;
13
14#[serde_with::skip_serializing_none]
22#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
23pub struct CreateMessageRequest {
24 #[validate(length(min = 1, message = "model field is required and cannot be empty"))]
26 pub model: String,
27
28 #[validate(length(min = 1, message = "messages array is required and cannot be empty"))]
30 pub messages: Vec<InputMessage>,
31
32 #[validate(range(min = 1, message = "max_tokens must be greater than 0"))]
34 pub max_tokens: u32,
35
36 pub metadata: Option<Metadata>,
38
39 pub service_tier: Option<ServiceTier>,
41
42 pub stop_sequences: Option<Vec<String>>,
44
45 pub stream: Option<bool>,
47
48 pub system: Option<SystemContent>,
50
51 pub temperature: Option<f64>,
53
54 pub thinking: Option<ThinkingConfig>,
56
57 pub tool_choice: Option<ToolChoice>,
59
60 pub tools: Option<Vec<Tool>>,
62
63 pub top_k: Option<u32>,
65
66 pub top_p: Option<f64>,
68
69 pub container: Option<ContainerConfig>,
72
73 pub mcp_servers: Option<Vec<McpServerConfig>>,
75}
76
77impl Normalizable for CreateMessageRequest {
78 }
80
81impl CreateMessageRequest {
82 pub fn is_stream(&self) -> bool {
84 self.stream.unwrap_or(false)
85 }
86
87 pub fn get_model(&self) -> &str {
89 &self.model
90 }
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct Metadata {
96 #[serde(skip_serializing_if = "Option::is_none")]
98 pub user_id: Option<String>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(rename_all = "snake_case")]
104pub enum ServiceTier {
105 Auto,
106 StandardOnly,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum SystemContent {
113 String(String),
114 Blocks(Vec<TextBlock>),
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct InputMessage {
120 pub role: Role,
122
123 pub content: InputContent,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
129#[serde(rename_all = "lowercase")]
130pub enum Role {
131 User,
132 Assistant,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum InputContent {
139 String(String),
140 Blocks(Vec<InputContentBlock>),
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(tag = "type", rename_all = "snake_case")]
150pub enum InputContentBlock {
151 Text(TextBlock),
153 Image(ImageBlock),
155 Document(DocumentBlock),
157 ToolUse(ToolUseBlock),
159 ToolResult(ToolResultBlock),
161 Thinking(ThinkingBlock),
163 RedactedThinking(RedactedThinkingBlock),
165 ServerToolUse(ServerToolUseBlock),
167 SearchResult(SearchResultBlock),
169 WebSearchToolResult(WebSearchToolResultBlock),
171}
172
173#[serde_with::skip_serializing_none]
175#[derive(Debug, Clone, Serialize, Deserialize)]
176pub struct TextBlock {
177 pub text: String,
179
180 pub cache_control: Option<CacheControl>,
182
183 pub citations: Option<Vec<Citation>>,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
189pub struct ImageBlock {
190 pub source: ImageSource,
192
193 #[serde(skip_serializing_if = "Option::is_none")]
195 pub cache_control: Option<CacheControl>,
196}
197
198#[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#[serde_with::skip_serializing_none]
208#[derive(Debug, Clone, Serialize, Deserialize)]
209pub struct DocumentBlock {
210 pub source: DocumentSource,
212
213 pub cache_control: Option<CacheControl>,
215
216 pub title: Option<String>,
218
219 pub context: Option<String>,
221
222 pub citations: Option<CitationsConfig>,
224}
225
226#[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#[derive(Debug, Clone, Serialize, Deserialize)]
238pub struct ToolUseBlock {
239 pub id: String,
241
242 pub name: String,
244
245 pub input: Value,
247
248 #[serde(skip_serializing_if = "Option::is_none")]
250 pub cache_control: Option<CacheControl>,
251}
252
253#[serde_with::skip_serializing_none]
255#[derive(Debug, Clone, Serialize, Deserialize)]
256pub struct ToolResultBlock {
257 pub tool_use_id: String,
259
260 pub content: Option<ToolResultContent>,
262
263 pub is_error: Option<bool>,
265
266 pub cache_control: Option<CacheControl>,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
272#[serde(untagged)]
273pub enum ToolResultContent {
274 String(String),
275 Blocks(Vec<ToolResultContentBlock>),
276}
277
278#[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#[derive(Debug, Clone, Serialize, Deserialize)]
290pub struct ThinkingBlock {
291 pub thinking: String,
293
294 pub signature: String,
296}
297
298#[derive(Debug, Clone, Serialize, Deserialize)]
300pub struct RedactedThinkingBlock {
301 pub data: String,
303}
304
305#[derive(Debug, Clone, Serialize, Deserialize)]
307pub struct ServerToolUseBlock {
308 pub id: String,
310
311 pub name: String,
313
314 pub input: Value,
316
317 #[serde(skip_serializing_if = "Option::is_none")]
319 pub cache_control: Option<CacheControl>,
320}
321
322#[serde_with::skip_serializing_none]
324#[derive(Debug, Clone, Serialize, Deserialize)]
325pub struct SearchResultBlock {
326 pub source: String,
328
329 pub title: String,
331
332 pub content: Vec<TextBlock>,
334
335 pub cache_control: Option<CacheControl>,
337
338 pub citations: Option<CitationsConfig>,
340}
341
342#[derive(Debug, Clone, Serialize, Deserialize)]
344pub struct WebSearchToolResultBlock {
345 pub tool_use_id: String,
347
348 pub content: WebSearchToolResultContent,
350
351 #[serde(skip_serializing_if = "Option::is_none")]
353 pub cache_control: Option<CacheControl>,
354}
355
356#[derive(Debug, Clone, Serialize, Deserialize)]
358#[serde(untagged)]
359pub enum WebSearchToolResultContent {
360 Results(Vec<WebSearchResultBlock>),
361 Error(WebSearchToolResultError),
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize)]
366pub struct WebSearchResultBlock {
367 pub title: String,
369
370 pub url: String,
372
373 pub encrypted_content: String,
375
376 #[serde(skip_serializing_if = "Option::is_none")]
378 pub page_age: Option<String>,
379}
380
381#[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#[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#[derive(Debug, Clone, Serialize, Deserialize)]
402#[serde(tag = "type", rename_all = "snake_case")]
403pub enum CacheControl {
404 Ephemeral,
405}
406
407#[derive(Debug, Clone, Serialize, Deserialize)]
409pub struct CitationsConfig {
410 #[serde(skip_serializing_if = "Option::is_none")]
411 pub enabled: Option<bool>,
412}
413
414#[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#[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#[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#[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#[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#[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#[derive(Debug, Clone, Serialize, Deserialize)]
483#[serde(untagged)]
484pub enum Tool {
485 Custom(CustomTool),
487 Bash(BashTool),
489 TextEditor(TextEditorTool),
491 WebSearch(WebSearchTool),
493}
494
495#[serde_with::skip_serializing_none]
497#[derive(Debug, Clone, Serialize, Deserialize)]
498pub struct CustomTool {
499 pub name: String,
501
502 #[serde(rename = "type")]
504 pub tool_type: Option<String>,
505
506 pub description: Option<String>,
508
509 pub input_schema: InputSchema,
511
512 pub cache_control: Option<CacheControl>,
514}
515
516#[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 #[serde(flatten)]
529 pub additional: HashMap<String, Value>,
530}
531
532#[derive(Debug, Clone, Serialize, Deserialize)]
534pub struct BashTool {
535 #[serde(rename = "type")]
536 pub tool_type: String, pub name: String, #[serde(skip_serializing_if = "Option::is_none")]
541 pub cache_control: Option<CacheControl>,
542}
543
544#[derive(Debug, Clone, Serialize, Deserialize)]
546pub struct TextEditorTool {
547 #[serde(rename = "type")]
548 pub tool_type: String, pub name: String, #[serde(skip_serializing_if = "Option::is_none")]
553 pub cache_control: Option<CacheControl>,
554}
555
556#[serde_with::skip_serializing_none]
558#[derive(Debug, Clone, Serialize, Deserialize)]
559pub struct WebSearchTool {
560 #[serde(rename = "type")]
561 pub tool_type: String, pub name: String, 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#[serde_with::skip_serializing_none]
578#[derive(Debug, Clone, Serialize, Deserialize)]
579pub struct UserLocation {
580 #[serde(rename = "type")]
581 pub location_type: String, 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#[serde_with::skip_serializing_none]
598#[derive(Debug, Clone, Serialize, Deserialize)]
599#[serde(tag = "type", rename_all = "snake_case")]
600pub enum ToolChoice {
601 Auto {
603 disable_parallel_tool_use: Option<bool>,
604 },
605 Any {
607 disable_parallel_tool_use: Option<bool>,
608 },
609 Tool {
611 name: String,
612 disable_parallel_tool_use: Option<bool>,
613 },
614 None,
616}
617
618#[derive(Debug, Clone, Serialize, Deserialize)]
624#[serde(tag = "type", rename_all = "snake_case")]
625pub enum ThinkingConfig {
626 Enabled {
628 budget_tokens: u32,
630 },
631 Disabled,
633}
634
635#[derive(Debug, Clone, Serialize, Deserialize)]
641pub struct Message {
642 pub id: String,
644
645 #[serde(rename = "type")]
647 pub message_type: String,
648
649 pub role: String,
651
652 pub content: Vec<ContentBlock>,
654
655 pub model: String,
657
658 pub stop_reason: Option<StopReason>,
660
661 pub stop_sequence: Option<String>,
663
664 pub usage: Usage,
666}
667
668#[derive(Debug, Clone, Serialize, Deserialize)]
670#[serde(tag = "type", rename_all = "snake_case")]
671pub enum ContentBlock {
672 Text {
674 text: String,
675 #[serde(skip_serializing_if = "Option::is_none")]
676 citations: Option<Vec<Citation>>,
677 },
678 ToolUse {
680 id: String,
681 name: String,
682 input: Value,
683 },
684 Thinking { thinking: String, signature: String },
686 RedactedThinking { data: String },
688 ServerToolUse {
690 id: String,
691 name: String,
692 input: Value,
693 },
694 WebSearchToolResult {
696 tool_use_id: String,
697 content: WebSearchToolResultContent,
698 },
699}
700
701#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
703#[serde(rename_all = "snake_case")]
704pub enum StopReason {
705 EndTurn,
707 MaxTokens,
709 StopSequence,
711 ToolUse,
713 PauseTurn,
715 Refusal,
717}
718
719#[serde_with::skip_serializing_none]
721#[derive(Debug, Clone, Serialize, Deserialize)]
722pub struct Usage {
723 pub input_tokens: u32,
725
726 pub output_tokens: u32,
728
729 pub cache_creation_input_tokens: Option<u32>,
731
732 pub cache_read_input_tokens: Option<u32>,
734
735 pub cache_creation: Option<CacheCreation>,
737
738 pub server_tool_use: Option<ServerToolUsage>,
740
741 pub service_tier: Option<String>,
743}
744
745#[derive(Debug, Clone, Serialize, Deserialize)]
747pub struct CacheCreation {
748 #[serde(flatten)]
749 pub tokens_by_ttl: HashMap<String, u32>,
750}
751
752#[derive(Debug, Clone, Serialize, Deserialize)]
754pub struct ServerToolUsage {
755 pub web_search_requests: u32,
756}
757
758#[derive(Debug, Clone, Serialize, Deserialize)]
764#[serde(tag = "type", rename_all = "snake_case")]
765pub enum MessageStreamEvent {
766 MessageStart { message: Message },
768 MessageDelta {
770 delta: MessageDelta,
771 usage: MessageDeltaUsage,
772 },
773 MessageStop,
775 ContentBlockStart {
777 index: u32,
778 content_block: ContentBlock,
779 },
780 ContentBlockDelta {
782 index: u32,
783 delta: ContentBlockDelta,
784 },
785 ContentBlockStop { index: u32 },
787 Ping,
789 Error { error: ErrorResponse },
791}
792
793#[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#[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#[derive(Debug, Clone, Serialize, Deserialize)]
819#[serde(tag = "type", rename_all = "snake_case")]
820pub enum ContentBlockDelta {
821 TextDelta { text: String },
823 InputJsonDelta { partial_json: String },
825 ThinkingDelta { thinking: String },
827 SignatureDelta { signature: String },
829 CitationsDelta { citation: Citation },
831}
832
833#[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#[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#[serde_with::skip_serializing_none]
867#[derive(Debug, Clone, Serialize, Deserialize)]
868pub struct CountMessageTokensRequest {
869 pub model: String,
871
872 pub messages: Vec<InputMessage>,
874
875 pub system: Option<SystemContent>,
877
878 pub thinking: Option<ThinkingConfig>,
880
881 pub tool_choice: Option<ToolChoice>,
883
884 pub tools: Option<Vec<Tool>>,
886}
887
888#[derive(Debug, Clone, Serialize, Deserialize)]
890pub struct CountMessageTokensResponse {
891 pub input_tokens: u32,
892}
893
894#[derive(Debug, Clone, Serialize, Deserialize)]
900pub struct ModelInfo {
901 #[serde(rename = "type")]
903 pub model_type: String,
904
905 pub id: String,
907
908 pub display_name: String,
910
911 pub created_at: String,
913}
914
915#[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#[serde_with::skip_serializing_none]
930#[derive(Debug, Clone, Serialize, Deserialize)]
931pub struct ContainerConfig {
932 pub id: Option<String>,
934
935 pub skills: Option<Vec<String>>,
937}
938
939#[serde_with::skip_serializing_none]
941#[derive(Debug, Clone, Serialize, Deserialize)]
942pub struct McpServerConfig {
943 pub name: String,
945
946 pub url: String,
948
949 pub authorization_token: Option<String>,
951
952 pub tool_configuration: Option<McpToolConfiguration>,
954}
955
956#[serde_with::skip_serializing_none]
958#[derive(Debug, Clone, Serialize, Deserialize)]
959pub struct McpToolConfiguration {
960 pub enabled: Option<bool>,
962
963 pub allowed_tools: Option<Vec<String>>,
965}
966
967#[derive(Debug, Clone, Serialize, Deserialize)]
973pub struct McpToolUseBlock {
974 pub id: String,
976
977 pub name: String,
979
980 pub server_name: String,
982
983 pub input: Value,
985
986 #[serde(skip_serializing_if = "Option::is_none")]
988 pub cache_control: Option<CacheControl>,
989}
990
991#[serde_with::skip_serializing_none]
993#[derive(Debug, Clone, Serialize, Deserialize)]
994pub struct McpToolResultBlock {
995 pub tool_use_id: String,
997
998 pub content: Option<ToolResultContent>,
1000
1001 pub is_error: Option<bool>,
1003
1004 pub cache_control: Option<CacheControl>,
1006}
1007
1008#[serde_with::skip_serializing_none]
1010#[derive(Debug, Clone, Serialize, Deserialize)]
1011pub struct McpToolset {
1012 #[serde(rename = "type")]
1013 pub toolset_type: String, pub mcp_server_name: String,
1017
1018 pub default_config: Option<McpToolDefaultConfig>,
1020
1021 pub configs: Option<HashMap<String, McpToolConfig>>,
1023
1024 pub cache_control: Option<CacheControl>,
1026}
1027
1028#[serde_with::skip_serializing_none]
1030#[derive(Debug, Clone, Serialize, Deserialize)]
1031pub struct McpToolDefaultConfig {
1032 pub enabled: Option<bool>,
1034
1035 pub defer_loading: Option<bool>,
1037}
1038
1039#[serde_with::skip_serializing_none]
1041#[derive(Debug, Clone, Serialize, Deserialize)]
1042pub struct McpToolConfig {
1043 pub enabled: Option<bool>,
1045
1046 pub defer_loading: Option<bool>,
1048}
1049
1050#[serde_with::skip_serializing_none]
1056#[derive(Debug, Clone, Serialize, Deserialize)]
1057pub struct CodeExecutionTool {
1058 #[serde(rename = "type")]
1059 pub tool_type: String, pub name: String, pub allowed_callers: Option<Vec<String>>,
1065
1066 pub defer_loading: Option<bool>,
1068
1069 pub strict: Option<bool>,
1071
1072 pub cache_control: Option<CacheControl>,
1074}
1075
1076#[derive(Debug, Clone, Serialize, Deserialize)]
1078pub struct CodeExecutionResultBlock {
1079 pub stdout: String,
1081
1082 pub stderr: String,
1084
1085 pub return_code: i32,
1087
1088 pub content: Vec<CodeExecutionOutputBlock>,
1090}
1091
1092#[derive(Debug, Clone, Serialize, Deserialize)]
1094pub struct CodeExecutionOutputBlock {
1095 #[serde(rename = "type")]
1096 pub block_type: String, pub file_id: String,
1100}
1101
1102#[derive(Debug, Clone, Serialize, Deserialize)]
1104pub struct CodeExecutionToolResultBlock {
1105 pub tool_use_id: String,
1107
1108 pub content: CodeExecutionToolResultContent,
1110
1111 #[serde(skip_serializing_if = "Option::is_none")]
1113 pub cache_control: Option<CacheControl>,
1114}
1115
1116#[derive(Debug, Clone, Serialize, Deserialize)]
1118#[serde(untagged)]
1119pub enum CodeExecutionToolResultContent {
1120 Success(CodeExecutionResultBlock),
1121 Error(CodeExecutionToolResultError),
1122}
1123
1124#[derive(Debug, Clone, Serialize, Deserialize)]
1126pub struct CodeExecutionToolResultError {
1127 #[serde(rename = "type")]
1128 pub error_type: String, pub error_code: CodeExecutionToolResultErrorCode,
1131}
1132
1133#[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#[derive(Debug, Clone, Serialize, Deserialize)]
1145pub struct BashCodeExecutionResultBlock {
1146 pub stdout: String,
1148
1149 pub stderr: String,
1151
1152 pub return_code: i32,
1154
1155 pub content: Vec<BashCodeExecutionOutputBlock>,
1157}
1158
1159#[derive(Debug, Clone, Serialize, Deserialize)]
1161pub struct BashCodeExecutionOutputBlock {
1162 #[serde(rename = "type")]
1163 pub block_type: String, pub file_id: String,
1167}
1168
1169#[derive(Debug, Clone, Serialize, Deserialize)]
1171pub struct BashCodeExecutionToolResultBlock {
1172 pub tool_use_id: String,
1174
1175 pub content: BashCodeExecutionToolResultContent,
1177
1178 #[serde(skip_serializing_if = "Option::is_none")]
1180 pub cache_control: Option<CacheControl>,
1181}
1182
1183#[derive(Debug, Clone, Serialize, Deserialize)]
1185#[serde(untagged)]
1186pub enum BashCodeExecutionToolResultContent {
1187 Success(BashCodeExecutionResultBlock),
1188 Error(BashCodeExecutionToolResultError),
1189}
1190
1191#[derive(Debug, Clone, Serialize, Deserialize)]
1193pub struct BashCodeExecutionToolResultError {
1194 #[serde(rename = "type")]
1195 pub error_type: String, pub error_code: BashCodeExecutionToolResultErrorCode,
1198}
1199
1200#[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#[derive(Debug, Clone, Serialize, Deserialize)]
1212pub struct TextEditorCodeExecutionToolResultBlock {
1213 pub tool_use_id: String,
1215
1216 pub content: TextEditorCodeExecutionToolResultContent,
1218
1219 #[serde(skip_serializing_if = "Option::is_none")]
1221 pub cache_control: Option<CacheControl>,
1222}
1223
1224#[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#[derive(Debug, Clone, Serialize, Deserialize)]
1236pub struct TextEditorCodeExecutionCreateResultBlock {
1237 #[serde(rename = "type")]
1238 pub block_type: String, }
1240
1241#[derive(Debug, Clone, Serialize, Deserialize)]
1243pub struct TextEditorCodeExecutionStrReplaceResultBlock {
1244 #[serde(rename = "type")]
1245 pub block_type: String, #[serde(skip_serializing_if = "Option::is_none")]
1249 pub snippet: Option<String>,
1250}
1251
1252#[derive(Debug, Clone, Serialize, Deserialize)]
1254pub struct TextEditorCodeExecutionViewResultBlock {
1255 #[serde(rename = "type")]
1256 pub block_type: String, pub content: String,
1260}
1261
1262#[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#[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#[serde_with::skip_serializing_none]
1287#[derive(Debug, Clone, Serialize, Deserialize)]
1288pub struct WebFetchTool {
1289 #[serde(rename = "type")]
1290 pub tool_type: String, pub name: String, pub allowed_callers: Option<Vec<String>>,
1296
1297 pub max_uses: Option<u32>,
1299
1300 pub cache_control: Option<CacheControl>,
1302}
1303
1304#[derive(Debug, Clone, Serialize, Deserialize)]
1306pub struct WebFetchResultBlock {
1307 #[serde(rename = "type")]
1308 pub block_type: String, pub url: String,
1312
1313 pub content: DocumentBlock,
1315
1316 #[serde(skip_serializing_if = "Option::is_none")]
1318 pub retrieved_at: Option<String>,
1319}
1320
1321#[derive(Debug, Clone, Serialize, Deserialize)]
1323pub struct WebFetchToolResultBlock {
1324 pub tool_use_id: String,
1326
1327 pub content: WebFetchToolResultContent,
1329
1330 #[serde(skip_serializing_if = "Option::is_none")]
1332 pub cache_control: Option<CacheControl>,
1333}
1334
1335#[derive(Debug, Clone, Serialize, Deserialize)]
1337#[serde(untagged)]
1338pub enum WebFetchToolResultContent {
1339 Success(WebFetchResultBlock),
1340 Error(WebFetchToolResultError),
1341}
1342
1343#[derive(Debug, Clone, Serialize, Deserialize)]
1345pub struct WebFetchToolResultError {
1346 #[serde(rename = "type")]
1347 pub error_type: String, pub error_code: WebFetchToolResultErrorCode,
1350}
1351
1352#[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#[serde_with::skip_serializing_none]
1371#[derive(Debug, Clone, Serialize, Deserialize)]
1372pub struct ToolSearchTool {
1373 #[serde(rename = "type")]
1374 pub tool_type: String, pub name: String,
1377
1378 pub allowed_callers: Option<Vec<String>>,
1380
1381 pub cache_control: Option<CacheControl>,
1383}
1384
1385#[derive(Debug, Clone, Serialize, Deserialize)]
1387pub struct ToolReferenceBlock {
1388 #[serde(rename = "type")]
1389 pub block_type: String, pub tool_name: String,
1393
1394 #[serde(skip_serializing_if = "Option::is_none")]
1396 pub description: Option<String>,
1397}
1398
1399#[derive(Debug, Clone, Serialize, Deserialize)]
1401pub struct ToolSearchResultBlock {
1402 #[serde(rename = "type")]
1403 pub block_type: String, pub tool_name: String,
1407
1408 #[serde(skip_serializing_if = "Option::is_none")]
1410 pub score: Option<f64>,
1411}
1412
1413#[derive(Debug, Clone, Serialize, Deserialize)]
1415pub struct ToolSearchToolResultBlock {
1416 pub tool_use_id: String,
1418
1419 pub content: Vec<ToolSearchResultBlock>,
1421
1422 #[serde(skip_serializing_if = "Option::is_none")]
1424 pub cache_control: Option<CacheControl>,
1425}
1426
1427#[derive(Debug, Clone, Serialize, Deserialize)]
1433pub struct ContainerUploadBlock {
1434 #[serde(rename = "type")]
1435 pub block_type: String, pub file_id: String,
1439
1440 pub file_name: String,
1442
1443 #[serde(skip_serializing_if = "Option::is_none")]
1445 pub file_path: Option<String>,
1446}
1447
1448#[serde_with::skip_serializing_none]
1454#[derive(Debug, Clone, Serialize, Deserialize)]
1455pub struct MemoryTool {
1456 #[serde(rename = "type")]
1457 pub tool_type: String, pub name: String, pub allowed_callers: Option<Vec<String>>,
1463
1464 pub defer_loading: Option<bool>,
1466
1467 pub strict: Option<bool>,
1469
1470 pub input_examples: Option<Vec<Value>>,
1472
1473 pub cache_control: Option<CacheControl>,
1475}
1476
1477#[serde_with::skip_serializing_none]
1483#[derive(Debug, Clone, Serialize, Deserialize)]
1484pub struct ComputerUseTool {
1485 #[serde(rename = "type")]
1486 pub tool_type: String, pub name: String, pub display_width_px: u32,
1492
1493 pub display_height_px: u32,
1495
1496 pub display_number: Option<u32>,
1498
1499 pub allowed_callers: Option<Vec<String>>,
1501
1502 pub cache_control: Option<CacheControl>,
1504}
1505
1506#[derive(Debug, Clone, Serialize, Deserialize)]
1512#[serde(tag = "type", rename_all = "snake_case")]
1513pub enum BetaInputContentBlock {
1514 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 McpToolUse(McpToolUseBlock),
1528 McpToolResult(McpToolResultBlock),
1529
1530 CodeExecutionToolResult(CodeExecutionToolResultBlock),
1532 BashCodeExecutionToolResult(BashCodeExecutionToolResultBlock),
1533 TextEditorCodeExecutionToolResult(TextEditorCodeExecutionToolResultBlock),
1534
1535 WebFetchToolResult(WebFetchToolResultBlock),
1537
1538 ToolSearchToolResult(ToolSearchToolResultBlock),
1540 ToolReference(ToolReferenceBlock),
1541
1542 ContainerUpload(ContainerUploadBlock),
1544}
1545
1546#[serde_with::skip_serializing_none]
1548#[derive(Debug, Clone, Serialize, Deserialize)]
1549#[serde(tag = "type", rename_all = "snake_case")]
1550pub enum BetaContentBlock {
1551 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 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 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 WebFetchToolResult {
1607 tool_use_id: String,
1608 content: WebFetchToolResultContent,
1609 },
1610
1611 ToolSearchToolResult {
1613 tool_use_id: String,
1614 content: Vec<ToolSearchResultBlock>,
1615 },
1616 ToolReference {
1617 tool_name: String,
1618 description: Option<String>,
1619 },
1620
1621 ContainerUpload {
1623 file_id: String,
1624 file_name: String,
1625 file_path: Option<String>,
1626 },
1627}
1628
1629#[derive(Debug, Clone, Serialize, Deserialize)]
1631#[serde(untagged)]
1632pub enum BetaTool {
1633 Custom(CustomTool),
1635 Bash(BashTool),
1636 TextEditor(TextEditorTool),
1637 WebSearch(WebSearchTool),
1638
1639 CodeExecution(CodeExecutionTool),
1641 McpToolset(McpToolset),
1642 WebFetch(WebFetchTool),
1643 ToolSearch(ToolSearchTool),
1644 Memory(MemoryTool),
1645 ComputerUse(ComputerUseTool),
1646}
1647
1648#[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#[derive(Debug, Clone, Serialize, Deserialize)]
1663#[serde(tag = "type", rename_all = "snake_case")]
1664pub enum ServerToolCaller {
1665 Direct,
1667 #[serde(rename = "code_execution_20250825")]
1669 CodeExecution20250825,
1670}