async_openai/types/responses/
response.rs

1use crate::error::OpenAIError;
2use crate::types::mcp::{MCPListToolsTool, MCPTool};
3use crate::types::responses::{
4    CustomGrammarFormatParam, Filter, ImageDetail, ReasoningEffort, ResponseFormatJsonSchema,
5    ResponseUsage,
6};
7use derive_builder::Builder;
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10
11/// Role of messages in the API.
12#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
13#[serde(rename_all = "lowercase")]
14pub enum Role {
15    #[default]
16    User,
17    Assistant,
18    System,
19    Developer,
20}
21
22/// Status of input/output items.
23#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
24#[serde(rename_all = "snake_case")]
25pub enum OutputStatus {
26    InProgress,
27    Completed,
28    Incomplete,
29}
30
31#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
32#[serde(untagged)]
33pub enum InputParam {
34    ///  A text input to the model, equivalent to a text input with the
35    /// `user` role.
36    Text(String),
37    /// A list of one or many input items to the model, containing
38    /// different content types.
39    Items(Vec<InputItem>),
40}
41
42/// Content item used to generate a response.
43///
44/// This is a properly discriminated union based on the `type` field, using Rust's
45/// type-safe enum with serde's tag attribute for efficient deserialization.
46///
47/// # OpenAPI Specification
48/// Corresponds to the `Item` schema in the OpenAPI spec with a `type` discriminator.
49#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
50#[serde(tag = "type", rename_all = "snake_case")]
51pub enum Item {
52    /// A message (type: "message").
53    /// Can represent InputMessage (user/system/developer) or OutputMessage (assistant).
54    ///
55    /// InputMessage:
56    ///     A message input to the model with a role indicating instruction following hierarchy.
57    ///     Instructions given with the developer or system role take precedence over instructions given with the user role.
58    /// OutputMessage:
59    ///     A message output from the model.
60    Message(MessageItem),
61
62    /// The results of a file search tool call. See the
63    /// [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
64    FileSearchCall(FileSearchToolCall),
65
66    /// A tool call to a computer use tool. See the
67    /// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
68    ComputerCall(ComputerToolCall),
69
70    /// The output of a computer tool call.
71    ComputerCallOutput(ComputerCallOutputItemParam),
72
73    /// The results of a web search tool call. See the
74    /// [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
75    WebSearchCall(WebSearchToolCall),
76
77    /// A tool call to run a function. See the
78    ///
79    /// [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
80    FunctionCall(FunctionToolCall),
81
82    /// The output of a function tool call.
83    FunctionCallOutput(FunctionCallOutputItemParam),
84
85    /// A description of the chain of thought used by a reasoning model while generating
86    /// a response. Be sure to include these items in your `input` to the Responses API
87    /// for subsequent turns of a conversation if you are manually
88    /// [managing context](https://platform.openai.com/docs/guides/conversation-state).
89    Reasoning(ReasoningItem),
90
91    /// A compaction item generated by the [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).
92    Compaction(CompactionSummaryItemParam),
93
94    /// An image generation request made by the model.
95    ImageGenerationCall(ImageGenToolCall),
96
97    /// A tool call to run code.
98    CodeInterpreterCall(CodeInterpreterToolCall),
99
100    /// A tool call to run a command on the local shell.
101    LocalShellCall(LocalShellToolCall),
102
103    /// The output of a local shell tool call.
104    LocalShellCallOutput(LocalShellToolCallOutput),
105
106    /// A tool representing a request to execute one or more shell commands.
107    ShellCall(FunctionShellCallItemParam),
108
109    /// The streamed output items emitted by a shell tool call.
110    ShellCallOutput(FunctionShellCallOutputItemParam),
111
112    /// A tool call representing a request to create, delete, or update files using diff patches.
113    ApplyPatchCall(ApplyPatchToolCallItemParam),
114
115    /// The streamed output emitted by an apply patch tool call.
116    ApplyPatchCallOutput(ApplyPatchToolCallOutputItemParam),
117
118    /// A list of tools available on an MCP server.
119    McpListTools(MCPListTools),
120
121    /// A request for human approval of a tool invocation.
122    McpApprovalRequest(MCPApprovalRequest),
123
124    /// A response to an MCP approval request.
125    McpApprovalResponse(MCPApprovalResponse),
126
127    /// An invocation of a tool on an MCP server.
128    McpCall(MCPToolCall),
129
130    /// The output of a custom tool call from your code, being sent back to the model.
131    CustomToolCallOutput(CustomToolCallOutput),
132
133    /// A call to a custom tool created by the model.
134    CustomToolCall(CustomToolCall),
135}
136
137/// Input item that can be used in the context for generating a response.
138///
139/// This represents the OpenAPI `InputItem` schema which is an `anyOf`:
140/// 1. `EasyInputMessage` - Simple, user-friendly message input (can use string content)
141/// 2. `Item` - Structured items with proper type discrimination (including InputMessage, OutputMessage, tool calls)
142/// 3. `ItemReferenceParam` - Reference to an existing item by ID (type can be null)
143///
144/// Uses untagged deserialization because these types overlap in structure.
145/// Order matters: more specific structures are tried first.
146///
147/// # OpenAPI Specification
148/// Corresponds to the `InputItem` schema: `anyOf[EasyInputMessage, Item, ItemReferenceParam]`
149#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
150#[serde(untagged)]
151pub enum InputItem {
152    /// A reference to an existing item by ID.
153    /// Has a required `id` field and optional `type` (can be "item_reference" or null).
154    /// Must be tried first as it's the most minimal structure.
155    ItemReference(ItemReference),
156
157    /// All structured items with proper type discrimination.
158    /// Includes InputMessage, OutputMessage, and all tool calls/outputs.
159    /// Uses the discriminated `Item` enum for efficient, type-safe deserialization.
160    Item(Item),
161
162    /// A simple, user-friendly message input (EasyInputMessage).
163    /// Supports string content and can include assistant role for previous responses.
164    /// Must be tried last as it's the most flexible structure.
165    ///
166    /// A message input to the model with a role indicating instruction following
167    /// hierarchy. Instructions given with the `developer` or `system` role take
168    /// precedence over instructions given with the `user` role. Messages with the
169    /// `assistant` role are presumed to have been generated by the model in previous
170    /// interactions.
171    EasyMessage(EasyInputMessage),
172}
173
174/// A message item used within the `Item` enum.
175///
176/// Both InputMessage and OutputMessage have `type: "message"`, so we use an untagged
177/// enum to distinguish them based on their structure:
178/// - OutputMessage: role=assistant, required id & status fields
179/// - InputMessage: role=user/system/developer, content is `Vec<ContentType>`, optional id/status
180///
181/// Note: EasyInputMessage is NOT included here - it's a separate variant in `InputItem`,
182/// not part of the structured `Item` enum.
183#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
184#[serde(untagged)]
185pub enum MessageItem {
186    /// An output message from the model (role: assistant, has required id & status).
187    /// This must come first as it has the most specific structure (required id and status fields).
188    Output(OutputMessage),
189
190    /// A structured input message (role: user/system/developer, content is `Vec<ContentType>`).
191    /// Has structured content list and optional id/status fields.
192    ///
193    /// A message input to the model with a role indicating instruction following hierarchy.
194    /// Instructions given with the `developer` or `system` role take precedence over instructions
195    /// given with the `user` role.
196    Input(InputMessage),
197}
198
199/// A reference to an existing item by ID.
200#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
201pub struct ItemReference {
202    /// The type of item to reference. Can be "item_reference" or null.
203    #[serde(skip_serializing_if = "Option::is_none")]
204    pub r#type: Option<ItemReferenceType>,
205    /// The ID of the item to reference.
206    pub id: String,
207}
208
209#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
210#[serde(rename_all = "snake_case")]
211pub enum ItemReferenceType {
212    ItemReference,
213}
214
215/// Output from a function call that you're providing back to the model.
216#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
217pub struct FunctionCallOutputItemParam {
218    /// The unique ID of the function tool call generated by the model.
219    pub call_id: String,
220    /// Text, image, or file output of the function tool call.
221    pub output: FunctionCallOutput,
222    /// The unique ID of the function tool call output.
223    /// Populated when this item is returned via API.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub id: Option<String>,
226    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
227    /// Populated when items are returned via API.
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub status: Option<OutputStatus>,
230}
231
232#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
233#[serde(untagged)]
234pub enum FunctionCallOutput {
235    /// A JSON string of the output of the function tool call.
236    Text(String),
237    Content(Vec<InputContent>), // TODO use shape which allows null from OpenAPI spec?
238}
239
240#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
241pub struct ComputerCallOutputItemParam {
242    /// The ID of the computer tool call that produced the output.
243    pub call_id: String,
244    /// A computer screenshot image used with the computer use tool.
245    pub output: ComputerScreenshotImage,
246    /// The safety checks reported by the API that have been acknowledged by the developer.
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub acknowledged_safety_checks: Option<Vec<ComputerCallSafetyCheckParam>>,
249    /// The unique ID of the computer tool call output. Optional when creating.
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub id: Option<String>,
252    /// The status of the message input. One of `in_progress`, `completed`, or `incomplete`.
253    /// Populated when input items are returned via API.
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub status: Option<OutputStatus>, // TODO rename OutputStatus?
256}
257
258#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
259#[serde(rename_all = "snake_case")]
260pub enum ComputerScreenshotImageType {
261    ComputerScreenshot,
262}
263
264/// A computer screenshot image used with the computer use tool.
265#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
266pub struct ComputerScreenshotImage {
267    /// Specifies the event type. For a computer screenshot, this property is always
268    /// set to `computer_screenshot`.
269    pub r#type: ComputerScreenshotImageType,
270    /// The identifier of an uploaded file that contains the screenshot.
271    #[serde(skip_serializing_if = "Option::is_none")]
272    pub file_id: Option<String>,
273    /// The URL of the screenshot image.
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub image_url: Option<String>,
276}
277
278/// Output from a local shell tool call that you're providing back to the model.
279#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
280pub struct LocalShellToolCallOutput {
281    /// The unique ID of the local shell tool call generated by the model.
282    pub id: String,
283
284    /// A JSON string of the output of the local shell tool call.
285    pub output: String,
286
287    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub status: Option<OutputStatus>,
290}
291
292/// Output from a local shell command execution.
293#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
294pub struct LocalShellOutput {
295    /// The stdout output from the command.
296    #[serde(skip_serializing_if = "Option::is_none")]
297    pub stdout: Option<String>,
298
299    /// The stderr output from the command.
300    #[serde(skip_serializing_if = "Option::is_none")]
301    pub stderr: Option<String>,
302
303    /// The exit code of the command.
304    #[serde(skip_serializing_if = "Option::is_none")]
305    pub exit_code: Option<i32>,
306}
307
308/// An MCP approval response that you're providing back to the model.
309#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
310pub struct MCPApprovalResponse {
311    /// The ID of the approval request being answered.
312    pub approval_request_id: String,
313
314    /// Whether the request was approved.
315    pub approve: bool,
316
317    /// The unique ID of the approval response
318    #[serde(skip_serializing_if = "Option::is_none")]
319    pub id: Option<String>,
320
321    /// Optional reason for the decision.
322    #[serde(skip_serializing_if = "Option::is_none")]
323    pub reason: Option<String>,
324}
325
326#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
327#[serde(untagged)]
328pub enum CustomToolCallOutputOutput {
329    /// A string of the output of the custom tool call.
330    Text(String),
331    /// Text, image, or file output of the custom tool call.
332    List(Vec<InputContent>),
333}
334
335#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
336pub struct CustomToolCallOutput {
337    /// The call ID, used to map this custom tool call output to a custom tool call.
338    pub call_id: String,
339
340    /// The output from the custom tool call generated by your code.
341    /// Can be a string or an list of output content.
342    pub output: CustomToolCallOutputOutput,
343
344    /// The unique ID of the custom tool call output in the OpenAI platform.
345    #[serde(skip_serializing_if = "Option::is_none")]
346    pub id: Option<String>,
347}
348
349/// A simplified message input to the model (EasyInputMessage in the OpenAPI spec).
350///
351/// This is the most user-friendly way to provide messages, supporting both simple
352/// string content and structured content. Role can include `assistant` for providing
353/// previous assistant responses.
354#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
355#[builder(
356    name = "EasyInputMessageArgs",
357    pattern = "mutable",
358    setter(into, strip_option),
359    default
360)]
361#[builder(build_fn(error = "OpenAIError"))]
362pub struct EasyInputMessage {
363    /// The type of the message input. Always set to `message`.
364    pub r#type: MessageType,
365    /// The role of the message input. One of `user`, `assistant`, `system`, or `developer`.
366    pub role: Role,
367    /// Text, image, or audio input to the model, used to generate a response.
368    /// Can also contain previous assistant responses.
369    pub content: EasyInputContent,
370}
371
372/// A structured message input to the model (InputMessage in the OpenAPI spec).
373///
374/// This variant requires structured content (not a simple string) and does not support
375/// the `assistant` role (use OutputMessage for that). status is populated when items are returned via API.
376#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
377#[builder(
378    name = "InputMessageArgs",
379    pattern = "mutable",
380    setter(into, strip_option),
381    default
382)]
383#[builder(build_fn(error = "OpenAIError"))]
384pub struct InputMessage {
385    /// A list of one or many input items to the model, containing different content types.
386    pub content: Vec<InputContent>,
387    /// The role of the message input. One of `user`, `system`, or `developer`.
388    /// Note: `assistant` is NOT allowed here; use OutputMessage instead.
389    pub role: InputRole,
390    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
391    /// Populated when items are returned via API.
392    #[serde(skip_serializing_if = "Option::is_none")]
393    pub status: Option<OutputStatus>,
394    /////The type of the message input. Always set to `message`.
395    //pub r#type: MessageType,
396}
397
398/// The role for an input message - can only be `user`, `system`, or `developer`.
399/// This type ensures type safety by excluding the `assistant` role (use OutputMessage for that).
400#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
401#[serde(rename_all = "lowercase")]
402pub enum InputRole {
403    #[default]
404    User,
405    System,
406    Developer,
407}
408
409/// Content for EasyInputMessage - can be a simple string or structured list.
410#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
411#[serde(untagged)]
412pub enum EasyInputContent {
413    /// A text input to the model.
414    Text(String),
415    /// A list of one or many input items to the model, containing different content types.
416    ContentList(Vec<InputContent>),
417}
418
419/// Parts of a message: text, image, file, or audio.
420#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
421#[serde(tag = "type", rename_all = "snake_case")]
422pub enum InputContent {
423    /// A text input to the model.
424    InputText(InputTextContent),
425    /// An image input to the model. Learn about
426    /// [image inputs](https://platform.openai.com/docs/guides/vision).
427    InputImage(InputImageContent),
428    /// A file input to the model.
429    InputFile(InputFileContent),
430}
431
432#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
433pub struct InputTextContent {
434    /// The text input to the model.
435    pub text: String,
436}
437
438#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
439#[builder(
440    name = "InputImageArgs",
441    pattern = "mutable",
442    setter(into, strip_option),
443    default
444)]
445#[builder(build_fn(error = "OpenAIError"))]
446pub struct InputImageContent {
447    /// The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`.
448    /// Defaults to `auto`.
449    pub detail: ImageDetail,
450    /// The ID of the file to be sent to the model.
451    #[serde(skip_serializing_if = "Option::is_none")]
452    pub file_id: Option<String>,
453    /// The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image
454    /// in a data URL.
455    #[serde(skip_serializing_if = "Option::is_none")]
456    pub image_url: Option<String>,
457}
458
459#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
460#[builder(
461    name = "InputFileArgs",
462    pattern = "mutable",
463    setter(into, strip_option),
464    default
465)]
466#[builder(build_fn(error = "OpenAIError"))]
467pub struct InputFileContent {
468    /// The content of the file to be sent to the model.
469    #[serde(skip_serializing_if = "Option::is_none")]
470    file_data: Option<String>,
471    /// The ID of the file to be sent to the model.
472    #[serde(skip_serializing_if = "Option::is_none")]
473    file_id: Option<String>,
474    /// The URL of the file to be sent to the model.
475    #[serde(skip_serializing_if = "Option::is_none")]
476    file_url: Option<String>,
477    /// The name of the file to be sent to the model.
478    #[serde(skip_serializing_if = "Option::is_none")]
479    filename: Option<String>,
480}
481
482/// The conversation that this response belonged to. Input items and output items from this
483/// response were automatically added to this conversation.
484#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
485pub struct Conversation {
486    /// The unique ID of the conversation that this response was associated with.
487    pub id: String,
488}
489
490#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
491#[serde(untagged)]
492pub enum ConversationParam {
493    /// The unique ID of the conversation.
494    ConversationID(String),
495    /// The conversation that this response belongs to.
496    Object(Conversation),
497}
498
499#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
500pub enum IncludeEnum {
501    #[serde(rename = "file_search_call.results")]
502    FileSearchCallResults,
503    #[serde(rename = "web_search_call.results")]
504    WebSearchCallResults,
505    #[serde(rename = "web_search_call.action.sources")]
506    WebSearchCallActionSources,
507    #[serde(rename = "message.input_image.image_url")]
508    MessageInputImageImageUrl,
509    #[serde(rename = "computer_call_output.output.image_url")]
510    ComputerCallOutputOutputImageUrl,
511    #[serde(rename = "code_interpreter_call.outputs")]
512    CodeInterpreterCallOutputs,
513    #[serde(rename = "reasoning.encrypted_content")]
514    ReasoningEncryptedContent,
515    #[serde(rename = "message.output_text.logprobs")]
516    MessageOutputTextLogprobs,
517}
518
519#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
520pub struct ResponseStreamOptions {
521    /// When true, stream obfuscation will be enabled. Stream obfuscation adds
522    /// random characters to an `obfuscation` field on streaming delta events to
523    /// normalize payload sizes as a mitigation to certain side-channel attacks.
524    /// These obfuscation fields are included by default, but add a small amount
525    /// of overhead to the data stream. You can set `include_obfuscation` to
526    /// false to optimize for bandwidth if you trust the network links between
527    /// your application and the OpenAI API.
528    #[serde(skip_serializing_if = "Option::is_none")]
529    pub include_obfuscation: Option<bool>,
530}
531
532/// Builder for a Responses API request.
533#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
534#[builder(
535    name = "CreateResponseArgs",
536    pattern = "mutable",
537    setter(into, strip_option),
538    default
539)]
540#[builder(build_fn(error = "OpenAIError"))]
541pub struct CreateResponse {
542    /// Whether to run the model response in the background.
543    /// [Learn more](https://platform.openai.com/docs/guides/background).
544    #[serde(skip_serializing_if = "Option::is_none")]
545    pub background: Option<bool>,
546
547    /// The conversation that this response belongs to. Items from this conversation are prepended to
548    ///  `input_items` for this response request.
549    ///
550    /// Input items and output items from this response are automatically added to this conversation after
551    /// this response completes.
552    #[serde(skip_serializing_if = "Option::is_none")]
553    pub conversation: Option<ConversationParam>,
554
555    /// Specify additional output data to include in the model response. Currently supported
556    /// values are:
557    ///
558    /// - `web_search_call.action.sources`: Include the sources of the web search tool call.
559    ///
560    /// - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
561    ///   interpreter tool call items.
562    ///
563    /// - `computer_call_output.output.image_url`: Include image urls from the computer call
564    ///   output.
565    ///
566    /// - `file_search_call.results`: Include the search results of the file search tool call.
567    ///
568    /// - `message.input_image.image_url`: Include image urls from the input message.
569    ///
570    /// - `message.output_text.logprobs`: Include logprobs with assistant messages.
571    ///
572    /// - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
573    ///   reasoning item outputs. This enables reasoning items to be used in multi-turn
574    ///   conversations when using the Responses API statelessly (like when the `store` parameter is
575    ///   set to `false`, or when an organization is enrolled in the zero data retention program).
576    #[serde(skip_serializing_if = "Option::is_none")]
577    pub include: Option<Vec<IncludeEnum>>,
578
579    /// Text, image, or file inputs to the model, used to generate a response.
580    ///
581    /// Learn more:
582    /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
583    /// - [Image inputs](https://platform.openai.com/docs/guides/images)
584    /// - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
585    /// - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
586    /// - [Function calling](https://platform.openai.com/docs/guides/function-calling)
587    pub input: InputParam,
588
589    /// A system (or developer) message inserted into the model's context.
590    ///
591    /// When using along with `previous_response_id`, the instructions from a previous
592    /// response will not be carried over to the next response. This makes it simple
593    /// to swap out system (or developer) messages in new responses.
594    #[serde(skip_serializing_if = "Option::is_none")]
595    pub instructions: Option<String>,
596
597    /// An upper bound for the number of tokens that can be generated for a response, including
598    /// visible output tokens and [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
599    #[serde(skip_serializing_if = "Option::is_none")]
600    pub max_output_tokens: Option<u32>,
601
602    /// The maximum number of total calls to built-in tools that can be processed in a response. This
603    /// maximum number applies across all built-in tool calls, not per individual tool. Any further
604    /// attempts to call a tool by the model will be ignored.
605    #[serde(skip_serializing_if = "Option::is_none")]
606    pub max_tool_calls: Option<u32>,
607
608    /// Set of 16 key-value pairs that can be attached to an object. This can be
609    /// useful for storing additional information about the object in a structured
610    /// format, and querying for objects via API or the dashboard.
611    ///
612    /// Keys are strings with a maximum length of 64 characters. Values are
613    /// strings with a maximum length of 512 characters.
614    #[serde(skip_serializing_if = "Option::is_none")]
615    pub metadata: Option<HashMap<String, String>>,
616
617    /// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI
618    /// offers a wide range of models with different capabilities, performance
619    /// characteristics, and price points. Refer to the [model guide](https://platform.openai.com/docs/models)
620    /// to browse and compare available models.
621    #[serde(skip_serializing_if = "Option::is_none")]
622    pub model: Option<String>,
623
624    /// Whether to allow the model to run tool calls in parallel.
625    #[serde(skip_serializing_if = "Option::is_none")]
626    pub parallel_tool_calls: Option<bool>,
627
628    /// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
629    /// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
630    /// Cannot be used in conjunction with `conversation`.
631    #[serde(skip_serializing_if = "Option::is_none")]
632    pub previous_response_id: Option<String>,
633
634    /// Reference to a prompt template and its variables.
635    /// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
636    #[serde(skip_serializing_if = "Option::is_none")]
637    pub prompt: Option<Prompt>,
638
639    /// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
640    /// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
641    #[serde(skip_serializing_if = "Option::is_none")]
642    pub prompt_cache_key: Option<String>,
643
644    /// The retention policy for the prompt cache. Set to `24h` to enable extended prompt caching,
645    /// which keeps cached prefixes active for longer, up to a maximum of 24 hours. [Learn
646    /// more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).    
647    #[serde(skip_serializing_if = "Option::is_none")]
648    pub prompt_cache_retention: Option<PromptCacheRetention>,
649
650    /// **gpt-5 and o-series models only**
651    /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
652    #[serde(skip_serializing_if = "Option::is_none")]
653    pub reasoning: Option<Reasoning>,
654
655    /// A stable identifier used to help detect users of your application that may be violating OpenAI's
656    /// usage policies.
657    ///
658    /// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
659    /// or email address, in order to avoid sending us any identifying information. [Learn
660    /// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
661    #[serde(skip_serializing_if = "Option::is_none")]
662    pub safety_identifier: Option<String>,
663
664    /// Specifies the processing type used for serving the request.
665    /// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
666    /// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
667    /// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
668    /// - When not set, the default behavior is 'auto'.
669    ///
670    /// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
671    #[serde(skip_serializing_if = "Option::is_none")]
672    pub service_tier: Option<ServiceTier>,
673
674    /// Whether to store the generated model response for later retrieval via API.
675    #[serde(skip_serializing_if = "Option::is_none")]
676    pub store: Option<bool>,
677
678    /// If set to true, the model response data will be streamed to the client
679    /// as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
680    /// See the [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
681    /// for more information.
682    #[serde(skip_serializing_if = "Option::is_none")]
683    pub stream: Option<bool>,
684
685    /// Options for streaming responses. Only set this when you set `stream: true`.
686    #[serde(skip_serializing_if = "Option::is_none")]
687    pub stream_options: Option<ResponseStreamOptions>,
688
689    /// What sampling temperature to use, between 0 and 2. Higher values like 0.8
690    /// will make the output more random, while lower values like 0.2 will make it
691    /// more focused and deterministic. We generally recommend altering this or
692    /// `top_p` but not both.
693    #[serde(skip_serializing_if = "Option::is_none")]
694    pub temperature: Option<f32>,
695
696    /// Configuration options for a text response from the model. Can be plain
697    /// text or structured JSON data. Learn more:
698    /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
699    /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
700    #[serde(skip_serializing_if = "Option::is_none")]
701    pub text: Option<ResponseTextParam>,
702
703    /// How the model should select which tool (or tools) to use when generating
704    /// a response. See the `tools` parameter to see how to specify which tools
705    /// the model can call.
706    #[serde(skip_serializing_if = "Option::is_none")]
707    pub tool_choice: Option<ToolChoiceParam>,
708
709    /// An array of tools the model may call while generating a response. You
710    /// can specify which tool to use by setting the `tool_choice` parameter.
711    ///
712    /// We support the following categories of tools:
713    /// - **Built-in tools**: Tools that are provided by OpenAI that extend the
714    ///   model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
715    ///   or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
716    ///   [built-in tools](https://platform.openai.com/docs/guides/tools).
717    /// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
718    ///   or predefined connectors such as Google Drive and SharePoint. Learn more about
719    ///   [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
720    /// - **Function calls (custom tools)**: Functions that are defined by you,
721    ///   enabling the model to call your own code with strongly typed arguments
722    ///   and outputs. Learn more about
723    ///   [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
724    ///   custom tools to call your own code.
725    #[serde(skip_serializing_if = "Option::is_none")]
726    pub tools: Option<Vec<Tool>>,
727
728    /// An integer between 0 and 20 specifying the number of most likely tokens to return at each
729    /// token position, each with an associated log probability.
730    #[serde(skip_serializing_if = "Option::is_none")]
731    pub top_logprobs: Option<u8>,
732
733    /// An alternative to sampling with temperature, called nucleus sampling,
734    /// where the model considers the results of the tokens with top_p probability
735    /// mass. So 0.1 means only the tokens comprising the top 10% probability mass
736    /// are considered.
737    ///
738    /// We generally recommend altering this or `temperature` but not both.
739    #[serde(skip_serializing_if = "Option::is_none")]
740    pub top_p: Option<f32>,
741
742    ///The truncation strategy to use for the model response.
743    /// - `auto`: If the input to this Response exceeds
744    ///   the model's context window size, the model will truncate the
745    ///   response to fit the context window by dropping items from the beginning of the conversation.
746    /// - `disabled` (default): If the input size will exceed the context window
747    ///   size for a model, the request will fail with a 400 error.
748    #[serde(skip_serializing_if = "Option::is_none")]
749    pub truncation: Option<Truncation>,
750}
751
752#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
753#[serde(untagged)]
754pub enum ResponsePromptVariables {
755    String(String),
756    Content(InputContent),
757    Custom(serde_json::Value),
758}
759
760#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
761pub struct Prompt {
762    /// The unique identifier of the prompt template to use.
763    pub id: String,
764
765    /// Optional version of the prompt template.
766    #[serde(skip_serializing_if = "Option::is_none")]
767    pub version: Option<String>,
768
769    /// Optional map of values to substitute in for variables in your
770    /// prompt. The substitution values can either be strings, or other
771    /// Response input types like images or files.
772    #[serde(skip_serializing_if = "Option::is_none")]
773    pub variables: Option<ResponsePromptVariables>,
774}
775
776#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
777#[serde(rename_all = "lowercase")]
778pub enum ServiceTier {
779    #[default]
780    Auto,
781    Default,
782    Flex,
783    Scale,
784    Priority,
785}
786
787/// Truncation strategies.
788#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
789#[serde(rename_all = "lowercase")]
790pub enum Truncation {
791    Auto,
792    Disabled,
793}
794
795#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
796pub struct Billing {
797    pub payer: String,
798}
799
800/// o-series reasoning settings.
801#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
802#[builder(
803    name = "ReasoningArgs",
804    pattern = "mutable",
805    setter(into, strip_option),
806    default
807)]
808#[builder(build_fn(error = "OpenAIError"))]
809pub struct Reasoning {
810    /// Constrains effort on reasoning for
811    /// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
812    /// Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing
813    /// reasoning effort can result in faster responses and fewer tokens used
814    /// on reasoning in a response.
815    ///
816    /// Note: The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.
817    #[serde(skip_serializing_if = "Option::is_none")]
818    pub effort: Option<ReasoningEffort>,
819    /// A summary of the reasoning performed by the model. This can be
820    /// useful for debugging and understanding the model's reasoning process.
821    /// One of `auto`, `concise`, or `detailed`.
822    ///
823    /// `concise` is supported for `computer-use-preview` models and all reasoning models after
824    /// `gpt-5`.
825    #[serde(skip_serializing_if = "Option::is_none")]
826    pub summary: Option<ReasoningSummary>,
827}
828
829/// o-series reasoning settings.
830#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
831#[serde(rename_all = "lowercase")]
832pub enum Verbosity {
833    Low,
834    Medium,
835    High,
836}
837
838#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
839#[serde(rename_all = "lowercase")]
840pub enum ReasoningSummary {
841    Auto,
842    Concise,
843    Detailed,
844}
845
846/// The retention policy for the prompt cache.
847#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
848pub enum PromptCacheRetention {
849    #[serde(rename = "in-memory")]
850    InMemory,
851    #[serde(rename = "24h")]
852    Hours24,
853}
854
855/// Configuration for text response format.
856#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
857pub struct ResponseTextParam {
858    /// An object specifying the format that the model must output.
859    ///
860    /// Configuring `{ "type": "json_schema" }` enables Structured Outputs,
861    /// which ensures the model will match your supplied JSON schema. Learn more in the
862    /// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
863    ///
864    /// The default format is `{ "type": "text" }` with no additional options.
865    ///
866    /// **Not recommended for gpt-4o and newer models:**
867    ///
868    /// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
869    /// ensures the message the model generates is valid JSON. Using `json_schema`
870    /// is preferred for models that support it.
871    pub format: TextResponseFormatConfiguration,
872
873    /// Constrains the verbosity of the model's response. Lower values will result in
874    /// more concise responses, while higher values will result in more verbose responses.
875    ///
876    /// Currently supported values are `low`, `medium`, and `high`.
877    #[serde(skip_serializing_if = "Option::is_none")]
878    pub verbosity: Option<Verbosity>,
879}
880
881#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
882#[serde(tag = "type", rename_all = "snake_case")]
883pub enum TextResponseFormatConfiguration {
884    /// Default response format. Used to generate text responses.
885    Text,
886    /// JSON object response format. An older method of generating JSON responses.
887    /// Using `json_schema` is recommended for models that support it.
888    /// Note that the model will not generate JSON without a system or user message
889    /// instructing it to do so.
890    JsonObject,
891    /// JSON Schema response format. Used to generate structured JSON responses.
892    /// Learn more about [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
893    JsonSchema(ResponseFormatJsonSchema),
894}
895
896/// Definitions for model-callable tools.
897#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
898#[serde(tag = "type", rename_all = "snake_case")]
899pub enum Tool {
900    /// Defines a function in your own code the model can choose to call. Learn more about [function
901    /// calling](https://platform.openai.com/docs/guides/tools).
902    Function(FunctionTool),
903    /// A tool that searches for relevant content from uploaded files. Learn more about the [file search
904    /// tool](https://platform.openai.com/docs/guides/tools-file-search).
905    FileSearch(FileSearchTool),
906    /// A tool that controls a virtual computer. Learn more about the [computer
907    /// use tool](https://platform.openai.com/docs/guides/tools-computer-use).
908    ComputerUsePreview(ComputerUsePreviewTool),
909    /// Search the Internet for sources related to the prompt. Learn more about the
910    /// [web search tool](https://platform.openai.com/docs/guides/tools-web-search).
911    WebSearch(WebSearchTool),
912    /// type: web_search_2025_08_26
913    #[serde(rename = "web_search_2025_08_26")]
914    WebSearch20250826(WebSearchTool),
915    /// Give the model access to additional tools via remote Model Context Protocol
916    /// (MCP) servers. [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).
917    Mcp(MCPTool),
918    /// A tool that runs Python code to help generate a response to a prompt.
919    CodeInterpreter(CodeInterpreterTool),
920    /// A tool that generates images using a model like `gpt-image-1`.
921    ImageGeneration(ImageGenTool),
922    /// A tool that allows the model to execute shell commands in a local environment.
923    LocalShell,
924    /// A tool that allows the model to execute shell commands.
925    Shell,
926    /// A custom tool that processes input using a specified format. Learn more about   [custom
927    /// tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
928    Custom(CustomToolParam),
929    /// This tool searches the web for relevant results to use in a response. Learn more about the [web search
930    ///tool](https://platform.openai.com/docs/guides/tools-web-search).
931    WebSearchPreview(WebSearchTool),
932    /// type: web_search_preview_2025_03_11
933    #[serde(rename = "web_search_preview_2025_03_11")]
934    WebSearchPreview20250311(WebSearchTool),
935    /// Allows the assistant to create, delete, or update files using unified diffs.
936    ApplyPatch,
937}
938
939#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
940pub struct CustomToolParam {
941    /// The name of the custom tool, used to identify it in tool calls.
942    pub name: String,
943    /// Optional description of the custom tool, used to provide more context.
944    pub description: Option<String>,
945    /// The input format for the custom tool. Default is unconstrained text.
946    pub format: CustomToolParamFormat,
947}
948
949#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
950#[serde(tag = "type", rename_all = "lowercase")]
951pub enum CustomToolParamFormat {
952    /// Unconstrained free-form text.
953    #[default]
954    Text,
955    /// A grammar defined by the user.
956    Grammar(CustomGrammarFormatParam),
957}
958
959#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
960#[builder(
961    name = "FileSearchToolArgs",
962    pattern = "mutable",
963    setter(into, strip_option),
964    default
965)]
966#[builder(build_fn(error = "OpenAIError"))]
967pub struct FileSearchTool {
968    /// The IDs of the vector stores to search.
969    pub vector_store_ids: Vec<String>,
970    /// The maximum number of results to return. This number should be between 1 and 50 inclusive.
971    #[serde(skip_serializing_if = "Option::is_none")]
972    pub max_num_results: Option<u32>,
973    /// A filter to apply.
974    #[serde(skip_serializing_if = "Option::is_none")]
975    pub filters: Option<Filter>,
976    /// Ranking options for search.
977    #[serde(skip_serializing_if = "Option::is_none")]
978    pub ranking_options: Option<RankingOptions>,
979}
980
981#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
982#[builder(
983    name = "FunctionToolArgs",
984    pattern = "mutable",
985    setter(into, strip_option),
986    default
987)]
988pub struct FunctionTool {
989    /// The name of the function to call.
990    pub name: String,
991    /// A JSON schema object describing the parameters of the function.
992    #[serde(skip_serializing_if = "Option::is_none")]
993    pub parameters: Option<serde_json::Value>,
994    /// Whether to enforce strict parameter validation. Default `true`.
995    #[serde(skip_serializing_if = "Option::is_none")]
996    pub strict: Option<bool>,
997    /// A description of the function. Used by the model to determine whether or not to call the
998    /// function.
999    #[serde(skip_serializing_if = "Option::is_none")]
1000    pub description: Option<String>,
1001}
1002
1003#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1004pub struct WebSearchToolFilters {
1005    /// Allowed domains for the search. If not provided, all domains are allowed.
1006    /// Subdomains of the provided domains are allowed as well.
1007    ///
1008    /// Example: `["pubmed.ncbi.nlm.nih.gov"]`
1009    #[serde(skip_serializing_if = "Option::is_none")]
1010    pub allowed_domains: Option<Vec<String>>,
1011}
1012
1013#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1014#[builder(
1015    name = "WebSearchToolArgs",
1016    pattern = "mutable",
1017    setter(into, strip_option),
1018    default
1019)]
1020pub struct WebSearchTool {
1021    /// Filters for the search.
1022    #[serde(skip_serializing_if = "Option::is_none")]
1023    pub filters: Option<WebSearchToolFilters>,
1024    /// The approximate location of the user.
1025    #[serde(skip_serializing_if = "Option::is_none")]
1026    pub user_location: Option<WebSearchApproximateLocation>,
1027    /// High level guidance for the amount of context window space to use for the search. One of `low`,
1028    /// `medium`, or `high`. `medium` is the default.
1029    #[serde(skip_serializing_if = "Option::is_none")]
1030    pub search_context_size: Option<WebSearchToolSearchContextSize>,
1031}
1032
1033#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1034#[serde(rename_all = "lowercase")]
1035pub enum WebSearchToolSearchContextSize {
1036    Low,
1037    #[default]
1038    Medium,
1039    High,
1040}
1041
1042#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1043#[serde(rename_all = "lowercase")]
1044pub enum ComputerEnvironment {
1045    Windows,
1046    Mac,
1047    Linux,
1048    Ubuntu,
1049    #[default]
1050    Browser,
1051}
1052
1053#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1054#[builder(
1055    name = "ComputerUsePreviewToolArgs",
1056    pattern = "mutable",
1057    setter(into, strip_option),
1058    default
1059)]
1060pub struct ComputerUsePreviewTool {
1061    /// The type of computer environment to control.
1062    environment: ComputerEnvironment,
1063    /// The width of the computer display.
1064    display_width: u32,
1065    /// The height of the computer display.
1066    display_height: u32,
1067}
1068
1069#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1070pub enum RankVersionType {
1071    #[serde(rename = "auto")]
1072    Auto,
1073    #[serde(rename = "default-2024-11-15")]
1074    Default20241115,
1075}
1076
1077#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1078pub struct HybridSearch {
1079    /// The weight of the embedding in the reciprocal ranking fusion.
1080    pub embedding_weight: f32,
1081    /// The weight of the text in the reciprocal ranking fusion.
1082    pub text_weight: f32,
1083}
1084
1085/// Options for search result ranking.
1086#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1087pub struct RankingOptions {
1088    /// Weights that control how reciprocal rank fusion balances semantic embedding matches versus
1089    /// sparse keyword matches when hybrid search is enabled.
1090    #[serde(skip_serializing_if = "Option::is_none")]
1091    pub hybrid_search: Option<HybridSearch>,
1092    /// The ranker to use for the file search.
1093    pub ranker: RankVersionType,
1094    /// The score threshold for the file search, a number between 0 and 1. Numbers closer to 1 will
1095    /// attempt to return only the most relevant results, but may return fewer results.
1096    #[serde(skip_serializing_if = "Option::is_none")]
1097    pub score_threshold: Option<f32>,
1098}
1099
1100#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1101#[serde(rename_all = "lowercase")]
1102pub enum WebSearchApproximateLocationType {
1103    #[default]
1104    Approximate,
1105}
1106
1107/// Approximate user location for web search.
1108#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1109#[builder(
1110    name = "WebSearchApproximateLocationArgs",
1111    pattern = "mutable",
1112    setter(into, strip_option),
1113    default
1114)]
1115#[builder(build_fn(error = "OpenAIError"))]
1116pub struct WebSearchApproximateLocation {
1117    /// The type of location approximation. Always `approximate`.
1118    pub r#type: WebSearchApproximateLocationType,
1119    /// Free text input for the city of the user, e.g. `San Francisco`.
1120    #[serde(skip_serializing_if = "Option::is_none")]
1121    pub city: Option<String>,
1122    /// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user,
1123    /// e.g. `US`.
1124    #[serde(skip_serializing_if = "Option::is_none")]
1125    pub country: Option<String>,
1126    /// Free text input for the region of the user, e.g. `California`.
1127    #[serde(skip_serializing_if = "Option::is_none")]
1128    pub region: Option<String>,
1129    /// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the user, e.g.
1130    /// `America/Los_Angeles`.
1131    #[serde(skip_serializing_if = "Option::is_none")]
1132    pub timezone: Option<String>,
1133}
1134
1135/// Container configuration for a code interpreter.
1136#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1137#[serde(tag = "type", rename_all = "snake_case")]
1138pub enum CodeInterpreterToolContainer {
1139    /// Configuration for a code interpreter container. Optionally specify the IDs of the
1140    /// files to run the code on.
1141    Auto(CodeInterpreterContainerAuto),
1142
1143    /// The container ID.
1144    #[serde(untagged)]
1145    ContainerID(String),
1146}
1147
1148/// Auto configuration for code interpreter container.
1149#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1150pub struct CodeInterpreterContainerAuto {
1151    /// An optional list of uploaded files to make available to your code.
1152    #[serde(skip_serializing_if = "Option::is_none")]
1153    pub file_ids: Option<Vec<String>>,
1154
1155    #[serde(skip_serializing_if = "Option::is_none")]
1156    pub memory_limit: Option<u64>,
1157}
1158
1159#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1160#[builder(
1161    name = "CodeInterpreterToolArgs",
1162    pattern = "mutable",
1163    setter(into, strip_option),
1164    default
1165)]
1166#[builder(build_fn(error = "OpenAIError"))]
1167pub struct CodeInterpreterTool {
1168    /// The code interpreter container. Can be a container ID or an object that
1169    /// specifies uploaded file IDs to make available to your code, along with an
1170    /// optional `memory_limit` setting.
1171    pub container: CodeInterpreterToolContainer,
1172}
1173
1174#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1175pub struct ImageGenToolInputImageMask {
1176    /// Base64-encoded mask image.
1177    #[serde(skip_serializing_if = "Option::is_none")]
1178    pub image_url: Option<String>,
1179    /// File ID for the mask image.
1180    #[serde(skip_serializing_if = "Option::is_none")]
1181    pub file_id: Option<String>,
1182}
1183
1184#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1185#[serde(rename_all = "lowercase")]
1186pub enum InputFidelity {
1187    #[default]
1188    High,
1189    Low,
1190}
1191
1192#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1193#[serde(rename_all = "lowercase")]
1194pub enum ImageGenToolModeration {
1195    #[default]
1196    Auto,
1197    Low,
1198}
1199
1200/// Image generation tool definition.
1201#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1202#[builder(
1203    name = "ImageGenerationArgs",
1204    pattern = "mutable",
1205    setter(into, strip_option),
1206    default
1207)]
1208#[builder(build_fn(error = "OpenAIError"))]
1209pub struct ImageGenTool {
1210    /// Background type for the generated image. One of `transparent`,
1211    /// `opaque`, or `auto`. Default: `auto`.
1212    #[serde(skip_serializing_if = "Option::is_none")]
1213    pub background: Option<ImageGenToolBackground>,
1214    /// Control how much effort the model will exert to match the style and features, especially facial features,
1215    /// of input images. This parameter is only supported for `gpt-image-1`. Unsupported
1216    /// for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.
1217    #[serde(skip_serializing_if = "Option::is_none")]
1218    pub input_fidelity: Option<InputFidelity>,
1219    /// Optional mask for inpainting. Contains `image_url`
1220    /// (string, optional) and `file_id` (string, optional).
1221    #[serde(skip_serializing_if = "Option::is_none")]
1222    pub input_image_mask: Option<ImageGenToolInputImageMask>,
1223    /// The image generation model to use. Default: `gpt-image-1`.
1224    #[serde(skip_serializing_if = "Option::is_none")]
1225    pub model: Option<String>,
1226    /// Moderation level for the generated image. Default: `auto`.
1227    #[serde(skip_serializing_if = "Option::is_none")]
1228    pub moderation: Option<ImageGenToolModeration>,
1229    /// Compression level for the output image. Default: 100.
1230    #[serde(skip_serializing_if = "Option::is_none")]
1231    pub output_compression: Option<u8>,
1232    /// The output format of the generated image. One of `png`, `webp`, or
1233    /// `jpeg`. Default: `png`.
1234    #[serde(skip_serializing_if = "Option::is_none")]
1235    pub output_format: Option<ImageGenToolOutputFormat>,
1236    /// Number of partial images to generate in streaming mode, from 0 (default value) to 3.
1237    #[serde(skip_serializing_if = "Option::is_none")]
1238    pub partial_images: Option<u8>,
1239    /// The quality of the generated image. One of `low`, `medium`, `high`,
1240    /// or `auto`. Default: `auto`.
1241    #[serde(skip_serializing_if = "Option::is_none")]
1242    pub quality: Option<ImageGenToolQuality>,
1243    /// The size of the generated image. One of `1024x1024`, `1024x1536`,
1244    /// `1536x1024`, or `auto`. Default: `auto`.
1245    #[serde(skip_serializing_if = "Option::is_none")]
1246    pub size: Option<ImageGenToolSize>,
1247}
1248
1249#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1250#[serde(rename_all = "lowercase")]
1251pub enum ImageGenToolBackground {
1252    Transparent,
1253    Opaque,
1254    #[default]
1255    Auto,
1256}
1257
1258#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1259#[serde(rename_all = "lowercase")]
1260pub enum ImageGenToolOutputFormat {
1261    #[default]
1262    Png,
1263    Webp,
1264    Jpeg,
1265}
1266
1267#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1268#[serde(rename_all = "lowercase")]
1269pub enum ImageGenToolQuality {
1270    Low,
1271    Medium,
1272    High,
1273    #[default]
1274    Auto,
1275}
1276
1277#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1278#[serde(rename_all = "lowercase")]
1279pub enum ImageGenToolSize {
1280    #[default]
1281    Auto,
1282    #[serde(rename = "1024x1024")]
1283    Size1024x1024,
1284    #[serde(rename = "1024x1536")]
1285    Size1024x1536,
1286    #[serde(rename = "1536x1024")]
1287    Size1536x1024,
1288}
1289
1290#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1291#[serde(rename_all = "lowercase")]
1292pub enum ToolChoiceAllowedMode {
1293    Auto,
1294    Required,
1295}
1296
1297#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1298pub struct ToolChoiceAllowed {
1299    /// Constrains the tools available to the model to a pre-defined set.
1300    ///
1301    /// `auto` allows the model to pick from among the allowed tools and generate a
1302    /// message.
1303    ///
1304    /// `required` requires the model to call one or more of the allowed tools.
1305    pub mode: ToolChoiceAllowedMode,
1306    /// A list of tool definitions that the model should be allowed to call.
1307    ///
1308    /// For the Responses API, the list of tool definitions might look like:
1309    /// ```json
1310    /// [
1311    ///   { "type": "function", "name": "get_weather" },
1312    ///   { "type": "mcp", "server_label": "deepwiki" },
1313    ///   { "type": "image_generation" }
1314    /// ]
1315    /// ```
1316    pub tools: Vec<serde_json::Value>,
1317}
1318
1319/// The type of hosted tool the model should to use. Learn more about
1320/// [built-in tools](https://platform.openai.com/docs/guides/tools).
1321#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1322#[serde(tag = "type", rename_all = "snake_case")]
1323pub enum ToolChoiceTypes {
1324    FileSearch,
1325    WebSearchPreview,
1326    ComputerUsePreview,
1327    CodeInterpreter,
1328    ImageGeneration,
1329}
1330
1331#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1332pub struct ToolChoiceFunction {
1333    /// The name of the function to call.
1334    pub name: String,
1335}
1336
1337#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1338pub struct ToolChoiceMCP {
1339    /// The name of the tool to call on the server.
1340    pub name: String,
1341    /// The label of the MCP server to use.
1342    pub server_label: String,
1343}
1344
1345#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1346pub struct ToolChoiceCustom {
1347    /// The name of the custom tool to call.
1348    pub name: String,
1349}
1350
1351#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1352#[serde(tag = "type", rename_all = "snake_case")]
1353pub enum ToolChoiceParam {
1354    /// Constrains the tools available to the model to a pre-defined set.
1355    AllowedTools(ToolChoiceAllowed),
1356
1357    /// Use this option to force the model to call a specific function.
1358    Function(ToolChoiceFunction),
1359
1360    /// Use this option to force the model to call a specific tool on a remote MCP server.
1361    Mcp(ToolChoiceMCP),
1362
1363    /// Use this option to force the model to call a custom tool.
1364    Custom(ToolChoiceCustom),
1365
1366    /// Forces the model to call the apply_patch tool when executing a tool call.
1367    ApplyPatch,
1368
1369    /// Forces the model to call the function shell tool when a tool call is required.
1370    Shell,
1371
1372    /// Indicates that the model should use a built-in tool to generate a response.
1373    /// [Learn more about built-in tools](https://platform.openai.com/docs/guides/tools).
1374    #[serde(untagged)]
1375    Hosted(ToolChoiceTypes),
1376
1377    /// Controls which (if any) tool is called by the model.
1378    ///
1379    /// `none` means the model will not call any tool and instead generates a message.
1380    ///
1381    /// `auto` means the model can pick between generating a message or calling one or
1382    /// more tools.
1383    ///
1384    /// `required` means the model must call one or more tools.
1385    #[serde(untagged)]
1386    Mode(ToolChoiceOptions),
1387}
1388
1389#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1390#[serde(rename_all = "lowercase")]
1391pub enum ToolChoiceOptions {
1392    None,
1393    Auto,
1394    Required,
1395}
1396
1397/// An error that occurred while generating the response.
1398#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1399pub struct ErrorObject {
1400    /// A machine-readable error code that was returned.
1401    pub code: String,
1402    /// A human-readable description of the error that was returned.
1403    pub message: String,
1404}
1405
1406/// Details about an incomplete response.
1407#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1408pub struct IncompleteDetails {
1409    /// The reason why the response is incomplete.
1410    pub reason: String,
1411}
1412
1413#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1414pub struct TopLogProb {
1415    pub bytes: Vec<u8>,
1416    pub logprob: f64,
1417    pub token: String,
1418}
1419
1420#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1421pub struct LogProb {
1422    pub bytes: Vec<u8>,
1423    pub logprob: f64,
1424    pub token: String,
1425    pub top_logprobs: Vec<TopLogProb>,
1426}
1427
1428#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1429pub struct ResponseTopLobProb {
1430    /// The log probability of this token.
1431    pub logprob: f64,
1432    /// A possible text token.
1433    pub token: String,
1434}
1435
1436#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1437pub struct ResponseLogProb {
1438    /// The log probability of this token.
1439    pub logprob: f64,
1440    /// A possible text token.
1441    pub token: String,
1442    /// The log probability of the top 20 most likely tokens.
1443    pub top_logprobs: Vec<ResponseTopLobProb>,
1444}
1445
1446/// A simple text output from the model.
1447#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1448pub struct OutputTextContent {
1449    /// The annotations of the text output.
1450    pub annotations: Vec<Annotation>,
1451    pub logprobs: Option<Vec<LogProb>>,
1452    /// The text output from the model.
1453    pub text: String,
1454}
1455
1456/// An annotation that applies to a span of output text.
1457#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1458#[serde(tag = "type", rename_all = "snake_case")]
1459pub enum Annotation {
1460    /// A citation to a file.
1461    FileCitation(FileCitationBody),
1462    /// A citation for a web resource used to generate a model response.
1463    UrlCitation(UrlCitationBody),
1464    /// A citation for a container file used to generate a model response.
1465    ContainerFileCitation(ContainerFileCitationBody),
1466    /// A path to a file.
1467    FilePath(FilePath),
1468}
1469
1470#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1471pub struct FileCitationBody {
1472    /// The ID of the file.
1473    file_id: String,
1474    /// The filename of the file cited.
1475    filename: String,
1476    /// The index of the file in the list of files.
1477    index: u32,
1478}
1479
1480#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1481pub struct UrlCitationBody {
1482    /// The index of the last character of the URL citation in the message.
1483    end_index: u32,
1484    /// The index of the first character of the URL citation in the message.
1485    start_index: u32,
1486    /// The title of the web resource.
1487    title: String,
1488    /// The URL of the web resource.
1489    url: String,
1490}
1491
1492#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1493pub struct ContainerFileCitationBody {
1494    /// The ID of the container file.
1495    container_id: String,
1496    /// The index of the last character of the container file citation in the message.
1497    end_index: u32,
1498    /// The ID of the file.
1499    file_id: String,
1500    /// The filename of the container file cited.
1501    filename: String,
1502    /// The index of the first character of the container file citation in the message.
1503    start_index: u32,
1504}
1505
1506#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1507pub struct FilePath {
1508    /// The ID of the file.
1509    file_id: String,
1510    /// The index of the file in the list of files.
1511    index: u32,
1512}
1513
1514/// A refusal explanation from the model.
1515#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1516pub struct RefusalContent {
1517    /// The refusal explanation from the model.
1518    pub refusal: String,
1519}
1520
1521/// A message generated by the model.
1522#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1523pub struct OutputMessage {
1524    /// The content of the output message.
1525    pub content: Vec<OutputMessageContent>,
1526    /// The unique ID of the output message.
1527    pub id: String,
1528    /// The role of the output message. Always `assistant`.
1529    pub role: AssistantRole,
1530    /// The status of the message input. One of `in_progress`, `completed`, or
1531    /// `incomplete`. Populated when input items are returned via API.
1532    pub status: OutputStatus,
1533    ///// The type of the output message. Always `message`.
1534    //pub r#type: MessageType,
1535}
1536
1537#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1538#[serde(rename_all = "lowercase")]
1539pub enum MessageType {
1540    #[default]
1541    Message,
1542}
1543
1544/// The role for an output message - always `assistant`.
1545/// This type ensures type safety by only allowing the assistant role.
1546#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1547#[serde(rename_all = "lowercase")]
1548pub enum AssistantRole {
1549    #[default]
1550    Assistant,
1551}
1552
1553#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1554#[serde(tag = "type", rename_all = "snake_case")]
1555pub enum OutputMessageContent {
1556    /// A text output from the model.
1557    OutputText(OutputTextContent),
1558    /// A refusal from the model.
1559    Refusal(RefusalContent),
1560}
1561
1562#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1563#[serde(tag = "type", rename_all = "snake_case")]
1564pub enum OutputContent {
1565    /// A text output from the model.
1566    OutputText(OutputTextContent),
1567    /// A refusal from the model.
1568    Refusal(RefusalContent),
1569    /// Reasoning text from the model.
1570    ReasoningText(ReasoningTextContent),
1571}
1572
1573#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1574pub struct ReasoningTextContent {
1575    /// The reasoning text from the model.
1576    pub text: String,
1577}
1578
1579/// A reasoning item representing the model's chain of thought, including summary paragraphs.
1580#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1581pub struct ReasoningItem {
1582    /// Unique identifier of the reasoning content.
1583    pub id: String,
1584    /// Reasoning summary content.
1585    pub summary: Vec<SummaryPart>,
1586    /// Reasoning text content.
1587    #[serde(skip_serializing_if = "Option::is_none")]
1588    pub content: Option<Vec<ReasoningTextContent>>,
1589    /// The encrypted content of the reasoning item - populated when a response is generated with
1590    /// `reasoning.encrypted_content` in the `include` parameter.
1591    #[serde(skip_serializing_if = "Option::is_none")]
1592    pub encrypted_content: Option<String>,
1593    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1594    /// Populated when items are returned via API.
1595    #[serde(skip_serializing_if = "Option::is_none")]
1596    pub status: Option<OutputStatus>,
1597}
1598
1599/// A single summary text fragment from reasoning.
1600#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1601pub struct Summary {
1602    /// A summary of the reasoning output from the model so far.
1603    pub text: String,
1604}
1605
1606#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1607#[serde(tag = "type", rename_all = "snake_case")]
1608pub enum SummaryPart {
1609    SummaryText(Summary),
1610}
1611
1612/// File search tool call output.
1613#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1614pub struct FileSearchToolCall {
1615    /// The unique ID of the file search tool call.
1616    pub id: String,
1617    /// The queries used to search for files.
1618    pub queries: Vec<String>,
1619    /// The status of the file search tool call. One of `in_progress`, `searching`,
1620    /// `incomplete`,`failed`, or `completed`.
1621    pub status: FileSearchToolCallStatus,
1622    /// The results of the file search tool call.
1623    #[serde(skip_serializing_if = "Option::is_none")]
1624    pub results: Option<Vec<FileSearchToolCallResult>>,
1625}
1626
1627#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1628#[serde(rename_all = "snake_case")]
1629pub enum FileSearchToolCallStatus {
1630    InProgress,
1631    Searching,
1632    Incomplete,
1633    Failed,
1634    Completed,
1635}
1636
1637/// A single result from a file search.
1638#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1639pub struct FileSearchToolCallResult {
1640    /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
1641    /// additional information about the object in a structured format, and querying for objects
1642    /// API or the dashboard. Keys are strings with a maximum length of 64 characters
1643    /// . Values are strings with a maximum length of 512 characters, booleans, or numbers.
1644    pub attributes: HashMap<String, serde_json::Value>,
1645    /// The unique ID of the file.
1646    pub file_id: String,
1647    /// The name of the file.
1648    pub filename: String,
1649    /// The relevance score of the file - a value between 0 and 1.
1650    pub score: f32,
1651    /// The text that was retrieved from the file.
1652    pub text: String,
1653}
1654
1655#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1656pub struct ComputerCallSafetyCheckParam {
1657    /// The ID of the pending safety check.
1658    pub id: String,
1659    /// The type of the pending safety check.
1660    #[serde(skip_serializing_if = "Option::is_none")]
1661    pub code: Option<String>,
1662    /// Details about the pending safety check.
1663    #[serde(skip_serializing_if = "Option::is_none")]
1664    pub message: Option<String>,
1665}
1666
1667#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1668#[serde(rename_all = "snake_case")]
1669pub enum WebSearchToolCallStatus {
1670    InProgress,
1671    Searching,
1672    Completed,
1673    Failed,
1674}
1675
1676#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1677pub struct WebSearchActionSearchSource {
1678    /// The type of source. Always `url`.
1679    pub r#type: String,
1680    /// The URL of the source.
1681    pub url: String,
1682}
1683
1684#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1685pub struct WebSearchActionSearch {
1686    /// The search query.
1687    pub query: String,
1688    /// The sources used in the search.
1689    pub sources: Option<Vec<WebSearchActionSearchSource>>,
1690}
1691
1692#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1693pub struct WebSearchActionOpenPage {
1694    /// The URL opened by the model.
1695    pub url: String,
1696}
1697
1698#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1699pub struct WebSearchActionFind {
1700    /// The URL of the page searched for the pattern.
1701    pub url: String,
1702    /// The pattern or text to search for within the page.
1703    pub pattern: String,
1704}
1705
1706#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1707#[serde(tag = "type", rename_all = "snake_case")]
1708pub enum WebSearchToolCallAction {
1709    /// Action type "search" - Performs a web search query.
1710    Search(WebSearchActionSearch),
1711    /// Action type "open_page" - Opens a specific URL from search results.
1712    OpenPage(WebSearchActionOpenPage),
1713    /// Action type "find": Searches for a pattern within a loaded page.
1714    Find(WebSearchActionFind),
1715}
1716
1717/// Web search tool call output.
1718#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1719pub struct WebSearchToolCall {
1720    /// An object describing the specific action taken in this web search call. Includes
1721    /// details on how the model used the web (search, open_page, find).
1722    pub action: WebSearchToolCallAction,
1723    /// The unique ID of the web search tool call.
1724    pub id: String,
1725    /// The status of the web search tool call.
1726    pub status: WebSearchToolCallStatus,
1727}
1728
1729/// Output from a computer tool call.
1730#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1731pub struct ComputerToolCall {
1732    pub action: ComputerAction,
1733    /// An identifier used when responding to the tool call with output.
1734    pub call_id: String,
1735    /// The unique ID of the computer call.
1736    pub id: String,
1737    /// The pending safety checks for the computer call.
1738    pub pending_safety_checks: Vec<ComputerCallSafetyCheckParam>,
1739    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1740    /// Populated when items are returned via API.
1741    pub status: OutputStatus,
1742}
1743
1744/// A point in 2D space.
1745#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1746pub struct DragPoint {
1747    /// The x-coordinate.
1748    pub x: i32,
1749    /// The y-coordinate.
1750    pub y: i32,
1751}
1752
1753/// Represents all user‐triggered actions.
1754#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1755#[serde(tag = "type", rename_all = "snake_case")]
1756pub enum ComputerAction {
1757    /// A click action.
1758    Click(ClickParam),
1759
1760    /// A double click action.
1761    DoubleClick(DoubleClickAction),
1762
1763    /// A drag action.
1764    Drag(Drag),
1765
1766    /// A collection of keypresses the model would like to perform.
1767    Keypress(KeyPressAction),
1768
1769    /// A mouse move action.
1770    Move(Move),
1771
1772    /// A screenshot action.
1773    Screenshot,
1774
1775    /// A scroll action.
1776    Scroll(Scroll),
1777
1778    /// An action to type in text.
1779    Type(Type),
1780
1781    /// A wait action.
1782    Wait,
1783}
1784
1785#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1786#[serde(rename_all = "lowercase")]
1787pub enum ClickButtonType {
1788    Left,
1789    Right,
1790    Wheel,
1791    Back,
1792    Forward,
1793}
1794
1795/// A click action.
1796#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1797pub struct ClickParam {
1798    /// Indicates which mouse button was pressed during the click. One of `left`,
1799    /// `right`, `wheel`, `back`, or `forward`.
1800    pub button: ClickButtonType,
1801    /// The x-coordinate where the click occurred.
1802    pub x: i32,
1803    /// The y-coordinate where the click occurred.
1804    pub y: i32,
1805}
1806
1807/// A double click action.
1808#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1809pub struct DoubleClickAction {
1810    /// The x-coordinate where the double click occurred.
1811    pub x: i32,
1812    /// The y-coordinate where the double click occurred.
1813    pub y: i32,
1814}
1815
1816/// A drag action.
1817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1818pub struct Drag {
1819    /// The path of points the cursor drags through.
1820    pub path: Vec<DragPoint>,
1821}
1822
1823/// A keypress action.
1824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1825pub struct KeyPressAction {
1826    /// The combination of keys the model is requesting to be pressed.
1827    /// This is an array of strings, each representing a key.
1828    pub keys: Vec<String>,
1829}
1830
1831/// A mouse move action.
1832#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1833pub struct Move {
1834    /// The x-coordinate to move to.
1835    pub x: i32,
1836    /// The y-coordinate to move to.
1837    pub y: i32,
1838}
1839
1840/// A scroll action.
1841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1842pub struct Scroll {
1843    /// The horizontal scroll distance.
1844    pub scroll_x: i32,
1845    /// The vertical scroll distance.
1846    pub scroll_y: i32,
1847    /// The x-coordinate where the scroll occurred.
1848    pub x: i32,
1849    /// The y-coordinate where the scroll occurred.
1850    pub y: i32,
1851}
1852
1853/// A typing (text entry) action.
1854#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1855pub struct Type {
1856    /// The text to type.
1857    pub text: String,
1858}
1859
1860#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1861pub struct FunctionToolCall {
1862    /// A JSON string of the arguments to pass to the function.
1863    pub arguments: String,
1864    /// The unique ID of the function tool call generated by the model.
1865    pub call_id: String,
1866    /// The name of the function to run.
1867    pub name: String,
1868    /// The unique ID of the function tool call.
1869    #[serde(skip_serializing_if = "Option::is_none")]
1870    pub id: Option<String>,
1871    /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1872    /// Populated when items are returned via API.
1873    #[serde(skip_serializing_if = "Option::is_none")]
1874    pub status: Option<OutputStatus>, // TODO rename OutputStatus?
1875}
1876
1877#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1878#[serde(rename_all = "snake_case")]
1879pub enum ImageGenToolCallStatus {
1880    InProgress,
1881    Completed,
1882    Generating,
1883    Failed,
1884}
1885
1886#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1887pub struct ImageGenToolCall {
1888    /// The unique ID of the image generation call.
1889    pub id: String,
1890    /// The generated image encoded in base64.
1891    pub result: Option<String>,
1892    /// The status of the image generation call.
1893    pub status: ImageGenToolCallStatus,
1894}
1895
1896#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1897#[serde(rename_all = "snake_case")]
1898pub enum CodeInterpreterToolCallStatus {
1899    InProgress,
1900    Completed,
1901    Incomplete,
1902    Interpreting,
1903    Failed,
1904}
1905
1906/// Output of a code interpreter request.
1907#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1908pub struct CodeInterpreterToolCall {
1909    /// The code to run, or null if not available.
1910    #[serde(skip_serializing_if = "Option::is_none")]
1911    pub code: Option<String>,
1912    /// ID of the container used to run the code.
1913    pub container_id: String,
1914    /// The unique ID of the code interpreter tool call.
1915    pub id: String,
1916    /// The outputs generated by the code interpreter, such as logs or images.
1917    /// Can be null if no outputs are available.
1918    #[serde(skip_serializing_if = "Option::is_none")]
1919    pub outputs: Option<Vec<CodeInterpreterToolCallOutput>>,
1920    /// The status of the code interpreter tool call.
1921    /// Valid values are `in_progress`, `completed`, `incomplete`, `interpreting`, and `failed`.
1922    pub status: CodeInterpreterToolCallStatus,
1923}
1924
1925/// Individual result from a code interpreter: either logs or files.
1926#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1927#[serde(tag = "type", rename_all = "snake_case")]
1928pub enum CodeInterpreterToolCallOutput {
1929    /// Code interpreter output logs
1930    Logs(CodeInterpreterOutputLogs),
1931    /// Code interpreter output image
1932    Image(CodeInterpreterOutputImage),
1933}
1934
1935#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1936pub struct CodeInterpreterOutputLogs {
1937    /// The logs output from the code interpreter.
1938    pub logs: String,
1939}
1940
1941#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1942pub struct CodeInterpreterOutputImage {
1943    /// The URL of the image output from the code interpreter.
1944    pub url: String,
1945}
1946
1947#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1948pub struct CodeInterpreterFile {
1949    /// The ID of the file.
1950    file_id: String,
1951    /// The MIME type of the file.
1952    mime_type: String,
1953}
1954
1955#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1956pub struct LocalShellToolCall {
1957    /// Execute a shell command on the server.
1958    pub action: LocalShellExecAction,
1959    /// The unique ID of the local shell tool call generated by the model.
1960    pub call_id: String,
1961    /// The unique ID of the local shell call.
1962    pub id: String,
1963    /// The status of the local shell call.
1964    pub status: OutputStatus,
1965}
1966
1967/// Define the shape of a local shell action (exec).
1968#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1969pub struct LocalShellExecAction {
1970    /// The command to run.
1971    pub command: Vec<String>,
1972    /// Environment variables to set for the command.
1973    pub env: HashMap<String, String>,
1974    /// Optional timeout in milliseconds for the command.
1975    pub timeout_ms: Option<u64>,
1976    /// Optional user to run the command as.
1977    pub user: Option<String>,
1978    /// Optional working directory to run the command in.
1979    pub working_directory: Option<String>,
1980}
1981
1982/// Commands and limits describing how to run the shell tool call.
1983#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1984pub struct FunctionShellActionParam {
1985    /// Ordered shell commands for the execution environment to run.
1986    pub commands: Vec<String>,
1987    /// Maximum wall-clock time in milliseconds to allow the shell commands to run.
1988    #[serde(skip_serializing_if = "Option::is_none")]
1989    pub timeout_ms: Option<u64>,
1990    /// Maximum number of UTF-8 characters to capture from combined stdout and stderr output.
1991    #[serde(skip_serializing_if = "Option::is_none")]
1992    pub max_output_length: Option<u64>,
1993}
1994
1995/// Status values reported for shell tool calls.
1996#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1997#[serde(rename_all = "snake_case")]
1998pub enum FunctionShellCallItemStatus {
1999    InProgress,
2000    Completed,
2001    Incomplete,
2002}
2003
2004/// A tool representing a request to execute one or more shell commands.
2005#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2006pub struct FunctionShellCallItemParam {
2007    /// The unique ID of the shell tool call. Populated when this item is returned via API.
2008    #[serde(skip_serializing_if = "Option::is_none")]
2009    pub id: Option<String>,
2010    /// The unique ID of the shell tool call generated by the model.
2011    pub call_id: String,
2012    /// The shell commands and limits that describe how to run the tool call.
2013    pub action: FunctionShellActionParam,
2014    /// The status of the shell call. One of `in_progress`, `completed`, or `incomplete`.
2015    #[serde(skip_serializing_if = "Option::is_none")]
2016    pub status: Option<FunctionShellCallItemStatus>,
2017}
2018
2019/// Indicates that the shell commands finished and returned an exit code.
2020#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2021pub struct FunctionShellCallOutputExitOutcomeParam {
2022    /// The exit code returned by the shell process.
2023    pub exit_code: i32,
2024}
2025
2026/// The exit or timeout outcome associated with this chunk.
2027#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2028#[serde(tag = "type", rename_all = "snake_case")]
2029pub enum FunctionShellCallOutputOutcomeParam {
2030    Timeout,
2031    Exit(FunctionShellCallOutputExitOutcomeParam),
2032}
2033
2034/// Captured stdout and stderr for a portion of a shell tool call output.
2035#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2036pub struct FunctionShellCallOutputContentParam {
2037    /// Captured stdout output for this chunk of the shell call.
2038    pub stdout: String,
2039    /// Captured stderr output for this chunk of the shell call.
2040    pub stderr: String,
2041    /// The exit or timeout outcome associated with this chunk.
2042    pub outcome: FunctionShellCallOutputOutcomeParam,
2043}
2044
2045/// The streamed output items emitted by a shell tool call.
2046#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2047pub struct FunctionShellCallOutputItemParam {
2048    /// The unique ID of the shell tool call output. Populated when this item is returned via API.
2049    #[serde(skip_serializing_if = "Option::is_none")]
2050    pub id: Option<String>,
2051    /// The unique ID of the shell tool call generated by the model.
2052    pub call_id: String,
2053    /// Captured chunks of stdout and stderr output, along with their associated outcomes.
2054    pub output: Vec<FunctionShellCallOutputContentParam>,
2055    /// The maximum number of UTF-8 characters captured for this shell call's combined output.
2056    #[serde(skip_serializing_if = "Option::is_none")]
2057    pub max_output_length: Option<u64>,
2058}
2059
2060/// Status values reported for apply_patch tool calls.
2061#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
2062#[serde(rename_all = "snake_case")]
2063pub enum ApplyPatchCallStatusParam {
2064    InProgress,
2065    Completed,
2066}
2067
2068/// Instruction for creating a new file via the apply_patch tool.
2069#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2070pub struct ApplyPatchCreateFileOperationParam {
2071    /// Path of the file to create relative to the workspace root.
2072    pub path: String,
2073    /// Unified diff content to apply when creating the file.
2074    pub diff: String,
2075}
2076
2077/// Instruction for deleting an existing file via the apply_patch tool.
2078#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2079pub struct ApplyPatchDeleteFileOperationParam {
2080    /// Path of the file to delete relative to the workspace root.
2081    pub path: String,
2082}
2083
2084/// Instruction for updating an existing file via the apply_patch tool.
2085#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2086pub struct ApplyPatchUpdateFileOperationParam {
2087    /// Path of the file to update relative to the workspace root.
2088    pub path: String,
2089    /// Unified diff content to apply to the existing file.
2090    pub diff: String,
2091}
2092
2093/// One of the create_file, delete_file, or update_file operations supplied to the apply_patch tool.
2094#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2095#[serde(tag = "type", rename_all = "snake_case")]
2096pub enum ApplyPatchOperationParam {
2097    CreateFile(ApplyPatchCreateFileOperationParam),
2098    DeleteFile(ApplyPatchDeleteFileOperationParam),
2099    UpdateFile(ApplyPatchUpdateFileOperationParam),
2100}
2101
2102/// A tool call representing a request to create, delete, or update files using diff patches.
2103#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2104pub struct ApplyPatchToolCallItemParam {
2105    /// The unique ID of the apply patch tool call. Populated when this item is returned via API.
2106    #[serde(skip_serializing_if = "Option::is_none")]
2107    pub id: Option<String>,
2108    /// The unique ID of the apply patch tool call generated by the model.
2109    pub call_id: String,
2110    /// The status of the apply patch tool call. One of `in_progress` or `completed`.
2111    pub status: ApplyPatchCallStatusParam,
2112    /// The specific create, delete, or update instruction for the apply_patch tool call.
2113    pub operation: ApplyPatchOperationParam,
2114}
2115
2116/// Outcome values reported for apply_patch tool call outputs.
2117#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
2118#[serde(rename_all = "snake_case")]
2119pub enum ApplyPatchCallOutputStatusParam {
2120    Completed,
2121    Failed,
2122}
2123
2124/// The streamed output emitted by an apply patch tool call.
2125#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2126pub struct ApplyPatchToolCallOutputItemParam {
2127    /// The unique ID of the apply patch tool call output. Populated when this item is returned via API.
2128    #[serde(skip_serializing_if = "Option::is_none")]
2129    pub id: Option<String>,
2130    /// The unique ID of the apply patch tool call generated by the model.
2131    pub call_id: String,
2132    /// The status of the apply patch tool call output. One of `completed` or `failed`.
2133    pub status: ApplyPatchCallOutputStatusParam,
2134    /// Optional human-readable log text from the apply patch tool (e.g., patch results or errors).
2135    #[serde(skip_serializing_if = "Option::is_none")]
2136    pub output: Option<String>,
2137}
2138
2139/// Shell exec action
2140/// Execute a shell command.
2141#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2142pub struct FunctionShellAction {
2143    /// A list of commands to run.
2144    pub commands: Vec<String>,
2145    /// Optional timeout in milliseconds for the commands.
2146    pub timeout_ms: Option<u64>,
2147    /// Optional maximum number of characters to return from each command.
2148    pub max_output_length: Option<u64>,
2149}
2150
2151/// Status values reported for function shell tool calls.
2152#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
2153#[serde(rename_all = "snake_case")]
2154pub enum LocalShellCallStatus {
2155    InProgress,
2156    Completed,
2157    Incomplete,
2158}
2159
2160/// A tool call that executes one or more shell commands in a managed environment.
2161#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2162pub struct FunctionShellCall {
2163    /// The unique ID of the function shell tool call. Populated when this item is returned via API.
2164    pub id: String,
2165    /// The unique ID of the function shell tool call generated by the model.
2166    pub call_id: String,
2167    /// The shell commands and limits that describe how to run the tool call.
2168    pub action: FunctionShellAction,
2169    /// The status of the shell call. One of `in_progress`, `completed`, or `incomplete`.
2170    pub status: LocalShellCallStatus,
2171    /// The ID of the entity that created this tool call.
2172    #[serde(skip_serializing_if = "Option::is_none")]
2173    pub created_by: Option<String>,
2174}
2175
2176/// The content of a shell tool call output that was emitted.
2177#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2178pub struct FunctionShellCallOutputContent {
2179    /// The standard output that was captured.
2180    pub stdout: String,
2181    /// The standard error output that was captured.
2182    pub stderr: String,
2183    /// Represents either an exit outcome (with an exit code) or a timeout outcome for a shell call output chunk.
2184    #[serde(flatten)]
2185    pub outcome: FunctionShellCallOutputOutcome,
2186    /// The identifier of the actor that created the item.
2187    #[serde(skip_serializing_if = "Option::is_none")]
2188    pub created_by: Option<String>,
2189}
2190
2191/// Function shell call outcome
2192#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2193#[serde(tag = "type", rename_all = "snake_case")]
2194pub enum FunctionShellCallOutputOutcome {
2195    Timeout,
2196    Exit(FunctionShellCallOutputExitOutcome),
2197}
2198
2199/// Indicates that the shell commands finished and returned an exit code.
2200#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2201pub struct FunctionShellCallOutputExitOutcome {
2202    /// Exit code from the shell process.
2203    pub exit_code: i32,
2204}
2205
2206/// The output of a shell tool call that was emitted.
2207#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2208pub struct FunctionShellCallOutput {
2209    /// The unique ID of the shell call output. Populated when this item is returned via API.
2210    pub id: String,
2211    /// The unique ID of the shell tool call generated by the model.
2212    pub call_id: String,
2213    /// An array of shell call output contents
2214    pub output: Vec<FunctionShellCallOutputContent>,
2215    /// The maximum length of the shell command output. This is generated by the model and should be
2216    /// passed back with the raw output.
2217    pub max_output_length: Option<u64>,
2218    /// The identifier of the actor that created the item.
2219    #[serde(skip_serializing_if = "Option::is_none")]
2220    pub created_by: Option<String>,
2221}
2222
2223/// Status values reported for apply_patch tool calls.
2224#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
2225#[serde(rename_all = "snake_case")]
2226pub enum ApplyPatchCallStatus {
2227    InProgress,
2228    Completed,
2229}
2230
2231/// Instruction describing how to create a file via the apply_patch tool.
2232#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2233pub struct ApplyPatchCreateFileOperation {
2234    /// Path of the file to create.
2235    pub path: String,
2236    /// Diff to apply.
2237    pub diff: String,
2238}
2239
2240/// Instruction describing how to delete a file via the apply_patch tool.
2241#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2242pub struct ApplyPatchDeleteFileOperation {
2243    /// Path of the file to delete.
2244    pub path: String,
2245}
2246
2247/// Instruction describing how to update a file via the apply_patch tool.
2248#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2249pub struct ApplyPatchUpdateFileOperation {
2250    /// Path of the file to update.
2251    pub path: String,
2252    /// Diff to apply.
2253    pub diff: String,
2254}
2255
2256/// One of the create_file, delete_file, or update_file operations applied via apply_patch.
2257#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2258#[serde(tag = "type", rename_all = "snake_case")]
2259pub enum ApplyPatchOperation {
2260    CreateFile(ApplyPatchCreateFileOperation),
2261    DeleteFile(ApplyPatchDeleteFileOperation),
2262    UpdateFile(ApplyPatchUpdateFileOperation),
2263}
2264
2265/// A tool call that applies file diffs by creating, deleting, or updating files.
2266#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2267pub struct ApplyPatchToolCall {
2268    /// The unique ID of the apply patch tool call. Populated when this item is returned via API.
2269    pub id: String,
2270    /// The unique ID of the apply patch tool call generated by the model.
2271    pub call_id: String,
2272    /// The status of the apply patch tool call. One of `in_progress` or `completed`.
2273    pub status: ApplyPatchCallStatus,
2274    /// One of the create_file, delete_file, or update_file operations applied via apply_patch.
2275    pub operation: ApplyPatchOperation,
2276    /// The ID of the entity that created this tool call.
2277    #[serde(skip_serializing_if = "Option::is_none")]
2278    pub created_by: Option<String>,
2279}
2280
2281/// Outcome values reported for apply_patch tool call outputs.
2282#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
2283#[serde(rename_all = "snake_case")]
2284pub enum ApplyPatchCallOutputStatus {
2285    Completed,
2286    Failed,
2287}
2288
2289/// The output emitted by an apply patch tool call.
2290#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2291pub struct ApplyPatchToolCallOutput {
2292    /// The unique ID of the apply patch tool call output. Populated when this item is returned via API.
2293    pub id: String,
2294    /// The unique ID of the apply patch tool call generated by the model.
2295    pub call_id: String,
2296    /// The status of the apply patch tool call output. One of `completed` or `failed`.
2297    pub status: ApplyPatchCallOutputStatus,
2298    /// Optional textual output returned by the apply patch tool.
2299    pub output: Option<String>,
2300    /// The ID of the entity that created this tool call output.
2301    #[serde(skip_serializing_if = "Option::is_none")]
2302    pub created_by: Option<String>,
2303}
2304
2305/// Output of an MCP server tool invocation.
2306#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2307pub struct MCPToolCall {
2308    /// A JSON string of the arguments passed to the tool.
2309    pub arguments: String,
2310    /// The unique ID of the tool call.
2311    pub id: String,
2312    /// The name of the tool that was run.
2313    pub name: String,
2314    /// The label of the MCP server running the tool.
2315    pub server_label: String,
2316    /// Unique identifier for the MCP tool call approval request. Include this value
2317    /// in a subsequent `mcp_approval_response` input to approve or reject the corresponding
2318    /// tool call.
2319    pub approval_request_id: Option<String>,
2320    /// Error message from the call, if any.
2321    pub error: Option<String>,
2322    /// The output from the tool call.
2323    pub output: Option<String>,
2324    /// The status of the tool call. One of `in_progress`, `completed`, `incomplete`,
2325    /// `calling`, or `failed`.
2326    pub status: Option<MCPToolCallStatus>,
2327}
2328
2329#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2330#[serde(rename_all = "snake_case")]
2331pub enum MCPToolCallStatus {
2332    InProgress,
2333    Completed,
2334    Incomplete,
2335    Calling,
2336    Failed,
2337}
2338
2339#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2340pub struct MCPListTools {
2341    /// The unique ID of the list.
2342    pub id: String,
2343    /// The label of the MCP server.
2344    pub server_label: String,
2345    /// The tools available on the server.
2346    pub tools: Vec<MCPListToolsTool>,
2347    /// Error message if listing failed.
2348    #[serde(skip_serializing_if = "Option::is_none")]
2349    pub error: Option<String>,
2350}
2351
2352#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2353pub struct MCPApprovalRequest {
2354    /// JSON string of arguments for the tool.
2355    pub arguments: String,
2356    /// The unique ID of the approval request.
2357    pub id: String,
2358    /// The name of the tool to run.
2359    pub name: String,
2360    /// The label of the MCP server making the request.
2361    pub server_label: String,
2362}
2363
2364#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2365#[serde(untagged)]
2366pub enum Instructions {
2367    /// A text input to the model, equivalent to a text input with the `developer` role.
2368    Text(String),
2369    /// A list of one or many input items to the model, containing different content types.
2370    Array(Vec<InputItem>),
2371}
2372
2373/// The complete response returned by the Responses API.
2374#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2375pub struct Response {
2376    /// Whether to run the model response in the background.
2377    /// [Learn more](https://platform.openai.com/docs/guides/background).
2378    #[serde(skip_serializing_if = "Option::is_none")]
2379    pub background: Option<bool>,
2380
2381    /// Billing information for the response.
2382    #[serde(skip_serializing_if = "Option::is_none")]
2383    pub billing: Option<Billing>,
2384
2385    /// The conversation that this response belongs to. Input items and output
2386    /// items from this response are automatically added to this conversation.
2387    #[serde(skip_serializing_if = "Option::is_none")]
2388    pub conversation: Option<Conversation>,
2389
2390    /// Unix timestamp (in seconds) when this Response was created.
2391    pub created_at: u64,
2392
2393    /// Unix timestamp (in seconds) of when this Response was completed.
2394    /// Only present when the status is `completed`.
2395    #[serde(skip_serializing_if = "Option::is_none")]
2396    pub completed_at: Option<u64>,
2397
2398    /// An error object returned when the model fails to generate a Response.
2399    #[serde(skip_serializing_if = "Option::is_none")]
2400    pub error: Option<ErrorObject>,
2401
2402    /// Unique identifier for this response.
2403    pub id: String,
2404
2405    /// Details about why the response is incomplete, if any.
2406    #[serde(skip_serializing_if = "Option::is_none")]
2407    pub incomplete_details: Option<IncompleteDetails>,
2408
2409    /// A system (or developer) message inserted into the model's context.
2410    ///
2411    /// When using along with `previous_response_id`, the instructions from a previous response
2412    /// will not be carried over to the next response. This makes it simple to swap out
2413    /// system (or developer) messages in new responses.
2414    #[serde(skip_serializing_if = "Option::is_none")]
2415    pub instructions: Option<Instructions>,
2416
2417    /// An upper bound for the number of tokens that can be generated for a response,
2418    /// including visible output tokens and
2419    /// [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
2420    #[serde(skip_serializing_if = "Option::is_none")]
2421    pub max_output_tokens: Option<u32>,
2422
2423    /// Set of 16 key-value pairs that can be attached to an object. This can be
2424    /// useful for storing additional information about the object in a structured
2425    /// format, and querying for objects via API or the dashboard.
2426    ///
2427    /// Keys are strings with a maximum length of 64 characters. Values are strings
2428    /// with a maximum length of 512 characters.
2429    #[serde(skip_serializing_if = "Option::is_none")]
2430    pub metadata: Option<HashMap<String, String>>,
2431
2432    /// Model ID used to generate the response, like gpt-4o or o3. OpenAI offers a
2433    /// wide range of models with different capabilities, performance characteristics,
2434    /// and price points. Refer to the [model guide](https://platform.openai.com/docs/models) to browse and compare available models.
2435    pub model: String,
2436
2437    /// The object type of this resource - always set to `response`.
2438    pub object: String,
2439
2440    /// An array of content items generated by the model.
2441    ///
2442    /// - The length and order of items in the output array is dependent on the model's response.
2443    /// - Rather than accessing the first item in the output array and assuming it's an assistant
2444    ///   message with the content generated by the model, you might consider using
2445    ///   the `output_text` property where supported in SDKs.
2446    pub output: Vec<OutputItem>,
2447
2448    /// SDK-only convenience property that contains the aggregated text output from all
2449    /// `output_text` items in the `output` array, if any are present.
2450    /// Supported in the Python and JavaScript SDKs.
2451    // #[serde(skip_serializing_if = "Option::is_none")]
2452    // pub output_text: Option<String>,
2453
2454    /// Whether to allow the model to run tool calls in parallel.
2455    #[serde(skip_serializing_if = "Option::is_none")]
2456    pub parallel_tool_calls: Option<bool>,
2457
2458    /// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
2459    /// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
2460    /// Cannot be used in conjunction with `conversation`.
2461    #[serde(skip_serializing_if = "Option::is_none")]
2462    pub previous_response_id: Option<String>,
2463
2464    /// Reference to a prompt template and its variables.
2465    /// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
2466    #[serde(skip_serializing_if = "Option::is_none")]
2467    pub prompt: Option<Prompt>,
2468
2469    /// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
2470    /// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
2471    #[serde(skip_serializing_if = "Option::is_none")]
2472    pub prompt_cache_key: Option<String>,
2473
2474    /// The retention policy for the prompt cache. Set to `24h` to enable extended prompt caching,
2475    /// which keeps cached prefixes active for longer, up to a maximum of 24 hours. [Learn
2476    /// more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).    
2477    #[serde(skip_serializing_if = "Option::is_none")]
2478    pub prompt_cache_retention: Option<PromptCacheRetention>,
2479
2480    /// **gpt-5 and o-series models only**
2481    /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
2482    #[serde(skip_serializing_if = "Option::is_none")]
2483    pub reasoning: Option<Reasoning>,
2484
2485    /// A stable identifier used to help detect users of your application that may be violating OpenAI's
2486    /// usage policies.
2487    ///
2488    /// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
2489    /// or email address, in order to avoid sending us any identifying information. [Learn
2490    /// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
2491    #[serde(skip_serializing_if = "Option::is_none")]
2492    pub safety_identifier: Option<String>,
2493
2494    /// Specifies the processing type used for serving the request.
2495    /// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
2496    /// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
2497    /// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
2498    /// - When not set, the default behavior is 'auto'.
2499    ///
2500    /// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
2501    #[serde(skip_serializing_if = "Option::is_none")]
2502    pub service_tier: Option<ServiceTier>,
2503
2504    /// The status of the response generation.
2505    /// One of `completed`, `failed`, `in_progress`, `cancelled`, `queued`, or `incomplete`.
2506    pub status: Status,
2507
2508    /// What sampling temperature was used, between 0 and 2. Higher values like 0.8 make
2509    /// outputs more random, lower values like 0.2 make output more focused and deterministic.
2510    ///
2511    /// We generally recommend altering this or `top_p` but not both.
2512    #[serde(skip_serializing_if = "Option::is_none")]
2513    pub temperature: Option<f32>,
2514
2515    /// Configuration options for a text response from the model. Can be plain
2516    /// text or structured JSON data. Learn more:
2517    /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
2518    /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
2519    #[serde(skip_serializing_if = "Option::is_none")]
2520    pub text: Option<ResponseTextParam>,
2521
2522    /// How the model should select which tool (or tools) to use when generating
2523    /// a response. See the `tools` parameter to see how to specify which tools
2524    /// the model can call.
2525    #[serde(skip_serializing_if = "Option::is_none")]
2526    pub tool_choice: Option<ToolChoiceParam>,
2527
2528    /// An array of tools the model may call while generating a response. You
2529    /// can specify which tool to use by setting the `tool_choice` parameter.
2530    ///
2531    /// We support the following categories of tools:
2532    /// - **Built-in tools**: Tools that are provided by OpenAI that extend the
2533    ///   model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
2534    ///   or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
2535    ///   [built-in tools](https://platform.openai.com/docs/guides/tools).
2536    /// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
2537    ///   or predefined connectors such as Google Drive and SharePoint. Learn more about
2538    ///   [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
2539    /// - **Function calls (custom tools)**: Functions that are defined by you,
2540    ///   enabling the model to call your own code with strongly typed arguments
2541    ///   and outputs. Learn more about
2542    ///   [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
2543    ///   custom tools to call your own code.
2544    #[serde(skip_serializing_if = "Option::is_none")]
2545    pub tools: Option<Vec<Tool>>,
2546
2547    /// An integer between 0 and 20 specifying the number of most likely tokens to return at each
2548    /// token position, each with an associated log probability.
2549    #[serde(skip_serializing_if = "Option::is_none")]
2550    pub top_logprobs: Option<u8>,
2551
2552    /// An alternative to sampling with temperature, called nucleus sampling,
2553    /// where the model considers the results of the tokens with top_p probability
2554    /// mass. So 0.1 means only the tokens comprising the top 10% probability mass
2555    /// are considered.
2556    ///
2557    /// We generally recommend altering this or `temperature` but not both.
2558    #[serde(skip_serializing_if = "Option::is_none")]
2559    pub top_p: Option<f32>,
2560
2561    ///The truncation strategy to use for the model response.
2562    /// - `auto`: If the input to this Response exceeds
2563    ///   the model's context window size, the model will truncate the
2564    ///   response to fit the context window by dropping items from the beginning of the conversation.
2565    /// - `disabled` (default): If the input size will exceed the context window
2566    ///   size for a model, the request will fail with a 400 error.
2567    #[serde(skip_serializing_if = "Option::is_none")]
2568    pub truncation: Option<Truncation>,
2569
2570    /// Represents token usage details including input tokens, output tokens,
2571    /// a breakdown of output tokens, and the total tokens used.
2572    #[serde(skip_serializing_if = "Option::is_none")]
2573    pub usage: Option<ResponseUsage>,
2574}
2575
2576#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2577#[serde(rename_all = "snake_case")]
2578pub enum Status {
2579    Completed,
2580    Failed,
2581    InProgress,
2582    Cancelled,
2583    Queued,
2584    Incomplete,
2585}
2586
2587/// Output item
2588#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2589#[serde(tag = "type")]
2590#[serde(rename_all = "snake_case")]
2591pub enum OutputItem {
2592    /// An output message from the model.
2593    Message(OutputMessage),
2594    /// The results of a file search tool call. See the
2595    /// [file search guide](https://platform.openai.com/docs/guides/tools-file-search)
2596    /// for more information.
2597    FileSearchCall(FileSearchToolCall),
2598    /// A tool call to run a function. See the
2599    /// [function calling guide](https://platform.openai.com/docs/guides/function-calling)
2600    /// for more information.
2601    FunctionCall(FunctionToolCall),
2602    /// The results of a web search tool call. See the
2603    /// [web search guide](https://platform.openai.com/docs/guides/tools-web-search)
2604    /// for more information.
2605    WebSearchCall(WebSearchToolCall),
2606    /// A tool call to a computer use tool. See the
2607    /// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use)
2608    /// for more information.
2609    ComputerCall(ComputerToolCall),
2610    /// A description of the chain of thought used by a reasoning model while generating
2611    /// a response. Be sure to include these items in your `input` to the Responses API for
2612    /// subsequent turns of a conversation if you are manually
2613    /// [managing context](https://platform.openai.com/docs/guides/conversation-state).
2614    Reasoning(ReasoningItem),
2615    /// A compaction item generated by the [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).
2616    Compaction(CompactionBody),
2617    /// An image generation request made by the model.
2618    ImageGenerationCall(ImageGenToolCall),
2619    /// A tool call to run code.
2620    CodeInterpreterCall(CodeInterpreterToolCall),
2621    /// A tool call to run a command on the local shell.
2622    LocalShellCall(LocalShellToolCall),
2623    /// A tool call that executes one or more shell commands in a managed environment.
2624    ShellCall(FunctionShellCall),
2625    /// The output of a shell tool call.
2626    ShellCallOutput(FunctionShellCallOutput),
2627    /// A tool call that applies file diffs by creating, deleting, or updating files.
2628    ApplyPatchCall(ApplyPatchToolCall),
2629    /// The output emitted by an apply patch tool call.
2630    ApplyPatchCallOutput(ApplyPatchToolCallOutput),
2631    /// An invocation of a tool on an MCP server.
2632    McpCall(MCPToolCall),
2633    /// A list of tools available on an MCP server.
2634    McpListTools(MCPListTools),
2635    /// A request for human approval of a tool invocation.
2636    McpApprovalRequest(MCPApprovalRequest),
2637    /// A call to a custom tool created by the model.
2638    CustomToolCall(CustomToolCall),
2639}
2640
2641#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2642#[non_exhaustive]
2643pub struct CustomToolCall {
2644    /// An identifier used to map this custom tool call to a tool call output.
2645    pub call_id: String,
2646    /// The input for the custom tool call generated by the model.
2647    pub input: String,
2648    /// The name of the custom tool being called.
2649    pub name: String,
2650    /// The unique ID of the custom tool call in the OpenAI platform.
2651    pub id: String,
2652}
2653
2654#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2655pub struct DeleteResponse {
2656    pub object: String,
2657    pub deleted: bool,
2658    pub id: String,
2659}
2660
2661#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2662pub struct AnyItemReference {
2663    pub r#type: Option<String>,
2664    pub id: String,
2665}
2666
2667#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2668#[serde(tag = "type", rename_all = "snake_case")]
2669pub enum ItemResourceItem {
2670    Message(MessageItem),
2671    FileSearchCall(FileSearchToolCall),
2672    ComputerCall(ComputerToolCall),
2673    ComputerCallOutput(ComputerCallOutputItemParam),
2674    WebSearchCall(WebSearchToolCall),
2675    FunctionCall(FunctionToolCall),
2676    FunctionCallOutput(FunctionCallOutputItemParam),
2677    ImageGenerationCall(ImageGenToolCall),
2678    CodeInterpreterCall(CodeInterpreterToolCall),
2679    LocalShellCall(LocalShellToolCall),
2680    LocalShellCallOutput(LocalShellToolCallOutput),
2681    ShellCall(FunctionShellCallItemParam),
2682    ShellCallOutput(FunctionShellCallOutputItemParam),
2683    ApplyPatchCall(ApplyPatchToolCallItemParam),
2684    ApplyPatchCallOutput(ApplyPatchToolCallOutputItemParam),
2685    McpListTools(MCPListTools),
2686    McpApprovalRequest(MCPApprovalRequest),
2687    McpApprovalResponse(MCPApprovalResponse),
2688    McpCall(MCPToolCall),
2689}
2690
2691#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2692#[serde(untagged)]
2693pub enum ItemResource {
2694    ItemReference(AnyItemReference),
2695    Item(ItemResourceItem),
2696}
2697
2698/// A list of Response items.
2699#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2700pub struct ResponseItemList {
2701    /// The type of object returned, must be `list`.
2702    pub object: String,
2703    /// The ID of the first item in the list.
2704    pub first_id: Option<String>,
2705    /// The ID of the last item in the list.
2706    pub last_id: Option<String>,
2707    /// Whether there are more items in the list.
2708    pub has_more: bool,
2709    /// The list of items.
2710    pub data: Vec<ItemResource>,
2711}
2712
2713#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
2714#[builder(
2715    name = "TokenCountsBodyArgs",
2716    pattern = "mutable",
2717    setter(into, strip_option),
2718    default
2719)]
2720#[builder(build_fn(error = "OpenAIError"))]
2721pub struct TokenCountsBody {
2722    /// The conversation that this response belongs to. Items from this
2723    /// conversation are prepended to `input_items` for this response request.
2724    /// Input items and output items from this response are automatically added to this
2725    /// conversation after this response completes.
2726    #[serde(skip_serializing_if = "Option::is_none")]
2727    pub conversation: Option<ConversationParam>,
2728
2729    /// Text, image, or file inputs to the model, used to generate a response
2730    #[serde(skip_serializing_if = "Option::is_none")]
2731    pub input: Option<InputParam>,
2732
2733    /// A system (or developer) message inserted into the model's context.
2734    ///
2735    /// When used along with `previous_response_id`, the instructions from a previous response will
2736    /// not be carried over to the next response. This makes it simple to swap out system (or
2737    /// developer) messages in new responses.
2738    #[serde(skip_serializing_if = "Option::is_none")]
2739    pub instructions: Option<String>,
2740
2741    /// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
2742    /// wide range of models with different capabilities, performance characteristics,
2743    /// and price points. Refer to the [model guide](https://platform.openai.com/docs/models)
2744    /// to browse and compare available models.
2745    #[serde(skip_serializing_if = "Option::is_none")]
2746    pub model: Option<String>,
2747
2748    /// Whether to allow the model to run tool calls in parallel.
2749    #[serde(skip_serializing_if = "Option::is_none")]
2750    pub parallel_tool_calls: Option<bool>,
2751
2752    /// The unique ID of the previous response to the model. Use this to create multi-turn
2753    /// conversations. Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
2754    /// Cannot be used in conjunction with `conversation`.
2755    #[serde(skip_serializing_if = "Option::is_none")]
2756    pub previous_response_id: Option<String>,
2757
2758    /// **gpt-5 and o-series models only**
2759    /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
2760    #[serde(skip_serializing_if = "Option::is_none")]
2761    pub reasoning: Option<Reasoning>,
2762
2763    /// Configuration options for a text response from the model. Can be plain
2764    /// text or structured JSON data. Learn more:
2765    /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
2766    /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
2767    #[serde(skip_serializing_if = "Option::is_none")]
2768    pub text: Option<ResponseTextParam>,
2769
2770    /// How the model should select which tool (or tools) to use when generating
2771    /// a response. See the `tools` parameter to see how to specify which tools
2772    /// the model can call.
2773    #[serde(skip_serializing_if = "Option::is_none")]
2774    pub tool_choice: Option<ToolChoiceParam>,
2775
2776    /// An array of tools the model may call while generating a response. You can specify which tool
2777    /// to use by setting the `tool_choice` parameter.
2778    #[serde(skip_serializing_if = "Option::is_none")]
2779    pub tools: Option<Vec<Tool>>,
2780
2781    ///The truncation strategy to use for the model response.
2782    /// - `auto`: If the input to this Response exceeds
2783    ///   the model's context window size, the model will truncate the
2784    ///   response to fit the context window by dropping items from the beginning of the conversation.
2785    /// - `disabled` (default): If the input size will exceed the context window
2786    ///   size for a model, the request will fail with a 400 error.
2787    #[serde(skip_serializing_if = "Option::is_none")]
2788    pub truncation: Option<Truncation>,
2789}
2790
2791#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2792pub struct TokenCountsResource {
2793    pub object: String,
2794    pub input_tokens: u32,
2795}
2796
2797/// A compaction item generated by the `/v1/responses/compact` API.
2798#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2799pub struct CompactionSummaryItemParam {
2800    /// The ID of the compaction item.
2801    #[serde(skip_serializing_if = "Option::is_none")]
2802    pub id: Option<String>,
2803    /// The encrypted content of the compaction summary.
2804    pub encrypted_content: String,
2805}
2806
2807/// A compaction item generated by the `/v1/responses/compact` API.
2808#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2809pub struct CompactionBody {
2810    /// The unique ID of the compaction item.
2811    pub id: String,
2812    /// The encrypted content that was produced by compaction.
2813    pub encrypted_content: String,
2814    /// The identifier of the actor that created the item.
2815    #[serde(skip_serializing_if = "Option::is_none")]
2816    pub created_by: Option<String>,
2817}
2818
2819/// Request to compact a conversation.
2820#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
2821#[builder(name = "CompactResponseRequestArgs")]
2822#[builder(pattern = "mutable")]
2823#[builder(setter(into, strip_option), default)]
2824#[builder(derive(Debug))]
2825#[builder(build_fn(error = "OpenAIError"))]
2826pub struct CompactResponseRequest {
2827    /// Model ID used to generate the response, like `gpt-5` or `o3`. OpenAI offers a wide range of models
2828    /// with different capabilities, performance characteristics, and price points. Refer to the
2829    /// [model guide](https://platform.openai.com/docs/models) to browse and compare available models.
2830    pub model: String,
2831
2832    /// Text, image, or file inputs to the model, used to generate a response
2833    #[serde(skip_serializing_if = "Option::is_none")]
2834    pub input: Option<InputParam>,
2835
2836    /// The unique ID of the previous response to the model. Use this to create multi-turn
2837    /// conversations. Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
2838    /// Cannot be used in conjunction with `conversation`.
2839    #[serde(skip_serializing_if = "Option::is_none")]
2840    pub previous_response_id: Option<String>,
2841
2842    /// A system (or developer) message inserted into the model's context.
2843    ///
2844    /// When used along with `previous_response_id`, the instructions from a previous response will
2845    /// not be carried over to the next response. This makes it simple to swap out system (or
2846    /// developer) messages in new responses.
2847    #[serde(skip_serializing_if = "Option::is_none")]
2848    pub instructions: Option<String>,
2849}
2850
2851/// The compacted response object.
2852#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2853pub struct CompactResource {
2854    /// The unique identifier for the compacted response.
2855    pub id: String,
2856    /// The object type. Always `response.compaction`.
2857    pub object: String,
2858    /// The compacted list of output items. This is a list of all user messages,
2859    /// followed by a single compaction item.
2860    pub output: Vec<OutputItem>,
2861    /// Unix timestamp (in seconds) when the compacted conversation was created.
2862    pub created_at: u64,
2863    /// Token accounting for the compaction pass, including cached, reasoning, and total tokens.
2864    pub usage: ResponseUsage,
2865}