async_openai_wasm/types/
responses.rs

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