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