async_openai/types/responses/
response.rs

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