async_openai_wasm/types/
responses.rs

1use crate::OpenAIEventStream;
2use crate::error::OpenAIError;
3pub use crate::types::{
4    CompletionTokensDetails, ImageDetail, PromptTokensDetails, ReasoningEffort,
5    ResponseFormatJsonSchema,
6};
7use derive_builder::Builder;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use std::collections::HashMap;
11
12/// Role of messages in the API.
13#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
14#[serde(rename_all = "lowercase")]
15pub enum Role {
16    User,
17    Assistant,
18    System,
19    Developer,
20}
21
22/// Status of input/output items.
23#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
24#[serde(rename_all = "snake_case")]
25pub enum OutputStatus {
26    InProgress,
27    Completed,
28    Incomplete,
29}
30
31/// Input payload: raw text or structured context items.
32#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
33#[serde(untagged)]
34pub enum Input {
35    /// A text input to the model, equivalent to a text input with the user role.
36    Text(String),
37    /// A list of one or many input items to the model, containing different content types.
38    Items(Vec<InputItem>),
39}
40
41/// A context item: currently only messages.
42#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
43#[serde(untagged, rename_all = "snake_case")]
44pub enum InputItem {
45    Message(InputMessage),
46    Custom(serde_json::Value),
47}
48
49/// A message to prime the model.
50#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
51#[builder(
52    name = "InputMessageArgs",
53    pattern = "mutable",
54    setter(into, strip_option),
55    default
56)]
57#[builder(build_fn(error = "OpenAIError"))]
58pub struct InputMessage {
59    #[serde(default, rename = "type")]
60    pub kind: InputMessageType,
61    /// The role of the message input.
62    pub role: Role,
63    /// Text, image, or audio input to the model, used to generate a response. Can also contain
64    /// previous assistant responses.
65    pub content: InputContent,
66}
67
68#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
69#[serde(rename_all = "snake_case")]
70pub enum InputMessageType {
71    #[default]
72    Message,
73}
74
75#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
76#[serde(untagged)]
77pub enum InputContent {
78    /// A text input to the model.
79    TextInput(String),
80    /// A list of one or many input items to the model, containing different content types.
81    InputItemContentList(Vec<ContentType>),
82}
83
84/// Parts of a message: text, image, file, or audio.
85#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
86#[serde(tag = "type", rename_all = "snake_case")]
87pub enum ContentType {
88    /// A text input to the model.
89    InputText(InputText),
90    /// An image input to the model.
91    InputImage(InputImage),
92    /// A file input to the model.
93    InputFile(InputFile),
94}
95
96#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
97pub struct InputText {
98    pub text: String,
99}
100
101#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
102#[builder(
103    name = "InputImageArgs",
104    pattern = "mutable",
105    setter(into, strip_option),
106    default
107)]
108#[builder(build_fn(error = "OpenAIError"))]
109pub struct InputImage {
110    /// The detail level of the image to be sent to the model.
111    detail: ImageDetail,
112    /// The ID of the file to be sent to the model.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    file_id: Option<String>,
115    /// The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image
116    /// in a data URL.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    image_url: Option<String>,
119}
120
121#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
122#[builder(
123    name = "InputFileArgs",
124    pattern = "mutable",
125    setter(into, strip_option),
126    default
127)]
128#[builder(build_fn(error = "OpenAIError"))]
129pub struct InputFile {
130    /// The content of the file to be sent to the model.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    file_data: Option<String>,
133    /// The ID of the file to be sent to the model.
134    #[serde(skip_serializing_if = "Option::is_none")]
135    file_id: Option<String>,
136    /// The name of the file to be sent to the model.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    filename: Option<String>,
139    /// The URL of the file to be sent to the model.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    file_url: Option<String>,
142}
143
144/// Builder for a Responses API request.
145#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
146#[builder(
147    name = "CreateResponseArgs",
148    pattern = "mutable",
149    setter(into, strip_option),
150    default
151)]
152#[builder(build_fn(error = "OpenAIError"))]
153pub struct CreateResponse {
154    /// Text, image, or file inputs to the model, used to generate a response.
155    pub input: Input,
156
157    /// Model ID used to generate the response, like `gpt-4o`.
158    /// OpenAI offers a wide range of models with different capabilities,
159    /// performance characteristics, and price points.
160    pub model: String,
161
162    /// Whether to run the model response in the background.
163    /// boolean or null.
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub background: Option<bool>,
166
167    /// Specify additional output data to include in the model response.
168    ///
169    /// Supported values:
170    /// - `file_search_call.results`
171    ///   Include the search results of the file search tool call.
172    /// - `message.input_image.image_url`
173    ///   Include image URLs from the input message.
174    /// - `computer_call_output.output.image_url`
175    ///   Include image URLs from the computer call output.
176    /// - `reasoning.encrypted_content`
177    ///   Include an encrypted version of reasoning tokens in reasoning item outputs.
178    ///   This enables reasoning items to be used in multi-turn conversations when
179    ///   using the Responses API statelessly (for example, when the `store` parameter
180    ///   is set to `false`, or when an organization is enrolled in the zero-data-
181    ///   retention program).
182    ///
183    /// If `None`, no additional data is returned.
184    #[serde(skip_serializing_if = "Option::is_none")]
185    pub include: Option<Vec<String>>,
186
187    /// Inserts a system (or developer) message as the first item in the model's context.
188    ///
189    /// When using along with previous_response_id, the instructions from a previous response will
190    /// not be carried over to the next response. This makes it simple to swap out system
191    /// (or developer) messages in new responses.
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub instructions: Option<String>,
194
195    /// An upper bound for the number of tokens that can be generated for a
196    /// response, including visible output tokens and reasoning tokens.
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub max_output_tokens: Option<u32>,
199
200    /// The maximum number of total calls to built-in tools that can be processed in a response.
201    /// This maximum number applies across all built-in tool calls, not per individual tool.
202    /// Any further attempts to call a tool by the model will be ignored.
203    pub max_tool_calls: Option<u32>,
204
205    /// Set of 16 key-value pairs that can be attached to an object. This can be
206    /// useful for storing additional information about the object in a structured
207    /// format, and querying for objects via API or the dashboard.
208    ///
209    /// Keys are strings with a maximum length of 64 characters. Values are
210    /// strings with a maximum length of 512 characters.
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub metadata: Option<HashMap<String, String>>,
213
214    /// Whether to allow the model to run tool calls in parallel.
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub parallel_tool_calls: Option<bool>,
217
218    /// The unique ID of the previous response to the model. Use this to create
219    /// multi-turn conversations.
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub previous_response_id: Option<String>,
222
223    /// Reference to a prompt template and its variables.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub prompt: Option<PromptConfig>,
226
227    /// **o-series models only**: Configuration options for reasoning models.
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub reasoning: Option<ReasoningConfig>,
230
231    /// Specifies the latency tier to use for processing the request.
232    ///
233    /// This parameter is relevant for customers subscribed to the Scale tier service.
234    ///
235    /// Supported values:
236    /// - `auto`
237    ///   - If the Project is Scale tier enabled, the system will utilize Scale tier credits until
238    ///     they are exhausted.
239    ///   - If the Project is not Scale tier enabled, the request will be processed using the
240    ///     default service tier with a lower uptime SLA and no latency guarantee.
241    /// - `default`
242    ///   The request will be processed using the default service tier with a lower uptime SLA and
243    ///   no latency guarantee.
244    /// - `flex`
245    ///   The request will be processed with the Flex Processing service tier. Learn more.
246    ///
247    /// When not set, the default behavior is `auto`.
248    ///
249    /// When this parameter is set, the response body will include the `service_tier` utilized.
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub service_tier: Option<ServiceTier>,
252
253    /// Whether to store the generated model response for later retrieval via API.
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub store: Option<bool>,
256
257    /// If set to true, the model response data will be streamed to the client as it is
258    /// generated using server-sent events.
259    #[serde(skip_serializing_if = "Option::is_none")]
260    pub stream: Option<bool>,
261
262    /// What sampling temperature to use, between 0 and 2. Higher values like 0.8
263    /// will make the output more random, while lower values like 0.2 will make it
264    /// more focused and deterministic. We generally recommend altering this or
265    /// `top_p` but not both.
266    #[serde(skip_serializing_if = "Option::is_none")]
267    pub temperature: Option<f32>,
268
269    /// Configuration options for a text response from the model. Can be plain text
270    /// or structured JSON data.
271    #[serde(skip_serializing_if = "Option::is_none")]
272    pub text: Option<TextConfig>,
273
274    /// How the model should select which tool (or tools) to use when generating
275    /// a response.
276    #[serde(skip_serializing_if = "Option::is_none")]
277    pub tool_choice: Option<ToolChoice>,
278
279    /// An array of tools the model may call while generating a response.
280    /// Can include built-in tools (file_search, web_search_preview,
281    /// computer_use_preview) or custom function definitions.
282    #[serde(skip_serializing_if = "Option::is_none")]
283    pub tools: Option<Vec<ToolDefinition>>,
284
285    /// An integer between 0 and 20 specifying the number of most likely tokens to return
286    /// at each token position, each with an associated log probability.
287    #[serde(skip_serializing_if = "Option::is_none")]
288    pub top_logprobs: Option<u32>, // TODO add validation of range
289
290    /// An alternative to sampling with temperature, called nucleus sampling,
291    /// where the model considers the results of the tokens with top_p probability
292    /// mass. So 0.1 means only the tokens comprising the top 10% probability mass
293    /// are considered. We generally recommend altering this or `temperature` but
294    /// not both.
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub top_p: Option<f32>,
297
298    /// The truncation strategy to use for the model response:
299    /// - `auto`: drop items in the middle to fit context window.
300    /// - `disabled`: error if exceeding context window.
301    #[serde(skip_serializing_if = "Option::is_none")]
302    pub truncation: Option<Truncation>,
303
304    /// A unique identifier representing your end-user, which can help OpenAI to
305    /// monitor and detect abuse.
306    #[serde(skip_serializing_if = "Option::is_none")]
307    pub user: Option<String>,
308}
309
310/// Service tier request options.
311#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
312pub struct PromptConfig {
313    /// The unique identifier of the prompt template to use.
314    pub id: String,
315
316    /// Optional version of the prompt template.
317    #[serde(skip_serializing_if = "Option::is_none")]
318    pub version: Option<String>,
319
320    /// Optional map of values to substitute in for variables in your prompt. The substitution
321    /// values can either be strings, or other Response input types like images or files.
322    /// For now only supporting Strings.
323    #[serde(skip_serializing_if = "Option::is_none")]
324    pub variables: Option<HashMap<String, String>>,
325}
326
327/// Service tier request options.
328#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
329#[serde(rename_all = "lowercase")]
330pub enum ServiceTier {
331    Auto,
332    Default,
333    Flex,
334    Scale,
335    Priority,
336}
337
338/// Truncation strategies.
339#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
340#[serde(rename_all = "lowercase")]
341pub enum Truncation {
342    Auto,
343    Disabled,
344}
345
346/// o-series reasoning settings.
347#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
348#[builder(
349    name = "ReasoningConfigArgs",
350    pattern = "mutable",
351    setter(into, strip_option),
352    default
353)]
354#[builder(build_fn(error = "OpenAIError"))]
355pub struct ReasoningConfig {
356    /// Constrain effort on reasoning.
357    #[serde(skip_serializing_if = "Option::is_none")]
358    pub effort: Option<ReasoningEffort>,
359    /// Summary mode for reasoning.
360    #[serde(skip_serializing_if = "Option::is_none")]
361    pub summary: Option<ReasoningSummary>,
362}
363
364/// o-series reasoning settings.
365#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
366#[serde(rename_all = "lowercase")]
367pub enum Verbosity {
368    Low,
369    Medium,
370    High,
371}
372
373#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
374#[serde(rename_all = "lowercase")]
375pub enum ReasoningSummary {
376    Auto,
377    Concise,
378    Detailed,
379}
380
381/// Configuration for text response format.
382#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
383pub struct TextConfig {
384    /// Defines the format: plain text, JSON object, or JSON schema.
385    pub format: TextResponseFormat,
386
387    #[serde(skip_serializing_if = "Option::is_none")]
388    pub verbosity: Option<Verbosity>,
389}
390
391#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
392#[serde(tag = "type", rename_all = "snake_case")]
393pub enum TextResponseFormat {
394    /// The type of response format being defined: `text`
395    Text,
396    /// The type of response format being defined: `json_object`
397    JsonObject,
398    /// The type of response format being defined: `json_schema`
399    JsonSchema(ResponseFormatJsonSchema),
400}
401
402/// Definitions for model-callable tools.
403#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
404#[serde(tag = "type", rename_all = "snake_case")]
405pub enum ToolDefinition {
406    /// File search tool.
407    FileSearch(FileSearch),
408    /// Custom function call.
409    Function(Function),
410    /// Web search preview tool.
411    WebSearchPreview(WebSearchPreview),
412    /// Virtual computer control tool.
413    ComputerUsePreview(ComputerUsePreview),
414    /// Remote Model Context Protocol server.
415    Mcp(Mcp),
416    /// Python code interpreter tool.
417    CodeInterpreter(CodeInterpreter),
418    /// Image generation tool.
419    ImageGeneration(ImageGeneration),
420    /// Local shell command execution tool.
421    LocalShell,
422}
423
424#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
425#[builder(
426    name = "FileSearchArgs",
427    pattern = "mutable",
428    setter(into, strip_option),
429    default
430)]
431#[builder(build_fn(error = "OpenAIError"))]
432pub struct FileSearch {
433    /// The IDs of the vector stores to search.
434    pub vector_store_ids: Vec<String>,
435    /// The maximum number of results to return. This number should be between 1 and 50 inclusive.
436    #[serde(skip_serializing_if = "Option::is_none")]
437    pub max_num_results: Option<u32>,
438    /// A filter to apply.
439    #[serde(skip_serializing_if = "Option::is_none")]
440    pub filters: Option<Filter>,
441    /// Ranking options for search.
442    #[serde(skip_serializing_if = "Option::is_none")]
443    pub ranking_options: Option<RankingOptions>,
444}
445
446#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
447#[builder(
448    name = "FunctionArgs",
449    pattern = "mutable",
450    setter(into, strip_option),
451    default
452)]
453pub struct Function {
454    /// The name of the function to call.
455    pub name: String,
456    /// A JSON schema object describing the parameters of the function.
457    pub parameters: serde_json::Value,
458    /// Whether to enforce strict parameter validation.
459    pub strict: bool,
460    /// A description of the function. Used by the model to determine whether or not to call the
461    /// function.
462    #[serde(skip_serializing_if = "Option::is_none")]
463    pub description: Option<String>,
464}
465
466#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
467#[builder(
468    name = "WebSearchPreviewArgs",
469    pattern = "mutable",
470    setter(into, strip_option),
471    default
472)]
473pub struct WebSearchPreview {
474    /// The user's location.
475    #[serde(skip_serializing_if = "Option::is_none")]
476    pub user_location: Option<Location>,
477    /// High level guidance for the amount of context window space to use for the search.
478    #[serde(skip_serializing_if = "Option::is_none")]
479    pub search_context_size: Option<WebSearchContextSize>,
480}
481
482#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
483#[serde(rename_all = "lowercase")]
484pub enum WebSearchContextSize {
485    Low,
486    Medium,
487    High,
488}
489
490#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
491#[builder(
492    name = "ComputerUsePreviewArgs",
493    pattern = "mutable",
494    setter(into, strip_option),
495    default
496)]
497pub struct ComputerUsePreview {
498    /// The type of computer environment to control.
499    environment: String,
500    /// The width of the computer display.
501    display_width: u32,
502    /// The height of the computer display.
503    display_height: u32,
504}
505
506/// Options for search result ranking.
507#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
508pub struct RankingOptions {
509    /// The ranker to use for the file search.
510    pub ranker: String,
511    /// The score threshold for the file search, a number between 0 and 1. Numbers closer to 1 will
512    /// attempt to return only the most relevant results, but may return fewer results.
513    #[serde(skip_serializing_if = "Option::is_none")]
514    pub score_threshold: Option<f32>,
515}
516
517/// Filters for file search.
518#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
519#[serde(untagged)]
520pub enum Filter {
521    /// A filter used to compare a specified attribute key to a given value using a defined
522    /// comparison operation.
523    Comparison(ComparisonFilter),
524    /// Combine multiple filters using and or or.
525    Compound(CompoundFilter),
526}
527
528/// Single comparison filter.
529#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
530pub struct ComparisonFilter {
531    /// Specifies the comparison operator
532    #[serde(rename = "type")]
533    pub op: ComparisonType,
534    /// The key to compare against the value.
535    pub key: String,
536    /// The value to compare against the attribute key; supports string, number, or boolean types.
537    pub value: serde_json::Value,
538}
539
540#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
541pub enum ComparisonType {
542    #[serde(rename = "eq")]
543    Equals,
544    #[serde(rename = "ne")]
545    NotEquals,
546    #[serde(rename = "gt")]
547    GreaterThan,
548    #[serde(rename = "gte")]
549    GreaterThanOrEqualTo,
550    #[serde(rename = "lt")]
551    LessThan,
552    #[serde(rename = "lte")]
553    LessThanOrEqualTo,
554}
555
556/// Combine multiple filters.
557#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
558pub struct CompoundFilter {
559    /// Type of operation
560    #[serde(rename = "type")]
561    pub op: CompoundType,
562    /// Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.
563    pub filters: Vec<Filter>,
564}
565
566#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
567#[serde(rename_all = "lowercase")]
568pub enum CompoundType {
569    And,
570    Or,
571}
572
573/// Approximate user location for web search.
574#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
575#[builder(
576    name = "LocationArgs",
577    pattern = "mutable",
578    setter(into, strip_option),
579    default
580)]
581#[builder(build_fn(error = "OpenAIError"))]
582pub struct Location {
583    /// The type of location approximation. Always approximate.
584    #[serde(rename = "type")]
585    pub kind: String,
586    /// Free text input for the city of the user, e.g. San Francisco.
587    #[serde(skip_serializing_if = "Option::is_none")]
588    pub city: Option<String>,
589    /// The two-letter ISO country code of the user, e.g. US.
590    #[serde(skip_serializing_if = "Option::is_none")]
591    pub country: Option<String>,
592    /// Free text input for the region of the user, e.g. California.
593    #[serde(skip_serializing_if = "Option::is_none")]
594    pub region: Option<String>,
595    /// The IANA timezone of the user, e.g. America/Los_Angeles.
596    #[serde(skip_serializing_if = "Option::is_none")]
597    pub timezone: Option<String>,
598}
599
600/// MCP (Model Context Protocol) tool configuration.
601#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
602#[builder(
603    name = "McpArgs",
604    pattern = "mutable",
605    setter(into, strip_option),
606    default
607)]
608#[builder(build_fn(error = "OpenAIError"))]
609pub struct Mcp {
610    /// A label for this MCP server.
611    pub server_label: String,
612    /// The URL for the MCP server.
613    pub server_url: String,
614    /// List of allowed tool names or filter object.
615    #[serde(skip_serializing_if = "Option::is_none")]
616    pub allowed_tools: Option<AllowedTools>,
617    /// Optional HTTP headers for the MCP server.
618    #[serde(skip_serializing_if = "Option::is_none")]
619    pub headers: Option<Value>,
620    /// Approval policy or filter for tools.
621    #[serde(skip_serializing_if = "Option::is_none")]
622    pub require_approval: Option<RequireApproval>,
623}
624
625/// Allowed tools configuration for MCP.
626#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
627#[serde(untagged)]
628pub enum AllowedTools {
629    /// A flat list of allowed tool names.
630    List(Vec<String>),
631    /// A filter object specifying allowed tools.
632    Filter(McpAllowedToolsFilter),
633}
634
635/// Filter object for MCP allowed tools.
636#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
637pub struct McpAllowedToolsFilter {
638    /// Names of tools in the filter
639    #[serde(skip_serializing_if = "Option::is_none")]
640    pub tool_names: Option<Vec<String>>,
641}
642
643/// Approval policy or filter for MCP tools.
644#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
645#[serde(untagged)]
646pub enum RequireApproval {
647    /// A blanket policy: "always" or "never".
648    Policy(RequireApprovalPolicy),
649    /// A filter object specifying which tools require approval.
650    Filter(McpApprovalFilter),
651}
652
653#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
654#[serde(rename_all = "lowercase")]
655pub enum RequireApprovalPolicy {
656    Always,
657    Never,
658}
659
660/// Filter object for MCP tool approval.
661#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
662pub struct McpApprovalFilter {
663    /// A list of tools that always require approval.
664    #[serde(skip_serializing_if = "Option::is_none")]
665    pub always: Option<McpAllowedToolsFilter>,
666    /// A list of tools that never require approval.
667    #[serde(skip_serializing_if = "Option::is_none")]
668    pub never: Option<McpAllowedToolsFilter>,
669}
670
671/// Container configuration for a code interpreter.
672#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
673#[serde(untagged)]
674pub enum CodeInterpreterContainer {
675    /// A simple container ID.
676    Id(String),
677    /// Auto-configured container with optional files.
678    Container(CodeInterpreterContainerKind),
679}
680
681/// Auto configuration for code interpreter container.
682#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
683#[serde(tag = "type", rename_all = "snake_case")]
684pub enum CodeInterpreterContainerKind {
685    Auto {
686        /// Optional list of uploaded file IDs.
687        #[serde(skip_serializing_if = "Option::is_none")]
688        file_ids: Option<Vec<String>>,
689    },
690}
691
692/// Code interpreter tool definition.
693#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
694#[builder(
695    name = "CodeInterpreterArgs",
696    pattern = "mutable",
697    setter(into, strip_option),
698    default
699)]
700#[builder(build_fn(error = "OpenAIError"))]
701pub struct CodeInterpreter {
702    /// Container configuration for running code.
703    pub container: CodeInterpreterContainer,
704}
705
706/// Mask image input for image generation.
707#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
708pub struct InputImageMask {
709    /// Base64-encoded mask image.
710    #[serde(skip_serializing_if = "Option::is_none")]
711    pub image_url: Option<String>,
712    /// File ID for the mask image.
713    #[serde(skip_serializing_if = "Option::is_none")]
714    pub file_id: Option<String>,
715}
716
717/// Image generation tool definition.
718#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
719#[builder(
720    name = "ImageGenerationArgs",
721    pattern = "mutable",
722    setter(into, strip_option),
723    default
724)]
725#[builder(build_fn(error = "OpenAIError"))]
726pub struct ImageGeneration {
727    /// Background type: transparent, opaque, or auto.
728    #[serde(skip_serializing_if = "Option::is_none")]
729    pub background: Option<ImageGenerationBackground>,
730    /// Optional mask for inpainting.
731    #[serde(skip_serializing_if = "Option::is_none")]
732    pub input_image_mask: Option<InputImageMask>,
733    /// Model to use (default: gpt-image-1).
734    #[serde(skip_serializing_if = "Option::is_none")]
735    pub model: Option<String>,
736    /// Moderation level (default: auto).
737    #[serde(skip_serializing_if = "Option::is_none")]
738    pub moderation: Option<String>,
739    /// Compression level (0-100).
740    #[serde(skip_serializing_if = "Option::is_none")]
741    pub output_compression: Option<u8>,
742    /// Output format: png, webp, or jpeg.
743    #[serde(skip_serializing_if = "Option::is_none")]
744    pub output_format: Option<ImageGenerationOutputFormat>,
745    /// Number of partial images (0-3).
746    #[serde(skip_serializing_if = "Option::is_none")]
747    pub partial_images: Option<u8>,
748    /// Quality: low, medium, high, or auto.
749    #[serde(skip_serializing_if = "Option::is_none")]
750    pub quality: Option<ImageGenerationQuality>,
751    /// Size: e.g. "1024x1024" or auto.
752    #[serde(skip_serializing_if = "Option::is_none")]
753    pub size: Option<ImageGenerationSize>,
754}
755
756#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
757#[serde(rename_all = "lowercase")]
758pub enum ImageGenerationBackground {
759    Transparent,
760    Opaque,
761    Auto,
762}
763
764#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
765#[serde(rename_all = "lowercase")]
766pub enum ImageGenerationOutputFormat {
767    Png,
768    Webp,
769    Jpeg,
770}
771
772#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
773#[serde(rename_all = "lowercase")]
774pub enum ImageGenerationQuality {
775    Low,
776    Medium,
777    High,
778    Auto,
779}
780
781#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
782#[serde(rename_all = "lowercase")]
783pub enum ImageGenerationSize {
784    Auto,
785    #[serde(rename = "1024x1024")]
786    Size1024x1024,
787    #[serde(rename = "1024x1536")]
788    Size1024x1536,
789    #[serde(rename = "1536x1024")]
790    Size1536x1024,
791}
792
793/// Control how the model picks or is forced to pick a tool.
794#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
795#[serde(untagged)]
796pub enum ToolChoice {
797    /// Controls which (if any) tool is called by the model.
798    Mode(ToolChoiceMode),
799    /// Indicates that the model should use a built-in tool to generate a response.
800    Hosted {
801        /// The type of hosted tool the model should to use.
802        #[serde(rename = "type")]
803        kind: HostedToolType,
804    },
805    /// Use this option to force the model to call a specific function.
806    Function {
807        /// The name of the function to call.
808        name: String,
809    },
810}
811
812/// Simple tool-choice modes.
813#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
814#[serde(rename_all = "lowercase")]
815pub enum ToolChoiceMode {
816    /// The model will not call any tool and instead generates a message.
817    None,
818    /// The model can pick between generating a message or calling one or more tools.
819    Auto,
820    /// The model must call one or more tools.
821    Required,
822}
823
824/// Hosted tool type identifiers.
825#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
826#[serde(rename_all = "snake_case")]
827pub enum HostedToolType {
828    FileSearch,
829    WebSearchPreview,
830    ComputerUsePreview,
831}
832
833/// Error returned by the API when a request fails.
834#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
835pub struct ErrorObject {
836    /// The error code for the response.
837    pub code: String,
838    /// A human-readable description of the error.
839    pub message: String,
840}
841
842/// Details about an incomplete response.
843#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
844pub struct IncompleteDetails {
845    /// The reason why the response is incomplete.
846    pub reason: String,
847}
848
849/// A simple text output from the model.
850#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
851pub struct OutputText {
852    /// The annotations of the text output.
853    pub annotations: Vec<Annotation>,
854    /// The text output from the model.
855    pub text: String,
856}
857
858#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
859#[serde(tag = "type", rename_all = "snake_case")]
860pub enum Annotation {
861    /// A citation to a file.
862    FileCitation(FileCitation),
863    /// A citation for a web resource used to generate a model response.
864    UrlCitation(UrlCitation),
865    /// A path to a file.
866    FilePath(FilePath),
867}
868
869#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
870pub struct FileCitation {
871    /// The ID of the file.
872    file_id: String,
873    /// The index of the file in the list of files.
874    index: u32,
875}
876
877#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
878pub struct UrlCitation {
879    /// The index of the last character of the URL citation in the message.
880    end_index: u32,
881    /// The index of the first character of the URL citation in the message.
882    start_index: u32,
883    /// The title of the web resource.
884    title: String,
885    /// The URL of the web resource.
886    url: String,
887}
888
889#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
890pub struct FilePath {
891    /// The ID of the file.
892    file_id: String,
893    /// The index of the file in the list of files.
894    index: u32,
895}
896
897/// A refusal explanation from the model.
898#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
899pub struct Refusal {
900    /// The refusal explanationfrom the model.
901    pub refusal: String,
902}
903
904/// A message generated by the model.
905#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
906pub struct OutputMessage {
907    /// The content of the output message.
908    pub content: Vec<Content>,
909    /// The unique ID of the output message.
910    pub id: String,
911    /// The role of the output message. Always assistant.
912    pub role: Role,
913    /// The status of the message input.
914    pub status: OutputStatus,
915}
916
917#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
918#[serde(tag = "type", rename_all = "snake_case")]
919pub enum Content {
920    /// A text output from the model.
921    OutputText(OutputText),
922    /// A refusal from the model.
923    Refusal(Refusal),
924}
925
926/// Nested content within an output message.
927#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
928#[serde(tag = "type", rename_all = "snake_case")]
929pub enum OutputContent {
930    /// An output message from the model.
931    Message(OutputMessage),
932    /// The results of a file search tool call.
933    FileSearchCall(FileSearchCallOutput),
934    /// A tool call to run a function.
935    FunctionCall(FunctionCall),
936    /// The results of a web search tool call.
937    WebSearchCall(WebSearchCallOutput),
938    /// A tool call to a computer use tool.
939    ComputerCall(ComputerCallOutput),
940    /// A description of the chain of thought used by a reasoning model while generating a response.
941    /// Be sure to include these items in your input to the Responses API for subsequent turns of a
942    /// conversation if you are manually managing context.
943    Reasoning(ReasoningItem),
944    /// Image generation tool call output.
945    ImageGenerationCall(ImageGenerationCallOutput),
946    /// Code interpreter tool call output.
947    CodeInterpreterCall(CodeInterpreterCallOutput),
948    /// Local shell tool call output.
949    LocalShellCall(LocalShellCallOutput),
950    /// MCP tool invocation output.
951    McpCall(McpCallOutput),
952    /// MCP list-tools output.
953    McpListTools(McpListToolsOutput),
954    /// MCP approval request output.
955    McpApprovalRequest(McpApprovalRequestOutput),
956}
957
958/// A reasoning item representing the model's chain of thought, including summary paragraphs.
959#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
960pub struct ReasoningItem {
961    /// Unique identifier of the reasoning content.
962    pub id: String,
963    /// The summarized chain-of-thought paragraphs.
964    pub summary: Vec<SummaryText>,
965    /// The encrypted content of the reasoning item - populated when a response is generated with
966    /// `reasoning.encrypted_content` in the `include` parameter.
967    #[serde(skip_serializing_if = "Option::is_none")]
968    pub encrypted_content: Option<String>,
969    /// The status of the reasoning item.
970    #[serde(skip_serializing_if = "Option::is_none")]
971    pub status: Option<OutputStatus>,
972}
973
974/// A single summary text fragment from reasoning.
975#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
976pub struct SummaryText {
977    /// A short summary of the reasoning used by the model.
978    pub text: String,
979}
980
981/// File search tool call output.
982#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
983pub struct FileSearchCallOutput {
984    /// The unique ID of the file search tool call.
985    pub id: String,
986    /// The queries used to search for files.
987    pub queries: Vec<String>,
988    /// The status of the file search tool call.
989    pub status: FileSearchCallOutputStatus,
990    /// The results of the file search tool call.
991    #[serde(skip_serializing_if = "Option::is_none")]
992    pub results: Option<Vec<FileSearchResult>>,
993}
994
995#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
996#[serde(rename_all = "snake_case")]
997pub enum FileSearchCallOutputStatus {
998    InProgress,
999    Searching,
1000    Incomplete,
1001    Failed,
1002    Completed,
1003}
1004
1005/// A single result from a file search.
1006#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1007pub struct FileSearchResult {
1008    /// The unique ID of the file.
1009    pub file_id: String,
1010    /// The name of the file.
1011    pub filename: String,
1012    /// The relevance score of the file - a value between 0 and 1.
1013    pub score: f32,
1014    /// The text that was retrieved from the file.
1015    pub text: String,
1016    /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
1017    /// additional information about the object in a structured format, and querying for objects
1018    /// API or the dashboard. Keys are strings with a maximum length of 64 characters
1019    /// . Values are strings with a maximum length of 512 characters, booleans, or numbers.
1020    pub attributes: HashMap<String, serde_json::Value>,
1021}
1022
1023#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1024pub struct SafetyCheck {
1025    /// The ID of the safety check.
1026    pub id: String,
1027    /// The type/code of the pending safety check.
1028    pub code: String,
1029    /// Details about the pending safety check.
1030    pub message: String,
1031}
1032
1033/// Web search tool call output.
1034#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1035pub struct WebSearchCallOutput {
1036    /// The unique ID of the web search tool call.
1037    pub id: String,
1038    /// The status of the web search tool call.
1039    pub status: String,
1040}
1041
1042/// Output from a computer tool call.
1043#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1044pub struct ComputerCallOutput {
1045    pub action: ComputerCallAction,
1046    /// An identifier used when responding to the tool call with output.
1047    pub call_id: String,
1048    /// The unique ID of the computer call.
1049    pub id: String,
1050    /// The pending safety checks for the computer call.
1051    pub pending_safety_checks: Vec<SafetyCheck>,
1052    /// The status of the item.
1053    pub status: OutputStatus,
1054}
1055
1056/// A point in 2D space.
1057#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1058pub struct Point {
1059    pub x: i32,
1060    pub y: i32,
1061}
1062
1063/// Represents all user‐triggered actions.
1064#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1065#[serde(tag = "type", rename_all = "snake_case")]
1066pub enum ComputerCallAction {
1067    /// A click action.
1068    Click(Click),
1069
1070    /// A double-click action.
1071    DoubleClick(DoubleClick),
1072
1073    /// A drag action.
1074    Drag(Drag),
1075
1076    /// A keypress action.
1077    KeyPress(KeyPress),
1078
1079    /// A mouse move action.
1080    Move(MoveAction),
1081
1082    /// A screenshot action.
1083    Screenshot,
1084
1085    /// A scroll action.
1086    Scroll(Scroll),
1087
1088    /// A type (text entry) action.
1089    Type(TypeAction),
1090
1091    /// A wait (no-op) action.
1092    Wait,
1093}
1094
1095#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1096#[serde(rename_all = "snake_case")]
1097pub enum ButtonPress {
1098    Left,
1099    Right,
1100    Wheel,
1101    Back,
1102    Forward,
1103}
1104
1105/// A click action.
1106#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1107pub struct Click {
1108    /// Which mouse button was pressed.
1109    pub button: ButtonPress,
1110    /// X‐coordinate of the click.
1111    pub x: i32,
1112    /// Y‐coordinate of the click.
1113    pub y: i32,
1114}
1115
1116/// A double click action.
1117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1118pub struct DoubleClick {
1119    /// X‐coordinate of the double click.
1120    pub x: i32,
1121    /// Y‐coordinate of the double click.
1122    pub y: i32,
1123}
1124
1125/// A drag action.
1126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1127pub struct Drag {
1128    /// The path of points the cursor drags through.
1129    pub path: Vec<Point>,
1130    /// X‐coordinate at the end of the drag.
1131    pub x: i32,
1132    /// Y‐coordinate at the end of the drag.
1133    pub y: i32,
1134}
1135
1136/// A keypress action.
1137#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1138pub struct KeyPress {
1139    /// The list of keys to press (e.g. `["Control", "C"]`).
1140    pub keys: Vec<String>,
1141}
1142
1143/// A mouse move action.
1144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1145pub struct MoveAction {
1146    /// X‐coordinate to move to.
1147    pub x: i32,
1148    /// Y‐coordinate to move to.
1149    pub y: i32,
1150}
1151
1152/// A scroll action.
1153#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1154pub struct Scroll {
1155    /// Horizontal scroll distance.
1156    pub scroll_x: i32,
1157    /// Vertical scroll distance.
1158    pub scroll_y: i32,
1159    /// X‐coordinate where the scroll began.
1160    pub x: i32,
1161    /// Y‐coordinate where the scroll began.
1162    pub y: i32,
1163}
1164
1165/// A typing (text entry) action.
1166#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1167pub struct TypeAction {
1168    /// The text to type.
1169    pub text: String,
1170}
1171
1172/// Metadata for a function call request.
1173#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1174pub struct FunctionCall {
1175    /// The unique ID of the function tool call.
1176    pub id: String,
1177    /// The unique ID of the function tool call generated by the model.
1178    pub call_id: String,
1179    /// The name of the function to run.
1180    pub name: String,
1181    /// A JSON string of the arguments to pass to the function.
1182    pub arguments: String,
1183    /// The status of the item.
1184    pub status: OutputStatus,
1185}
1186
1187/// Output of an image generation request.
1188#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1189pub struct ImageGenerationCallOutput {
1190    /// Unique ID of the image generation call.
1191    pub id: String,
1192    /// Base64-encoded generated image, or null.
1193    pub result: Option<String>,
1194    /// Status of the image generation call.
1195    pub status: String,
1196}
1197
1198/// Output of a code interpreter request.
1199#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1200pub struct CodeInterpreterCallOutput {
1201    /// The code that was executed.
1202    #[serde(skip_serializing_if = "Option::is_none")]
1203    pub code: Option<String>,
1204    /// Unique ID of the call.
1205    pub id: String,
1206    /// Status of the tool call.
1207    pub status: String,
1208    /// ID of the container used to run the code.
1209    pub container_id: String,
1210    /// The outputs of the execution: logs or files.
1211    #[serde(skip_serializing_if = "Option::is_none")]
1212    pub outputs: Option<Vec<CodeInterpreterResult>>,
1213}
1214
1215/// Individual result from a code interpreter: either logs or files.
1216#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1217#[serde(tag = "type", rename_all = "snake_case")]
1218pub enum CodeInterpreterResult {
1219    /// Text logs from the execution.
1220    Logs(CodeInterpreterTextOutput),
1221    /// File outputs from the execution.
1222    Files(CodeInterpreterFileOutput),
1223}
1224
1225/// The output containing execution logs.
1226#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1227pub struct CodeInterpreterTextOutput {
1228    /// The logs of the code interpreter tool call.
1229    pub logs: String,
1230}
1231
1232/// The output containing file references.
1233#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1234pub struct CodeInterpreterFileOutput {
1235    /// List of file IDs produced.
1236    pub files: Vec<CodeInterpreterFile>,
1237}
1238
1239#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1240pub struct CodeInterpreterFile {
1241    /// The ID of the file.
1242    file_id: String,
1243    /// The MIME type of the file.
1244    mime_type: String,
1245}
1246
1247/// Output of a local shell command request.
1248#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1249pub struct LocalShellCallOutput {
1250    /// Details of the exec action.
1251    pub action: LocalShellAction,
1252    /// Unique call identifier for responding to the tool call.
1253    pub call_id: String,
1254    /// Unique ID of the local shell call.
1255    pub id: String,
1256    /// Status of the local shell call.
1257    pub status: String,
1258}
1259
1260/// Define the shape of a local shell action (exec).
1261#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1262pub struct LocalShellAction {
1263    /// The command to run.
1264    pub command: Vec<String>,
1265    /// Environment variables to set for the command.
1266    pub env: HashMap<String, String>,
1267    /// Optional timeout for the command (ms).
1268    pub timeout_ms: Option<u64>,
1269    /// Optional user to run the command as.
1270    pub user: Option<String>,
1271    /// Optional working directory for the command.
1272    pub working_directory: Option<String>,
1273}
1274
1275/// Output of an MCP server tool invocation.
1276#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1277pub struct McpCallOutput {
1278    /// JSON string of the arguments passed.
1279    pub arguments: String,
1280    /// Unique ID of the MCP call.
1281    pub id: String,
1282    /// Name of the tool invoked.
1283    pub name: String,
1284    /// Label of the MCP server.
1285    pub server_label: String,
1286    /// Error message from the call, if any.
1287    pub error: Option<String>,
1288    /// Output from the call, if any.
1289    pub output: Option<String>,
1290}
1291
1292/// Output listing tools available on an MCP server.
1293#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1294pub struct McpListToolsOutput {
1295    /// Unique ID of the list request.
1296    pub id: String,
1297    /// Label of the MCP server.
1298    pub server_label: String,
1299    /// Tools available on the server with metadata.
1300    pub tools: Vec<McpToolInfo>,
1301    /// Error message if listing failed.
1302    #[serde(skip_serializing_if = "Option::is_none")]
1303    pub error: Option<String>,
1304}
1305
1306/// Information about a single tool on an MCP server.
1307#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1308pub struct McpToolInfo {
1309    /// The name of the tool.
1310    pub name: String,
1311    /// The JSON schema describing the tool's input.
1312    pub input_schema: Value,
1313    /// Additional annotations about the tool.
1314    #[serde(skip_serializing_if = "Option::is_none")]
1315    pub annotations: Option<Value>,
1316    /// The description of the tool.
1317    #[serde(skip_serializing_if = "Option::is_none")]
1318    pub description: Option<String>,
1319}
1320
1321/// Output representing a human approval request for an MCP tool.
1322#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1323pub struct McpApprovalRequestOutput {
1324    /// JSON string of arguments for the tool.
1325    pub arguments: String,
1326    /// Unique ID of the approval request.
1327    pub id: String,
1328    /// Name of the tool requiring approval.
1329    pub name: String,
1330    /// Label of the MCP server making the request.
1331    pub server_label: String,
1332}
1333
1334/// Usage statistics for a response.
1335#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1336pub struct Usage {
1337    /// The number of input tokens.
1338    pub input_tokens: u32,
1339    /// A detailed breakdown of the input tokens.
1340    pub input_tokens_details: PromptTokensDetails,
1341    /// The number of output tokens.
1342    pub output_tokens: u32,
1343    /// A detailed breakdown of the output tokens.
1344    pub output_tokens_details: CompletionTokensDetails,
1345    /// The total number of tokens used.
1346    pub total_tokens: u32,
1347}
1348
1349/// The complete response returned by the Responses API.
1350#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1351pub struct Response {
1352    /// Unix timestamp (in seconds) when this Response was created.
1353    pub created_at: u64,
1354
1355    /// Error object if the API failed to generate a response.
1356    #[serde(skip_serializing_if = "Option::is_none")]
1357    pub error: Option<ErrorObject>,
1358
1359    /// Unique identifier for this response.
1360    pub id: String,
1361
1362    /// Details about why the response is incomplete, if any.
1363    #[serde(skip_serializing_if = "Option::is_none")]
1364    pub incomplete_details: Option<IncompleteDetails>,
1365
1366    /// Instructions that were inserted as the first item in context.
1367    #[serde(skip_serializing_if = "Option::is_none")]
1368    pub instructions: Option<String>,
1369
1370    /// The value of `max_output_tokens` that was honored.
1371    #[serde(skip_serializing_if = "Option::is_none")]
1372    pub max_output_tokens: Option<u32>,
1373
1374    /// Metadata tags/values that were attached to this response.
1375    #[serde(skip_serializing_if = "Option::is_none")]
1376    pub metadata: Option<HashMap<String, String>>,
1377
1378    /// Model ID used to generate the response.
1379    pub model: String,
1380
1381    /// The object type – always `response`.
1382    pub object: String,
1383
1384    /// The array of content items generated by the model.
1385    pub output: Vec<OutputContent>,
1386
1387    /// SDK-only convenience property that contains the aggregated text output from all
1388    /// `output_text` items in the `output` array, if any are present.
1389    /// Supported in the Python and JavaScript SDKs.
1390    #[serde(skip_serializing_if = "Option::is_none")]
1391    pub output_text: Option<String>,
1392
1393    /// Whether parallel tool calls were enabled.
1394    #[serde(skip_serializing_if = "Option::is_none")]
1395    pub parallel_tool_calls: Option<bool>,
1396
1397    /// Previous response ID, if creating part of a multi-turn conversation.
1398    #[serde(skip_serializing_if = "Option::is_none")]
1399    pub previous_response_id: Option<String>,
1400
1401    /// Reasoning configuration echoed back (effort, summary settings).
1402    #[serde(skip_serializing_if = "Option::is_none")]
1403    pub reasoning: Option<ReasoningConfig>,
1404
1405    /// Whether to store the generated model response for later retrieval via API.
1406    #[serde(skip_serializing_if = "Option::is_none")]
1407    pub store: Option<bool>,
1408
1409    /// The service tier that actually processed this response.
1410    #[serde(skip_serializing_if = "Option::is_none")]
1411    pub service_tier: Option<ServiceTier>,
1412
1413    /// The status of the response generation.
1414    pub status: Status,
1415
1416    /// Sampling temperature that was used.
1417    #[serde(skip_serializing_if = "Option::is_none")]
1418    pub temperature: Option<f32>,
1419
1420    /// Text format configuration echoed back (plain, json_object, json_schema).
1421    #[serde(skip_serializing_if = "Option::is_none")]
1422    pub text: Option<TextConfig>,
1423
1424    /// How the model chose or was forced to choose a tool.
1425    #[serde(skip_serializing_if = "Option::is_none")]
1426    pub tool_choice: Option<ToolChoice>,
1427
1428    /// Tool definitions that were provided.
1429    #[serde(skip_serializing_if = "Option::is_none")]
1430    pub tools: Option<Vec<ToolDefinition>>,
1431
1432    /// Nucleus sampling cutoff that was used.
1433    #[serde(skip_serializing_if = "Option::is_none")]
1434    pub top_p: Option<f32>,
1435
1436    /// Truncation strategy that was applied.
1437    #[serde(skip_serializing_if = "Option::is_none")]
1438    pub truncation: Option<Truncation>,
1439
1440    /// Token usage statistics for this request.
1441    #[serde(skip_serializing_if = "Option::is_none")]
1442    pub usage: Option<Usage>,
1443
1444    /// End-user ID for which this response was generated.
1445    #[serde(skip_serializing_if = "Option::is_none")]
1446    pub user: Option<String>,
1447}
1448
1449#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1450#[serde(rename_all = "snake_case")]
1451pub enum Status {
1452    Completed,
1453    Failed,
1454    InProgress,
1455    Incomplete,
1456}
1457
1458/// Event types for streaming responses from the Responses API
1459#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1460#[serde(tag = "type")]
1461#[non_exhaustive] // Future-proof against breaking changes
1462pub enum ResponseEvent {
1463    /// Response creation started
1464    #[serde(rename = "response.created")]
1465    ResponseCreated(ResponseCreated),
1466    /// Processing in progress
1467    #[serde(rename = "response.in_progress")]
1468    ResponseInProgress(ResponseInProgress),
1469    /// Response completed (different from done)
1470    #[serde(rename = "response.completed")]
1471    ResponseCompleted(ResponseCompleted),
1472    /// Response failed
1473    #[serde(rename = "response.failed")]
1474    ResponseFailed(ResponseFailed),
1475    /// Response incomplete
1476    #[serde(rename = "response.incomplete")]
1477    ResponseIncomplete(ResponseIncomplete),
1478    /// Response queued
1479    #[serde(rename = "response.queued")]
1480    ResponseQueued(ResponseQueued),
1481    /// Output item added
1482    #[serde(rename = "response.output_item.added")]
1483    ResponseOutputItemAdded(ResponseOutputItemAdded),
1484    /// Content part added
1485    #[serde(rename = "response.content_part.added")]
1486    ResponseContentPartAdded(ResponseContentPartAdded),
1487    /// Text delta update
1488    #[serde(rename = "response.output_text.delta")]
1489    ResponseOutputTextDelta(ResponseOutputTextDelta),
1490    /// Text output completed
1491    #[serde(rename = "response.output_text.done")]
1492    ResponseOutputTextDone(ResponseOutputTextDone),
1493    /// Refusal delta update
1494    #[serde(rename = "response.refusal.delta")]
1495    ResponseRefusalDelta(ResponseRefusalDelta),
1496    /// Refusal completed
1497    #[serde(rename = "response.refusal.done")]
1498    ResponseRefusalDone(ResponseRefusalDone),
1499    /// Content part completed
1500    #[serde(rename = "response.content_part.done")]
1501    ResponseContentPartDone(ResponseContentPartDone),
1502    /// Output item completed
1503    #[serde(rename = "response.output_item.done")]
1504    ResponseOutputItemDone(ResponseOutputItemDone),
1505    /// Function call arguments delta
1506    #[serde(rename = "response.function_call_arguments.delta")]
1507    ResponseFunctionCallArgumentsDelta(ResponseFunctionCallArgumentsDelta),
1508    /// Function call arguments completed
1509    #[serde(rename = "response.function_call_arguments.done")]
1510    ResponseFunctionCallArgumentsDone(ResponseFunctionCallArgumentsDone),
1511    /// File search call in progress
1512    #[serde(rename = "response.file_search_call.in_progress")]
1513    ResponseFileSearchCallInProgress(ResponseFileSearchCallInProgress),
1514    /// File search call searching
1515    #[serde(rename = "response.file_search_call.searching")]
1516    ResponseFileSearchCallSearching(ResponseFileSearchCallSearching),
1517    /// File search call completed
1518    #[serde(rename = "response.file_search_call.completed")]
1519    ResponseFileSearchCallCompleted(ResponseFileSearchCallCompleted),
1520    /// Web search call in progress
1521    #[serde(rename = "response.web_search_call.in_progress")]
1522    ResponseWebSearchCallInProgress(ResponseWebSearchCallInProgress),
1523    /// Web search call searching
1524    #[serde(rename = "response.web_search_call.searching")]
1525    ResponseWebSearchCallSearching(ResponseWebSearchCallSearching),
1526    /// Web search call completed
1527    #[serde(rename = "response.web_search_call.completed")]
1528    ResponseWebSearchCallCompleted(ResponseWebSearchCallCompleted),
1529    /// Reasoning summary part added
1530    #[serde(rename = "response.reasoning_summary_part.added")]
1531    ResponseReasoningSummaryPartAdded(ResponseReasoningSummaryPartAdded),
1532    /// Reasoning summary part done
1533    #[serde(rename = "response.reasoning_summary_part.done")]
1534    ResponseReasoningSummaryPartDone(ResponseReasoningSummaryPartDone),
1535    /// Reasoning summary text delta
1536    #[serde(rename = "response.reasoning_summary_text.delta")]
1537    ResponseReasoningSummaryTextDelta(ResponseReasoningSummaryTextDelta),
1538    /// Reasoning summary text done
1539    #[serde(rename = "response.reasoning_summary_text.done")]
1540    ResponseReasoningSummaryTextDone(ResponseReasoningSummaryTextDone),
1541    /// Reasoning summary delta
1542    #[serde(rename = "response.reasoning_summary.delta")]
1543    ResponseReasoningSummaryDelta(ResponseReasoningSummaryDelta),
1544    /// Reasoning summary done
1545    #[serde(rename = "response.reasoning_summary.done")]
1546    ResponseReasoningSummaryDone(ResponseReasoningSummaryDone),
1547    /// Image generation call in progress
1548    #[serde(rename = "response.image_generation_call.in_progress")]
1549    ResponseImageGenerationCallInProgress(ResponseImageGenerationCallInProgress),
1550    /// Image generation call generating
1551    #[serde(rename = "response.image_generation_call.generating")]
1552    ResponseImageGenerationCallGenerating(ResponseImageGenerationCallGenerating),
1553    /// Image generation call partial image
1554    #[serde(rename = "response.image_generation_call.partial_image")]
1555    ResponseImageGenerationCallPartialImage(ResponseImageGenerationCallPartialImage),
1556    /// Image generation call completed
1557    #[serde(rename = "response.image_generation_call.completed")]
1558    ResponseImageGenerationCallCompleted(ResponseImageGenerationCallCompleted),
1559    /// MCP call arguments delta
1560    #[serde(rename = "response.mcp_call_arguments.delta")]
1561    ResponseMcpCallArgumentsDelta(ResponseMcpCallArgumentsDelta),
1562    /// MCP call arguments done
1563    #[serde(rename = "response.mcp_call_arguments.done")]
1564    ResponseMcpCallArgumentsDone(ResponseMcpCallArgumentsDone),
1565    /// MCP call completed
1566    #[serde(rename = "response.mcp_call.completed")]
1567    ResponseMcpCallCompleted(ResponseMcpCallCompleted),
1568    /// MCP call failed
1569    #[serde(rename = "response.mcp_call.failed")]
1570    ResponseMcpCallFailed(ResponseMcpCallFailed),
1571    /// MCP call in progress
1572    #[serde(rename = "response.mcp_call.in_progress")]
1573    ResponseMcpCallInProgress(ResponseMcpCallInProgress),
1574    /// MCP list tools completed
1575    #[serde(rename = "response.mcp_list_tools.completed")]
1576    ResponseMcpListToolsCompleted(ResponseMcpListToolsCompleted),
1577    /// MCP list tools failed
1578    #[serde(rename = "response.mcp_list_tools.failed")]
1579    ResponseMcpListToolsFailed(ResponseMcpListToolsFailed),
1580    /// MCP list tools in progress
1581    #[serde(rename = "response.mcp_list_tools.in_progress")]
1582    ResponseMcpListToolsInProgress(ResponseMcpListToolsInProgress),
1583    /// Code interpreter call in progress
1584    #[serde(rename = "response.code_interpreter_call.in_progress")]
1585    ResponseCodeInterpreterCallInProgress(ResponseCodeInterpreterCallInProgress),
1586    /// Code interpreter call interpreting
1587    #[serde(rename = "response.code_interpreter_call.interpreting")]
1588    ResponseCodeInterpreterCallInterpreting(ResponseCodeInterpreterCallInterpreting),
1589    /// Code interpreter call completed
1590    #[serde(rename = "response.code_interpreter_call.completed")]
1591    ResponseCodeInterpreterCallCompleted(ResponseCodeInterpreterCallCompleted),
1592    /// Code interpreter call code delta
1593    #[serde(rename = "response.code_interpreter_call_code.delta")]
1594    ResponseCodeInterpreterCallCodeDelta(ResponseCodeInterpreterCallCodeDelta),
1595    /// Code interpreter call code done
1596    #[serde(rename = "response.code_interpreter_call_code.done")]
1597    ResponseCodeInterpreterCallCodeDone(ResponseCodeInterpreterCallCodeDone),
1598    /// Output text annotation added
1599    #[serde(rename = "response.output_text.annotation.added")]
1600    ResponseOutputTextAnnotationAdded(ResponseOutputTextAnnotationAdded),
1601    /// Error occurred
1602    #[serde(rename = "error")]
1603    ResponseError(ResponseError),
1604
1605    /// Unknown event type
1606    #[serde(untagged)]
1607    Unknown(serde_json::Value),
1608}
1609
1610/// Stream of response events
1611pub type ResponseStream = OpenAIEventStream<ResponseEvent>;
1612
1613#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1614#[non_exhaustive]
1615pub struct ResponseCreated {
1616    pub sequence_number: u64,
1617    pub response: ResponseMetadata,
1618}
1619
1620#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1621#[non_exhaustive]
1622pub struct ResponseInProgress {
1623    pub sequence_number: u64,
1624    pub response: ResponseMetadata,
1625}
1626
1627#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1628#[non_exhaustive]
1629pub struct ResponseOutputItemAdded {
1630    pub sequence_number: u64,
1631    pub output_index: u32,
1632    pub item: OutputItem,
1633}
1634
1635#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1636#[non_exhaustive]
1637pub struct ResponseContentPartAdded {
1638    pub sequence_number: u64,
1639    pub item_id: String,
1640    pub output_index: u32,
1641    pub content_index: u32,
1642    pub part: ContentPart,
1643}
1644
1645#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1646#[non_exhaustive]
1647pub struct ResponseOutputTextDelta {
1648    pub sequence_number: u64,
1649    pub item_id: String,
1650    pub output_index: u32,
1651    pub content_index: u32,
1652    pub delta: String,
1653    #[serde(default, skip_serializing_if = "Option::is_none")]
1654    pub logprobs: Option<serde_json::Value>,
1655}
1656
1657#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1658#[non_exhaustive]
1659pub struct ResponseContentPartDone {
1660    pub sequence_number: u64,
1661    pub item_id: String,
1662    pub output_index: u32,
1663    pub content_index: u32,
1664    pub part: ContentPart,
1665}
1666
1667#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1668#[non_exhaustive]
1669pub struct ResponseOutputItemDone {
1670    pub sequence_number: u64,
1671    pub output_index: u32,
1672    pub item: OutputItem,
1673}
1674
1675/// Response completed event
1676#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1677#[non_exhaustive]
1678pub struct ResponseCompleted {
1679    pub sequence_number: u64,
1680    pub response: ResponseMetadata,
1681}
1682
1683/// Response failed event
1684#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1685#[non_exhaustive]
1686pub struct ResponseFailed {
1687    pub sequence_number: u64,
1688    pub response: ResponseMetadata,
1689}
1690
1691/// Response incomplete event
1692#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1693#[non_exhaustive]
1694pub struct ResponseIncomplete {
1695    pub sequence_number: u64,
1696    pub response: ResponseMetadata,
1697}
1698
1699/// Response queued event
1700#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1701#[non_exhaustive]
1702pub struct ResponseQueued {
1703    pub sequence_number: u64,
1704    pub response: ResponseMetadata,
1705}
1706
1707/// Text output completed event
1708#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1709#[non_exhaustive]
1710pub struct ResponseOutputTextDone {
1711    pub sequence_number: u64,
1712    pub item_id: String,
1713    pub output_index: u32,
1714    pub content_index: u32,
1715    pub text: String,
1716    pub logprobs: Option<Vec<serde_json::Value>>,
1717}
1718
1719/// Refusal delta event
1720#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1721#[non_exhaustive]
1722pub struct ResponseRefusalDelta {
1723    pub sequence_number: u64,
1724    pub item_id: String,
1725    pub output_index: u32,
1726    pub content_index: u32,
1727    pub delta: String,
1728}
1729
1730/// Refusal done event
1731#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1732#[non_exhaustive]
1733pub struct ResponseRefusalDone {
1734    pub sequence_number: u64,
1735    pub item_id: String,
1736    pub output_index: u32,
1737    pub content_index: u32,
1738    pub refusal: String,
1739}
1740
1741/// Function call arguments delta event
1742#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1743#[non_exhaustive]
1744pub struct ResponseFunctionCallArgumentsDelta {
1745    pub sequence_number: u64,
1746    pub item_id: String,
1747    pub output_index: u32,
1748    pub delta: String,
1749}
1750
1751/// Function call arguments done event
1752#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1753#[non_exhaustive]
1754pub struct ResponseFunctionCallArgumentsDone {
1755    pub name: String,
1756    pub sequence_number: u64,
1757    pub item_id: String,
1758    pub output_index: u32,
1759    pub arguments: String,
1760}
1761
1762/// Error event
1763#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1764#[non_exhaustive]
1765pub struct ResponseError {
1766    pub sequence_number: u64,
1767    pub code: Option<String>,
1768    pub message: String,
1769    pub param: Option<String>,
1770}
1771
1772/// File search call in progress event
1773#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1774#[non_exhaustive]
1775pub struct ResponseFileSearchCallInProgress {
1776    pub sequence_number: u64,
1777    pub output_index: u32,
1778    pub item_id: String,
1779}
1780
1781/// File search call searching event
1782#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1783#[non_exhaustive]
1784pub struct ResponseFileSearchCallSearching {
1785    pub sequence_number: u64,
1786    pub output_index: u32,
1787    pub item_id: String,
1788}
1789
1790/// File search call completed event
1791#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1792#[non_exhaustive]
1793pub struct ResponseFileSearchCallCompleted {
1794    pub sequence_number: u64,
1795    pub output_index: u32,
1796    pub item_id: String,
1797}
1798
1799/// Web search call in progress event
1800#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1801#[non_exhaustive]
1802pub struct ResponseWebSearchCallInProgress {
1803    pub sequence_number: u64,
1804    pub output_index: u32,
1805    pub item_id: String,
1806}
1807
1808/// Web search call searching event
1809#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1810#[non_exhaustive]
1811pub struct ResponseWebSearchCallSearching {
1812    pub sequence_number: u64,
1813    pub output_index: u32,
1814    pub item_id: String,
1815}
1816
1817/// Web search call completed event
1818#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1819#[non_exhaustive]
1820pub struct ResponseWebSearchCallCompleted {
1821    pub sequence_number: u64,
1822    pub output_index: u32,
1823    pub item_id: String,
1824}
1825
1826/// Reasoning summary part added event
1827#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1828#[non_exhaustive]
1829pub struct ResponseReasoningSummaryPartAdded {
1830    pub sequence_number: u64,
1831    pub item_id: String,
1832    pub output_index: u32,
1833    pub summary_index: u32,
1834    pub part: serde_json::Value, // Could be more specific but using Value for flexibility
1835}
1836
1837/// Reasoning summary part done event
1838#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1839#[non_exhaustive]
1840pub struct ResponseReasoningSummaryPartDone {
1841    pub sequence_number: u64,
1842    pub item_id: String,
1843    pub output_index: u32,
1844    pub summary_index: u32,
1845    pub part: serde_json::Value,
1846}
1847
1848/// Reasoning summary text delta event
1849#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1850#[non_exhaustive]
1851pub struct ResponseReasoningSummaryTextDelta {
1852    pub sequence_number: u64,
1853    pub item_id: String,
1854    pub output_index: u32,
1855    pub summary_index: u32,
1856    pub delta: String,
1857}
1858
1859/// Reasoning summary text done event
1860#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1861#[non_exhaustive]
1862pub struct ResponseReasoningSummaryTextDone {
1863    pub sequence_number: u64,
1864    pub item_id: String,
1865    pub output_index: u32,
1866    pub summary_index: u32,
1867    pub text: String,
1868}
1869
1870/// Reasoning summary delta event
1871#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1872#[non_exhaustive]
1873pub struct ResponseReasoningSummaryDelta {
1874    pub sequence_number: u64,
1875    pub item_id: String,
1876    pub output_index: u32,
1877    pub summary_index: u32,
1878    pub delta: serde_json::Value,
1879}
1880
1881/// Reasoning summary done event
1882#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1883#[non_exhaustive]
1884pub struct ResponseReasoningSummaryDone {
1885    pub sequence_number: u64,
1886    pub item_id: String,
1887    pub output_index: u32,
1888    pub summary_index: u32,
1889    pub text: String,
1890}
1891
1892/// Image generation call in progress event
1893#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1894#[non_exhaustive]
1895pub struct ResponseImageGenerationCallInProgress {
1896    pub sequence_number: u64,
1897    pub output_index: u32,
1898    pub item_id: String,
1899}
1900
1901/// Image generation call generating event
1902#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1903#[non_exhaustive]
1904pub struct ResponseImageGenerationCallGenerating {
1905    pub sequence_number: u64,
1906    pub output_index: u32,
1907    pub item_id: String,
1908}
1909
1910/// Image generation call partial image event
1911#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1912#[non_exhaustive]
1913pub struct ResponseImageGenerationCallPartialImage {
1914    pub sequence_number: u64,
1915    pub output_index: u32,
1916    pub item_id: String,
1917    pub partial_image_index: u32,
1918    pub partial_image_b64: String,
1919}
1920
1921/// Image generation call completed event
1922#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1923#[non_exhaustive]
1924pub struct ResponseImageGenerationCallCompleted {
1925    pub sequence_number: u64,
1926    pub output_index: u32,
1927    pub item_id: String,
1928}
1929
1930/// MCP call arguments delta event
1931#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1932#[non_exhaustive]
1933pub struct ResponseMcpCallArgumentsDelta {
1934    pub sequence_number: u64,
1935    pub output_index: u32,
1936    pub item_id: String,
1937    pub delta: String,
1938}
1939
1940/// MCP call arguments done event
1941#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1942#[non_exhaustive]
1943pub struct ResponseMcpCallArgumentsDone {
1944    pub sequence_number: u64,
1945    pub output_index: u32,
1946    pub item_id: String,
1947    pub arguments: String,
1948}
1949
1950/// MCP call completed event
1951#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1952#[non_exhaustive]
1953pub struct ResponseMcpCallCompleted {
1954    pub sequence_number: u64,
1955    pub output_index: u32,
1956    pub item_id: String,
1957}
1958
1959/// MCP call failed event
1960#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1961#[non_exhaustive]
1962pub struct ResponseMcpCallFailed {
1963    pub sequence_number: u64,
1964    pub output_index: u32,
1965    pub item_id: String,
1966}
1967
1968/// MCP call in progress event
1969#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1970#[non_exhaustive]
1971pub struct ResponseMcpCallInProgress {
1972    pub sequence_number: u64,
1973    pub output_index: u32,
1974    pub item_id: String,
1975}
1976
1977/// MCP list tools completed event
1978#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1979#[non_exhaustive]
1980pub struct ResponseMcpListToolsCompleted {
1981    pub sequence_number: u64,
1982    pub output_index: u32,
1983    pub item_id: String,
1984}
1985
1986/// MCP list tools failed event
1987#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1988#[non_exhaustive]
1989pub struct ResponseMcpListToolsFailed {
1990    pub sequence_number: u64,
1991    pub output_index: u32,
1992    pub item_id: String,
1993}
1994
1995/// MCP list tools in progress event
1996#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1997#[non_exhaustive]
1998pub struct ResponseMcpListToolsInProgress {
1999    pub sequence_number: u64,
2000    pub output_index: u32,
2001    pub item_id: String,
2002}
2003
2004/// Code interpreter call in progress event
2005#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2006#[non_exhaustive]
2007pub struct ResponseCodeInterpreterCallInProgress {
2008    pub sequence_number: u64,
2009    pub output_index: u32,
2010    pub item_id: String,
2011}
2012
2013/// Code interpreter call interpreting event
2014#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2015#[non_exhaustive]
2016pub struct ResponseCodeInterpreterCallInterpreting {
2017    pub sequence_number: u64,
2018    pub output_index: u32,
2019    pub item_id: String,
2020}
2021
2022/// Code interpreter call completed event
2023#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2024#[non_exhaustive]
2025pub struct ResponseCodeInterpreterCallCompleted {
2026    pub sequence_number: u64,
2027    pub output_index: u32,
2028    pub item_id: String,
2029}
2030
2031/// Code interpreter call code delta event
2032#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2033#[non_exhaustive]
2034pub struct ResponseCodeInterpreterCallCodeDelta {
2035    pub sequence_number: u64,
2036    pub output_index: u32,
2037    pub item_id: String,
2038    pub delta: String,
2039}
2040
2041/// Code interpreter call code done event
2042#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2043#[non_exhaustive]
2044pub struct ResponseCodeInterpreterCallCodeDone {
2045    pub sequence_number: u64,
2046    pub output_index: u32,
2047    pub item_id: String,
2048    pub code: String,
2049}
2050
2051/// Response metadata
2052#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2053#[non_exhaustive]
2054pub struct ResponseMetadata {
2055    pub id: String,
2056    #[serde(skip_serializing_if = "Option::is_none")]
2057    pub object: Option<String>,
2058    pub created_at: u64,
2059    pub status: Status,
2060    #[serde(skip_serializing_if = "Option::is_none")]
2061    pub model: Option<String>,
2062    #[serde(skip_serializing_if = "Option::is_none")]
2063    pub usage: Option<Usage>,
2064    #[serde(skip_serializing_if = "Option::is_none")]
2065    pub error: Option<ErrorObject>,
2066    #[serde(skip_serializing_if = "Option::is_none")]
2067    pub incomplete_details: Option<IncompleteDetails>,
2068    #[serde(skip_serializing_if = "Option::is_none")]
2069    pub input: Option<Input>,
2070    #[serde(skip_serializing_if = "Option::is_none")]
2071    pub instructions: Option<String>,
2072    #[serde(skip_serializing_if = "Option::is_none")]
2073    pub max_output_tokens: Option<u32>,
2074    /// Whether the model was run in background mode
2075    #[serde(skip_serializing_if = "Option::is_none")]
2076    pub background: Option<bool>,
2077    /// The service tier that was actually used
2078    #[serde(skip_serializing_if = "Option::is_none")]
2079    pub service_tier: Option<ServiceTier>,
2080    /// The effective value of top_logprobs parameter
2081    #[serde(skip_serializing_if = "Option::is_none")]
2082    pub top_logprobs: Option<u32>,
2083    /// The effective value of max_tool_calls parameter
2084    #[serde(skip_serializing_if = "Option::is_none")]
2085    pub max_tool_calls: Option<u32>,
2086    #[serde(skip_serializing_if = "Option::is_none")]
2087    pub output: Option<Vec<OutputItem>>,
2088    #[serde(skip_serializing_if = "Option::is_none")]
2089    pub parallel_tool_calls: Option<bool>,
2090    #[serde(skip_serializing_if = "Option::is_none")]
2091    pub previous_response_id: Option<String>,
2092    #[serde(skip_serializing_if = "Option::is_none")]
2093    pub reasoning: Option<ReasoningConfig>,
2094    #[serde(skip_serializing_if = "Option::is_none")]
2095    pub store: Option<bool>,
2096    #[serde(skip_serializing_if = "Option::is_none")]
2097    pub temperature: Option<f32>,
2098    #[serde(skip_serializing_if = "Option::is_none")]
2099    pub text: Option<TextConfig>,
2100    #[serde(skip_serializing_if = "Option::is_none")]
2101    pub tool_choice: Option<ToolChoice>,
2102    #[serde(skip_serializing_if = "Option::is_none")]
2103    pub tools: Option<Vec<ToolDefinition>>,
2104    #[serde(skip_serializing_if = "Option::is_none")]
2105    pub top_p: Option<f32>,
2106    #[serde(skip_serializing_if = "Option::is_none")]
2107    pub truncation: Option<Truncation>,
2108    #[serde(skip_serializing_if = "Option::is_none")]
2109    pub user: Option<String>,
2110    #[serde(skip_serializing_if = "Option::is_none")]
2111    pub metadata: Option<HashMap<String, String>>,
2112    /// Prompt cache key for improved performance
2113    #[serde(skip_serializing_if = "Option::is_none")]
2114    pub prompt_cache_key: Option<String>,
2115    /// Safety identifier for content filtering
2116    #[serde(skip_serializing_if = "Option::is_none")]
2117    pub safety_identifier: Option<String>,
2118}
2119
2120/// Output item
2121#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2122#[serde(tag = "type")]
2123#[serde(rename_all = "snake_case")]
2124#[non_exhaustive]
2125pub enum OutputItem {
2126    Message(OutputMessage),
2127    FileSearchCall(FileSearchCallOutput),
2128    FunctionCall(FunctionCall),
2129    WebSearchCall(WebSearchCallOutput),
2130    ComputerCall(ComputerCallOutput),
2131    Reasoning(ReasoningItem),
2132    ImageGenerationCall(ImageGenerationCallOutput),
2133    CodeInterpreterCall(CodeInterpreterCallOutput),
2134    LocalShellCall(LocalShellCallOutput),
2135    McpCall(McpCallOutput),
2136    McpListTools(McpListToolsOutput),
2137    McpApprovalRequest(McpApprovalRequestOutput),
2138    CustomToolCall(CustomToolCallOutput),
2139}
2140
2141#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2142#[non_exhaustive]
2143pub struct CustomToolCallOutput {
2144    pub call_id: String,
2145    pub input: String,
2146    pub name: String,
2147    pub id: String,
2148}
2149
2150/// Content part
2151#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2152#[non_exhaustive]
2153pub struct ContentPart {
2154    #[serde(rename = "type")]
2155    pub part_type: String,
2156    pub text: Option<String>,
2157    #[serde(default, skip_serializing_if = "Option::is_none")]
2158    pub annotations: Option<Vec<serde_json::Value>>,
2159    #[serde(default, skip_serializing_if = "Option::is_none")]
2160    pub logprobs: Option<Vec<serde_json::Value>>,
2161}
2162
2163// ===== RESPONSE COLLECTOR =====
2164
2165/// Collects streaming response events into a complete response
2166/// Output text annotation added event
2167#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2168#[non_exhaustive]
2169pub struct ResponseOutputTextAnnotationAdded {
2170    pub sequence_number: u64,
2171    pub item_id: String,
2172    pub output_index: u32,
2173    pub content_index: u32,
2174    pub annotation_index: u32,
2175    pub annotation: TextAnnotation,
2176}
2177
2178/// Text annotation object for output text
2179#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2180#[non_exhaustive]
2181pub struct TextAnnotation {
2182    #[serde(rename = "type")]
2183    pub annotation_type: String,
2184    pub text: String,
2185    pub start: u32,
2186    pub end: u32,
2187}