dynamo_async_openai/types/
responses.rs

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