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