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