async_openai_compat/types/
responses.rs

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