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