async_openai/types/
responses.rs

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