async_openai/types/
responses.rs

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