async_openai/types/responses/response.rs
1use crate::error::OpenAIError;
2pub use crate::types::{
3 CompletionTokensDetails, ImageDetail, PromptTokensDetails, ReasoningEffort,
4 ResponseFormatJsonSchema,
5};
6use crate::types::{MCPListToolsTool, MCPTool};
7use derive_builder::Builder;
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10
11/// Role of messages in the API.
12#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
13#[serde(rename_all = "lowercase")]
14pub enum Role {
15 User,
16 Assistant,
17 System,
18 Developer,
19}
20
21/// Status of input/output items.
22#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
23#[serde(rename_all = "snake_case")]
24pub enum OutputStatus {
25 InProgress,
26 Completed,
27 Incomplete,
28}
29
30#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
31#[serde(untagged)]
32pub enum InputParam {
33 /// A text input to the model, equivalent to a text input with the
34 /// `user` role.
35 Text(String),
36 /// A list of one or many input items to the model, containing
37 /// different content types.
38 Items(Vec<InputItem>),
39}
40
41impl Default for InputParam {
42 fn default() -> Self {
43 Self::Text(String::new())
44 }
45}
46
47/// Content item used to generate a response.
48///
49/// This is a properly discriminated union based on the `type` field, using Rust's
50/// type-safe enum with serde's tag attribute for efficient deserialization.
51///
52/// # OpenAPI Specification
53/// Corresponds to the `Item` schema in the OpenAPI spec with a `type` discriminator.
54#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
55#[serde(tag = "type", rename_all = "snake_case")]
56pub enum Item {
57 /// A message (type: "message").
58 /// Can represent InputMessage (user/system/developer) or OutputMessage (assistant).
59 ///
60 /// InputMessage:
61 /// A message input to the model with a role indicating instruction following hierarchy.
62 /// Instructions given with the developer or system role take precedence over instructions given with the user role.
63 /// OutputMessage:
64 /// A message output from the model.
65 Message(MessageItem),
66
67 /// The results of a file search tool call. See the
68 /// [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
69 FileSearchCall(FileSearchToolCall),
70
71 /// A tool call to a computer use tool. See the
72 /// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
73 ComputerCall(ComputerToolCall),
74
75 /// The output of a computer tool call.
76 ComputerCallOutput(ComputerCallOutputItemParam),
77
78 /// The results of a web search tool call. See the
79 /// [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
80 WebSearchCall(WebSearchToolCall),
81
82 /// A tool call to run a function. See the
83 ///
84 /// [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
85 FunctionCall(FunctionToolCall),
86
87 /// The output of a function tool call.
88 FunctionCallOutput(FunctionCallOutputItemParam),
89
90 /// A description of the chain of thought used by a reasoning model while generating
91 /// a response. Be sure to include these items in your `input` to the Responses API
92 /// for subsequent turns of a conversation if you are manually
93 /// [managing context](https://platform.openai.com/docs/guides/conversation-state).
94 Reasoning(ReasoningItem),
95
96 /// An image generation request made by the model.
97 ImageGenerationCall(ImageGenToolCall),
98
99 /// A tool call to run code.
100 CodeInterpreterCall(CodeInterpreterToolCall),
101
102 /// A tool call to run a command on the local shell.
103 LocalShellCall(LocalShellToolCall),
104
105 /// The output of a local shell tool call.
106 LocalShellCallOutput(LocalShellToolCallOutput),
107
108 /// A list of tools available on an MCP server.
109 McpListTools(MCPListTools),
110
111 /// A request for human approval of a tool invocation.
112 McpApprovalRequest(MCPApprovalRequest),
113
114 /// A response to an MCP approval request.
115 McpApprovalResponse(MCPApprovalResponse),
116
117 /// An invocation of a tool on an MCP server.
118 McpCall(MCPToolCall),
119
120 /// The output of a custom tool call from your code, being sent back to the model.
121 CustomToolCallOutput(CustomToolCallOutput),
122
123 /// A call to a custom tool created by the model.
124 CustomToolCall(CustomToolCall),
125}
126
127/// Input item that can be used in the context for generating a response.
128///
129/// This represents the OpenAPI `InputItem` schema which is an `anyOf`:
130/// 1. `EasyInputMessage` - Simple, user-friendly message input (can use string content)
131/// 2. `Item` - Structured items with proper type discrimination (including InputMessage, OutputMessage, tool calls)
132/// 3. `ItemReferenceParam` - Reference to an existing item by ID (type can be null)
133///
134/// Uses untagged deserialization because these types overlap in structure.
135/// Order matters: more specific structures are tried first.
136///
137/// # OpenAPI Specification
138/// Corresponds to the `InputItem` schema: `anyOf[EasyInputMessage, Item, ItemReferenceParam]`
139#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
140#[serde(untagged)]
141pub enum InputItem {
142 /// A reference to an existing item by ID.
143 /// Has a required `id` field and optional `type` (can be "item_reference" or null).
144 /// Must be tried first as it's the most minimal structure.
145 ItemReference(ItemReference),
146
147 /// All structured items with proper type discrimination.
148 /// Includes InputMessage, OutputMessage, and all tool calls/outputs.
149 /// Uses the discriminated `Item` enum for efficient, type-safe deserialization.
150 Item(Item),
151
152 /// A simple, user-friendly message input (EasyInputMessage).
153 /// Supports string content and can include assistant role for previous responses.
154 /// Must be tried last as it's the most flexible structure.
155 ///
156 /// A message input to the model with a role indicating instruction following
157 /// hierarchy. Instructions given with the `developer` or `system` role take
158 /// precedence over instructions given with the `user` role. Messages with the
159 /// `assistant` role are presumed to have been generated by the model in previous
160 /// interactions.
161 EasyMessage(EasyInputMessage),
162}
163
164impl InputItem {
165 /// Creates an InputItem from an item reference ID.
166 pub fn from_reference(id: impl Into<String>) -> Self {
167 Self::ItemReference(ItemReference::new(id))
168 }
169
170 /// Creates an InputItem from a structured Item.
171 pub fn from_item(item: Item) -> Self {
172 Self::Item(item)
173 }
174
175 /// Creates an InputItem from an EasyInputMessage.
176 pub fn from_easy_message(message: EasyInputMessage) -> Self {
177 Self::EasyMessage(message)
178 }
179
180 /// Creates a simple text message with the given role and content.
181 pub fn text_message(role: Role, content: impl Into<String>) -> Self {
182 Self::EasyMessage(EasyInputMessage {
183 r#type: MessageType::Message,
184 role,
185 content: EasyInputContent::Text(content.into()),
186 })
187 }
188}
189
190/// A message item used within the `Item` enum.
191///
192/// Both InputMessage and OutputMessage have `type: "message"`, so we use an untagged
193/// enum to distinguish them based on their structure:
194/// - OutputMessage: role=assistant, required id & status fields
195/// - InputMessage: role=user/system/developer, content is Vec<ContentType>, optional id/status
196///
197/// Note: EasyInputMessage is NOT included here - it's a separate variant in `InputItem`,
198/// not part of the structured `Item` enum.
199#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
200#[serde(untagged)]
201pub enum MessageItem {
202 /// An output message from the model (role: assistant, has required id & status).
203 /// This must come first as it has the most specific structure (required id and status fields).
204 Output(OutputMessage),
205
206 /// A structured input message (role: user/system/developer, content is Vec<ContentType>).
207 /// Has structured content list and optional id/status fields.
208 ///
209 /// A message input to the model with a role indicating instruction following hierarchy.
210 /// Instructions given with the `developer` or `system` role take precedence over instructions
211 /// given with the `user` role.
212 Input(InputMessage),
213}
214
215/// A reference to an existing item by ID.
216#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
217pub struct ItemReference {
218 /// The type of item to reference. Can be "item_reference" or null.
219 #[serde(skip_serializing_if = "Option::is_none")]
220 pub r#type: Option<ItemReferenceType>,
221 /// The ID of the item to reference.
222 pub id: String,
223}
224
225impl ItemReference {
226 /// Create a new item reference with the given ID.
227 pub fn new(id: impl Into<String>) -> Self {
228 Self {
229 r#type: Some(ItemReferenceType::ItemReference),
230 id: id.into(),
231 }
232 }
233}
234
235#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
236#[serde(rename_all = "snake_case")]
237pub enum ItemReferenceType {
238 ItemReference,
239}
240
241/// Output from a function call that you're providing back to the model.
242#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
243pub struct FunctionCallOutputItemParam {
244 /// The unique ID of the function tool call generated by the model.
245 pub call_id: String,
246 /// Text, image, or file output of the function tool call.
247 pub output: FunctionCallOutput,
248 /// The unique ID of the function tool call output.
249 /// Populated when this item is returned via API.
250 #[serde(skip_serializing_if = "Option::is_none")]
251 pub id: Option<String>,
252 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
253 /// Populated when items are returned via API.
254 #[serde(skip_serializing_if = "Option::is_none")]
255 pub status: Option<OutputStatus>,
256}
257
258#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
259#[serde(untagged)]
260pub enum FunctionCallOutput {
261 /// A JSON string of the output of the function tool call.
262 Text(String),
263 Content(Vec<InputContent>), // TODO use shape which allows null from OpenAPI spec?
264}
265
266#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
267pub struct ComputerCallOutputItemParam {
268 /// The ID of the computer tool call that produced the output.
269 pub call_id: String,
270 /// A computer screenshot image used with the computer use tool.
271 pub output: ComputerScreenshotImage,
272 /// The safety checks reported by the API that have been acknowledged by the developer.
273 #[serde(skip_serializing_if = "Option::is_none")]
274 pub acknowledged_safety_checks: Option<Vec<ComputerCallSafetyCheckParam>>,
275 /// The unique ID of the computer tool call output. Optional when creating.
276 #[serde(skip_serializing_if = "Option::is_none")]
277 pub id: Option<String>,
278 /// The status of the message input. One of `in_progress`, `completed`, or `incomplete`.
279 /// Populated when input items are returned via API.
280 #[serde(skip_serializing_if = "Option::is_none")]
281 pub status: Option<OutputStatus>, // TODO rename OutputStatus?
282}
283
284#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
285#[serde(rename_all = "snake_case")]
286pub enum ComputerScreenshotImageType {
287 ComputerScreenshot,
288}
289
290/// A computer screenshot image used with the computer use tool.
291#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
292pub struct ComputerScreenshotImage {
293 /// Specifies the event type. For a computer screenshot, this property is always
294 /// set to `computer_screenshot`.
295 pub r#type: ComputerScreenshotImageType,
296 /// The identifier of an uploaded file that contains the screenshot.
297 #[serde(skip_serializing_if = "Option::is_none")]
298 pub file_id: Option<String>,
299 /// The URL of the screenshot image.
300 #[serde(skip_serializing_if = "Option::is_none")]
301 pub image_url: Option<String>,
302}
303
304/// Output from a local shell tool call that you're providing back to the model.
305#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
306pub struct LocalShellToolCallOutput {
307 /// The unique ID of the local shell tool call generated by the model.
308 pub id: String,
309
310 /// A JSON string of the output of the local shell tool call.
311 pub output: String,
312
313 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
314 #[serde(skip_serializing_if = "Option::is_none")]
315 pub status: Option<OutputStatus>,
316}
317
318/// Output from a local shell command execution.
319#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
320pub struct LocalShellOutput {
321 /// The stdout output from the command.
322 #[serde(skip_serializing_if = "Option::is_none")]
323 pub stdout: Option<String>,
324
325 /// The stderr output from the command.
326 #[serde(skip_serializing_if = "Option::is_none")]
327 pub stderr: Option<String>,
328
329 /// The exit code of the command.
330 #[serde(skip_serializing_if = "Option::is_none")]
331 pub exit_code: Option<i32>,
332}
333
334/// An MCP approval response that you're providing back to the model.
335#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
336pub struct MCPApprovalResponse {
337 /// The ID of the approval request being answered.
338 pub approval_request_id: String,
339
340 /// Whether the request was approved.
341 pub approve: bool,
342
343 /// The unique ID of the approval response
344 #[serde(skip_serializing_if = "Option::is_none")]
345 pub id: Option<String>,
346
347 /// Optional reason for the decision.
348 #[serde(skip_serializing_if = "Option::is_none")]
349 pub reason: Option<String>,
350}
351
352#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
353#[serde(untagged)]
354pub enum CustomToolCallOutputOutput {
355 /// A string of the output of the custom tool call.
356 Text(String),
357 /// Text, image, or file output of the custom tool call.
358 List(Vec<InputContent>),
359}
360
361#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
362pub struct CustomToolCallOutput {
363 /// The call ID, used to map this custom tool call output to a custom tool call.
364 pub call_id: String,
365
366 /// The output from the custom tool call generated by your code.
367 /// Can be a string or an list of output content.
368 pub output: CustomToolCallOutputOutput,
369
370 /// The unique ID of the custom tool call output in the OpenAI platform.
371 #[serde(skip_serializing_if = "Option::is_none")]
372 pub id: Option<String>,
373}
374
375/// A simplified message input to the model (EasyInputMessage in the OpenAPI spec).
376///
377/// This is the most user-friendly way to provide messages, supporting both simple
378/// string content and structured content. Role can include `assistant` for providing
379/// previous assistant responses.
380#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
381#[builder(
382 name = "EasyInputMessageArgs",
383 pattern = "mutable",
384 setter(into, strip_option),
385 default
386)]
387#[builder(build_fn(error = "OpenAIError"))]
388pub struct EasyInputMessage {
389 /// The type of the message input. Always set to `message`.
390 pub r#type: MessageType,
391 /// The role of the message input. One of `user`, `assistant`, `system`, or `developer`.
392 pub role: Role,
393 /// Text, image, or audio input to the model, used to generate a response.
394 /// Can also contain previous assistant responses.
395 pub content: EasyInputContent,
396}
397
398/// A structured message input to the model (InputMessage in the OpenAPI spec).
399///
400/// This variant requires structured content (not a simple string) and does not support
401/// the `assistant` role (use OutputMessage for that). Used when items are returned via API
402/// with additional metadata.
403#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
404#[builder(
405 name = "InputMessageArgs",
406 pattern = "mutable",
407 setter(into, strip_option),
408 default
409)]
410#[builder(build_fn(error = "OpenAIError"))]
411pub struct InputMessage {
412 /// A list of one or many input items to the model, containing different content types.
413 pub content: Vec<InputContent>,
414 /// The role of the message input. One of `user`, `system`, or `developer`.
415 /// Note: `assistant` is NOT allowed here; use OutputMessage instead.
416 pub role: InputRole,
417 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
418 /// Populated when items are returned via API.
419 #[serde(skip_serializing_if = "Option::is_none")]
420 pub status: Option<OutputStatus>,
421 /////The type of the message input. Always set to `message`.
422 //pub r#type: MessageType,
423}
424
425/// The role for an input message - can only be `user`, `system`, or `developer`.
426/// This type ensures type safety by excluding the `assistant` role (use OutputMessage for that).
427#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
428#[serde(rename_all = "lowercase")]
429pub enum InputRole {
430 #[default]
431 User,
432 System,
433 Developer,
434}
435
436/// Content for EasyInputMessage - can be a simple string or structured list.
437#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
438#[serde(untagged)]
439pub enum EasyInputContent {
440 /// A text input to the model.
441 Text(String),
442 /// A list of one or many input items to the model, containing different content types.
443 ContentList(Vec<InputContent>),
444}
445
446/// Parts of a message: text, image, file, or audio.
447#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
448#[serde(tag = "type", rename_all = "snake_case")]
449pub enum InputContent {
450 /// A text input to the model.
451 InputText(InputTextContent),
452 /// An image input to the model. Learn about
453 /// [image inputs](https://platform.openai.com/docs/guides/vision).
454 InputImage(InputImageContent),
455 /// A file input to the model.
456 InputFile(InputFileContent),
457}
458
459#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
460pub struct InputTextContent {
461 /// The text input to the model.
462 pub text: String,
463}
464
465#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
466#[builder(
467 name = "InputImageArgs",
468 pattern = "mutable",
469 setter(into, strip_option),
470 default
471)]
472#[builder(build_fn(error = "OpenAIError"))]
473pub struct InputImageContent {
474 /// The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`.
475 /// Defaults to `auto`.
476 detail: ImageDetail,
477 /// The ID of the file to be sent to the model.
478 #[serde(skip_serializing_if = "Option::is_none")]
479 file_id: Option<String>,
480 /// The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image
481 /// in a data URL.
482 #[serde(skip_serializing_if = "Option::is_none")]
483 image_url: Option<String>,
484}
485
486#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
487#[builder(
488 name = "InputFileArgs",
489 pattern = "mutable",
490 setter(into, strip_option),
491 default
492)]
493#[builder(build_fn(error = "OpenAIError"))]
494pub struct InputFileContent {
495 /// The content of the file to be sent to the model.
496 #[serde(skip_serializing_if = "Option::is_none")]
497 file_data: Option<String>,
498 /// The ID of the file to be sent to the model.
499 #[serde(skip_serializing_if = "Option::is_none")]
500 file_id: Option<String>,
501 /// The URL of the file to be sent to the model.
502 #[serde(skip_serializing_if = "Option::is_none")]
503 file_url: Option<String>,
504 /// The name of the file to be sent to the model.
505 #[serde(skip_serializing_if = "Option::is_none")]
506 filename: Option<String>,
507}
508
509#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
510pub struct Conversation {
511 /// The unique ID of the conversation.
512 pub id: String,
513}
514
515#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
516#[serde(untagged)]
517pub enum ConversationParam {
518 /// The unique ID of the conversation.
519 ConversationID(String),
520 /// The conversation that this response belongs to.
521 Object(Conversation),
522}
523
524#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
525pub enum IncludeEnum {
526 #[serde(rename = "file_search_call.results")]
527 FileSearchCallResults,
528 #[serde(rename = "web_search_call.results")]
529 WebSearchCallResults,
530 #[serde(rename = "web_search_call.action.sources")]
531 WebSearchCallActionSources,
532 #[serde(rename = "message.input_image.image_url")]
533 MessageInputImageImageUrl,
534 #[serde(rename = "computer_call_output.output.image_url")]
535 ComputerCallOutputOutputImageUrl,
536 #[serde(rename = "code_interpreter_call.outputs")]
537 CodeInterpreterCallOutputs,
538 #[serde(rename = "reasoning.encrypted_content")]
539 ReasoningEncryptedContent,
540 #[serde(rename = "message.output_text.logprobs")]
541 MessageOutputTextLogprobs,
542}
543
544#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
545pub struct ResponseStreamOptions {
546 /// When true, stream obfuscation will be enabled. Stream obfuscation adds
547 /// random characters to an `obfuscation` field on streaming delta events to
548 /// normalize payload sizes as a mitigation to certain side-channel attacks.
549 /// These obfuscation fields are included by default, but add a small amount
550 /// of overhead to the data stream. You can set `include_obfuscation` to
551 /// false to optimize for bandwidth if you trust the network links between
552 /// your application and the OpenAI API.
553 #[serde(skip_serializing_if = "Option::is_none")]
554 pub include_obfuscation: Option<bool>,
555}
556
557/// Builder for a Responses API request.
558#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
559#[builder(
560 name = "CreateResponseArgs",
561 pattern = "mutable",
562 setter(into, strip_option),
563 default
564)]
565#[builder(build_fn(error = "OpenAIError"))]
566pub struct CreateResponse {
567 /// Whether to run the model response in the background.
568 /// [Learn more](https://platform.openai.com/docs/guides/background).
569 #[serde(skip_serializing_if = "Option::is_none")]
570 pub background: Option<bool>,
571
572 /// The conversation that this response belongs to. Items from this conversation are prepended to
573 /// `input_items` for this response request.
574 ///
575 /// Input items and output items from this response are automatically added to this conversation after
576 /// this response completes.
577 #[serde(skip_serializing_if = "Option::is_none")]
578 pub conversation: Option<ConversationParam>,
579
580 /// Specify additional output data to include in the model response. Currently supported
581 /// values are:
582 ///
583 /// - `web_search_call.action.sources`: Include the sources of the web search tool call.
584 ///
585 /// - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
586 /// interpreter tool call items.
587 ///
588 /// - `computer_call_output.output.image_url`: Include image urls from the computer call
589 /// output.
590 ///
591 /// - `file_search_call.results`: Include the search results of the file search tool call.
592 ///
593 /// - `message.input_image.image_url`: Include image urls from the input message.
594 ///
595 /// - `message.output_text.logprobs`: Include logprobs with assistant messages.
596 ///
597 /// - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
598 /// reasoning item outputs. This enables reasoning items to be used in multi-turn
599 /// conversations when using the Responses API statelessly (like when the `store` parameter is
600 /// set to `false`, or when an organization is enrolled in the zero data retention program).
601 #[serde(skip_serializing_if = "Option::is_none")]
602 pub include: Option<Vec<IncludeEnum>>,
603
604 /// Text, image, or file inputs to the model, used to generate a response.
605 ///
606 /// Learn more:
607 /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
608 /// - [Image inputs](https://platform.openai.com/docs/guides/images)
609 /// - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
610 /// - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
611 /// - [Function calling](https://platform.openai.com/docs/guides/function-calling)
612 pub input: InputParam,
613
614 /// A system (or developer) message inserted into the model's context.
615 ///
616 /// When using along with `previous_response_id`, the instructions from a previous
617 /// response will not be carried over to the next response. This makes it simple
618 /// to swap out system (or developer) messages in new responses.
619 #[serde(skip_serializing_if = "Option::is_none")]
620 pub instructions: Option<String>,
621
622 /// An upper bound for the number of tokens that can be generated for a response, including
623 /// visible output tokens and [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
624 #[serde(skip_serializing_if = "Option::is_none")]
625 pub max_output_tokens: Option<u32>,
626
627 /// The maximum number of total calls to built-in tools that can be processed in a response. This
628 /// maximum number applies across all built-in tool calls, not per individual tool. Any further
629 /// attempts to call a tool by the model will be ignored.
630 #[serde(skip_serializing_if = "Option::is_none")]
631 pub max_tool_calls: Option<u32>,
632
633 /// Set of 16 key-value pairs that can be attached to an object. This can be
634 /// useful for storing additional information about the object in a structured
635 /// format, and querying for objects via API or the dashboard.
636 ///
637 /// Keys are strings with a maximum length of 64 characters. Values are
638 /// strings with a maximum length of 512 characters.
639 #[serde(skip_serializing_if = "Option::is_none")]
640 pub metadata: Option<HashMap<String, String>>,
641
642 /// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI
643 /// offers a wide range of models with different capabilities, performance
644 /// characteristics, and price points. Refer to the [model guide](https://platform.openai.com/docs/models)
645 /// to browse and compare available models.
646 #[serde(skip_serializing_if = "Option::is_none")]
647 pub model: Option<String>,
648
649 /// Whether to allow the model to run tool calls in parallel.
650 #[serde(skip_serializing_if = "Option::is_none")]
651 pub parallel_tool_calls: Option<bool>,
652
653 /// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
654 /// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
655 /// Cannot be used in conjunction with `conversation`.
656 #[serde(skip_serializing_if = "Option::is_none")]
657 pub previous_response_id: Option<String>,
658
659 /// Reference to a prompt template and its variables.
660 /// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
661 #[serde(skip_serializing_if = "Option::is_none")]
662 pub prompt: Option<Prompt>,
663
664 /// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
665 /// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
666 #[serde(skip_serializing_if = "Option::is_none")]
667 pub prompt_cache_key: Option<String>,
668
669 /// **gpt-5 and o-series models only**
670 /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
671 #[serde(skip_serializing_if = "Option::is_none")]
672 pub reasoning: Option<Reasoning>,
673
674 /// A stable identifier used to help detect users of your application that may be violating OpenAI's
675 /// usage policies.
676 ///
677 /// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
678 /// or email address, in order to avoid sending us any identifying information. [Learn
679 /// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
680 #[serde(skip_serializing_if = "Option::is_none")]
681 pub safety_identifier: Option<String>,
682
683 /// Specifies the processing type used for serving the request.
684 /// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
685 /// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
686 /// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
687 /// - When not set, the default behavior is 'auto'.
688 ///
689 /// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
690 #[serde(skip_serializing_if = "Option::is_none")]
691 pub service_tier: Option<ServiceTier>,
692
693 /// Whether to store the generated model response for later retrieval via API.
694 #[serde(skip_serializing_if = "Option::is_none")]
695 pub store: Option<bool>,
696
697 /// If set to true, the model response data will be streamed to the client
698 /// as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
699 /// See the [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
700 /// for more information.
701 #[serde(skip_serializing_if = "Option::is_none")]
702 pub stream: Option<bool>,
703
704 /// Options for streaming responses. Only set this when you set `stream: true`.
705 #[serde(skip_serializing_if = "Option::is_none")]
706 pub stream_options: Option<ResponseStreamOptions>,
707
708 /// What sampling temperature to use, between 0 and 2. Higher values like 0.8
709 /// will make the output more random, while lower values like 0.2 will make it
710 /// more focused and deterministic. We generally recommend altering this or
711 /// `top_p` but not both.
712 #[serde(skip_serializing_if = "Option::is_none")]
713 pub temperature: Option<f32>,
714
715 /// Configuration options for a text response from the model. Can be plain
716 /// text or structured JSON data. Learn more:
717 /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
718 /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
719 #[serde(skip_serializing_if = "Option::is_none")]
720 pub text: Option<ResponseTextParam>,
721
722 /// How the model should select which tool (or tools) to use when generating
723 /// a response. See the `tools` parameter to see how to specify which tools
724 /// the model can call.
725 #[serde(skip_serializing_if = "Option::is_none")]
726 pub tool_choice: Option<ToolChoiceParam>,
727
728 /// An array of tools the model may call while generating a response. You
729 /// can specify which tool to use by setting the `tool_choice` parameter.
730 ///
731 /// We support the following categories of tools:
732 /// - **Built-in tools**: Tools that are provided by OpenAI that extend the
733 /// model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
734 /// or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
735 /// [built-in tools](https://platform.openai.com/docs/guides/tools).
736 /// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
737 /// or predefined connectors such as Google Drive and SharePoint. Learn more about
738 /// [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
739 /// - **Function calls (custom tools)**: Functions that are defined by you,
740 /// enabling the model to call your own code with strongly typed arguments
741 /// and outputs. Learn more about
742 /// [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
743 /// custom tools to call your own code.
744 #[serde(skip_serializing_if = "Option::is_none")]
745 pub tools: Option<Vec<Tool>>,
746
747 /// An integer between 0 and 20 specifying the number of most likely tokens to return at each
748 /// token position, each with an associated log probability.
749 #[serde(skip_serializing_if = "Option::is_none")]
750 pub top_logprobs: Option<u8>,
751
752 /// An alternative to sampling with temperature, called nucleus sampling,
753 /// where the model considers the results of the tokens with top_p probability
754 /// mass. So 0.1 means only the tokens comprising the top 10% probability mass
755 /// are considered.
756 ///
757 /// We generally recommend altering this or `temperature` but not both.
758 #[serde(skip_serializing_if = "Option::is_none")]
759 pub top_p: Option<f32>,
760
761 ///The truncation strategy to use for the model response.
762 /// - `auto`: If the input to this Response exceeds
763 /// the model's context window size, the model will truncate the
764 /// response to fit the context window by dropping items from the beginning of the conversation.
765 /// - `disabled` (default): If the input size will exceed the context window
766 /// size for a model, the request will fail with a 400 error.
767 #[serde(skip_serializing_if = "Option::is_none")]
768 pub truncation: Option<Truncation>,
769}
770
771#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
772#[serde(untagged)]
773pub enum ResponsePromptVariables {
774 String(String),
775 Content(InputContent),
776 Custom(serde_json::Value),
777}
778
779#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
780pub struct Prompt {
781 /// The unique identifier of the prompt template to use.
782 pub id: String,
783
784 /// Optional version of the prompt template.
785 #[serde(skip_serializing_if = "Option::is_none")]
786 pub version: Option<String>,
787
788 /// Optional map of values to substitute in for variables in your
789 /// prompt. The substitution values can either be strings, or other
790 /// Response input types like images or files.
791 #[serde(skip_serializing_if = "Option::is_none")]
792 pub variables: Option<ResponsePromptVariables>,
793}
794
795#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
796#[serde(rename_all = "lowercase")]
797pub enum ServiceTier {
798 #[default]
799 Auto,
800 Default,
801 Flex,
802 Scale,
803 Priority,
804}
805
806/// Truncation strategies.
807#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
808#[serde(rename_all = "lowercase")]
809pub enum Truncation {
810 Auto,
811 Disabled,
812}
813
814#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
815pub struct Billing {
816 pub payer: String,
817}
818
819/// o-series reasoning settings.
820#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
821#[builder(
822 name = "ReasoningArgs",
823 pattern = "mutable",
824 setter(into, strip_option),
825 default
826)]
827#[builder(build_fn(error = "OpenAIError"))]
828pub struct Reasoning {
829 /// Constrains effort on reasoning for
830 /// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
831 /// Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing
832 /// reasoning effort can result in faster responses and fewer tokens used
833 /// on reasoning in a response.
834 ///
835 /// Note: The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.
836 #[serde(skip_serializing_if = "Option::is_none")]
837 pub effort: Option<ReasoningEffort>,
838 /// A summary of the reasoning performed by the model. This can be
839 /// useful for debugging and understanding the model's reasoning process.
840 /// One of `auto`, `concise`, or `detailed`.
841 ///
842 /// `concise` is only supported for `computer-use-preview` models.
843 #[serde(skip_serializing_if = "Option::is_none")]
844 pub summary: Option<ReasoningSummary>,
845}
846
847/// o-series reasoning settings.
848#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
849#[serde(rename_all = "lowercase")]
850pub enum Verbosity {
851 Low,
852 Medium,
853 High,
854}
855
856#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
857#[serde(rename_all = "lowercase")]
858pub enum ReasoningSummary {
859 Auto,
860 Concise,
861 Detailed,
862}
863
864/// Configuration for text response format.
865#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
866pub struct ResponseTextParam {
867 /// An object specifying the format that the model must output.
868 ///
869 /// Configuring `{ "type": "json_schema" }` enables Structured Outputs,
870 /// which ensures the model will match your supplied JSON schema. Learn more in the
871 /// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
872 ///
873 /// The default format is `{ "type": "text" }` with no additional options.
874 ///
875 /// **Not recommended for gpt-4o and newer models:**
876 ///
877 /// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
878 /// ensures the message the model generates is valid JSON. Using `json_schema`
879 /// is preferred for models that support it.
880 pub format: TextResponseFormatConfiguration,
881
882 /// Constrains the verbosity of the model's response. Lower values will result in
883 /// more concise responses, while higher values will result in more verbose responses.
884 ///
885 /// Currently supported values are `low`, `medium`, and `high`.
886 #[serde(skip_serializing_if = "Option::is_none")]
887 pub verbosity: Option<Verbosity>,
888}
889
890#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
891#[serde(tag = "type", rename_all = "snake_case")]
892pub enum TextResponseFormatConfiguration {
893 /// Default response format. Used to generate text responses.
894 Text,
895 /// JSON object response format. An older method of generating JSON responses.
896 /// Using `json_schema` is recommended for models that support it.
897 /// Note that the model will not generate JSON without a system or user message
898 /// instructing it to do so.
899 JsonObject,
900 /// JSON Schema response format. Used to generate structured JSON responses.
901 /// Learn more about [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
902 JsonSchema(ResponseFormatJsonSchema),
903}
904
905/// Definitions for model-callable tools.
906#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
907#[serde(tag = "type", rename_all = "snake_case")]
908pub enum Tool {
909 /// Defines a function in your own code the model can choose to call. Learn more about [function
910 /// calling](https://platform.openai.com/docs/guides/tools).
911 Function(FunctionTool),
912 /// A tool that searches for relevant content from uploaded files. Learn more about the [file search
913 /// tool](https://platform.openai.com/docs/guides/tools-file-search).
914 FileSearch(FileSearchTool),
915 /// A tool that controls a virtual computer. Learn more about the [computer
916 /// use tool](https://platform.openai.com/docs/guides/tools-computer-use).
917 ComputerUsePreview(ComputerUsePreviewTool),
918 /// Search the Internet for sources related to the prompt. Learn more about the
919 /// [web search tool](https://platform.openai.com/docs/guides/tools-web-search).
920 WebSearch(WebSearchTool),
921 /// type: web_search_2025_08_26
922 #[serde(rename = "web_search_2025_08_26")]
923 WebSearch20250826(WebSearchTool),
924 /// Give the model access to additional tools via remote Model Context Protocol
925 /// (MCP) servers. [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).
926 Mcp(MCPTool),
927 /// A tool that runs Python code to help generate a response to a prompt.
928 CodeInterpreter(CodeInterpreterTool),
929 /// A tool that generates images using a model like `gpt-image-1`.
930 ImageGeneration(ImageGenTool),
931 /// A tool that allows the model to execute shell commands in a local environment.
932 LocalShell,
933 /// A custom tool that processes input using a specified format. Learn more about [custom
934 /// tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
935 Custom(CustomToolParam),
936 /// This tool searches the web for relevant results to use in a response. Learn more about the [web search
937 ///tool](https://platform.openai.com/docs/guides/tools-web-search).
938 WebSearchPreview(WebSearchTool),
939 /// type: web_search_preview_2025_03_11
940 #[serde(rename = "web_search_preview_2025_03_11")]
941 WebSearchPreview20250311(WebSearchTool),
942}
943
944#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
945pub struct CustomToolParam {
946 /// The name of the custom tool, used to identify it in tool calls.
947 pub name: String,
948 /// Optional description of the custom tool, used to provide more context.
949 pub description: Option<String>,
950 /// The input format for the custom tool. Default is unconstrained text.
951 pub format: CustomToolParamFormat,
952}
953
954#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
955#[serde(rename_all = "lowercase")]
956pub enum GrammarSyntax {
957 Lark,
958 #[default]
959 Regex,
960}
961
962#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
963pub struct CustomGrammarFormatParam {
964 /// The grammar definition.
965 pub definition: String,
966 /// The syntax of the grammar definition. One of `lark` or `regex`.
967 pub syntax: GrammarSyntax,
968}
969
970#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
971#[serde(tag = "type", rename_all = "lowercase")]
972pub enum CustomToolParamFormat {
973 /// Unconstrained free-form text.
974 #[default]
975 Text,
976 /// A grammar defined by the user.
977 Grammar(CustomGrammarFormatParam),
978}
979
980#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
981#[builder(
982 name = "FileSearchToolArgs",
983 pattern = "mutable",
984 setter(into, strip_option),
985 default
986)]
987#[builder(build_fn(error = "OpenAIError"))]
988pub struct FileSearchTool {
989 /// The IDs of the vector stores to search.
990 pub vector_store_ids: Vec<String>,
991 /// The maximum number of results to return. This number should be between 1 and 50 inclusive.
992 #[serde(skip_serializing_if = "Option::is_none")]
993 pub max_num_results: Option<u32>,
994 /// A filter to apply.
995 #[serde(skip_serializing_if = "Option::is_none")]
996 pub filters: Option<Filter>,
997 /// Ranking options for search.
998 #[serde(skip_serializing_if = "Option::is_none")]
999 pub ranking_options: Option<RankingOptions>,
1000}
1001
1002#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1003#[builder(
1004 name = "FunctionToolArgs",
1005 pattern = "mutable",
1006 setter(into, strip_option),
1007 default
1008)]
1009pub struct FunctionTool {
1010 /// The name of the function to call.
1011 pub name: String,
1012 /// A JSON schema object describing the parameters of the function.
1013 #[serde(skip_serializing_if = "Option::is_none")]
1014 pub parameters: Option<serde_json::Value>,
1015 /// Whether to enforce strict parameter validation. Default `true`.
1016 #[serde(skip_serializing_if = "Option::is_none")]
1017 pub strict: Option<bool>,
1018 /// A description of the function. Used by the model to determine whether or not to call the
1019 /// function.
1020 #[serde(skip_serializing_if = "Option::is_none")]
1021 pub description: Option<String>,
1022}
1023
1024#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1025pub struct WebSearchToolFilters {
1026 /// Allowed domains for the search. If not provided, all domains are allowed.
1027 /// Subdomains of the provided domains are allowed as well.
1028 ///
1029 /// Example: `["pubmed.ncbi.nlm.nih.gov"]`
1030 #[serde(skip_serializing_if = "Option::is_none")]
1031 pub allowed_domains: Option<Vec<String>>,
1032}
1033
1034#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1035#[builder(
1036 name = "WebSearchToolArgs",
1037 pattern = "mutable",
1038 setter(into, strip_option),
1039 default
1040)]
1041pub struct WebSearchTool {
1042 /// Filters for the search.
1043 #[serde(skip_serializing_if = "Option::is_none")]
1044 pub filters: Option<WebSearchToolFilters>,
1045 /// The approximate location of the user.
1046 #[serde(skip_serializing_if = "Option::is_none")]
1047 pub user_location: Option<WebSearchApproximateLocation>,
1048 /// High level guidance for the amount of context window space to use for the search. One of `low`,
1049 /// `medium`, or `high`. `medium` is the default.
1050 #[serde(skip_serializing_if = "Option::is_none")]
1051 pub search_context_size: Option<WebSearchToolSearchContextSize>,
1052}
1053
1054#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1055#[serde(rename_all = "lowercase")]
1056pub enum WebSearchToolSearchContextSize {
1057 Low,
1058 #[default]
1059 Medium,
1060 High,
1061}
1062
1063#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1064#[serde(rename_all = "lowercase")]
1065pub enum ComputerEnvironment {
1066 Windows,
1067 Mac,
1068 Linux,
1069 Ubuntu,
1070 #[default]
1071 Browser,
1072}
1073
1074#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1075#[builder(
1076 name = "ComputerUsePreviewToolArgs",
1077 pattern = "mutable",
1078 setter(into, strip_option),
1079 default
1080)]
1081pub struct ComputerUsePreviewTool {
1082 /// The type of computer environment to control.
1083 environment: ComputerEnvironment,
1084 /// The width of the computer display.
1085 display_width: u32,
1086 /// The height of the computer display.
1087 display_height: u32,
1088}
1089
1090#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1091pub enum RankVersionType {
1092 #[serde(rename = "auto")]
1093 Auto,
1094 #[serde(rename = "default-2024-11-15")]
1095 Default20241115,
1096}
1097
1098#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1099pub struct HybridSearch {
1100 /// The weight of the embedding in the reciprocal ranking fusion.
1101 pub embedding_weight: f32,
1102 /// The weight of the text in the reciprocal ranking fusion.
1103 pub text_weight: f32,
1104}
1105
1106/// Options for search result ranking.
1107#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1108pub struct RankingOptions {
1109 /// Weights that control how reciprocal rank fusion balances semantic embedding matches versus
1110 /// sparse keyword matches when hybrid search is enabled.
1111 #[serde(skip_serializing_if = "Option::is_none")]
1112 pub hybrid_search: Option<HybridSearch>,
1113 /// The ranker to use for the file search.
1114 pub ranker: RankVersionType,
1115 /// The score threshold for the file search, a number between 0 and 1. Numbers closer to 1 will
1116 /// attempt to return only the most relevant results, but may return fewer results.
1117 #[serde(skip_serializing_if = "Option::is_none")]
1118 pub score_threshold: Option<f32>,
1119}
1120
1121/// Filters for file search.
1122#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1123#[serde(untagged)]
1124pub enum Filter {
1125 /// A filter used to compare a specified attribute key to a given value using a defined
1126 /// comparison operation.
1127 Comparison(ComparisonFilter),
1128 /// Combine multiple filters using `and` or `or`.
1129 Compound(CompoundFilter),
1130}
1131
1132/// Single comparison filter.
1133#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1134pub struct ComparisonFilter {
1135 /// Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `nin`.
1136 /// - `eq`: equals
1137 /// - `ne`: not equal
1138 /// - `gt`: greater than
1139 /// - `gte`: greater than or equal
1140 /// - `lt`: less than
1141 /// - `lte`: less than or equal
1142 /// - `in`: in
1143 /// - `nin`: not in
1144 pub r#type: ComparisonType,
1145 /// The key to compare against the value.
1146 pub key: String,
1147 /// The value to compare against the attribute key; supports string, number, or boolean types.
1148 pub value: serde_json::Value,
1149}
1150
1151#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1152pub enum ComparisonType {
1153 #[serde(rename = "eq")]
1154 Equals,
1155 #[serde(rename = "ne")]
1156 NotEquals,
1157 #[serde(rename = "gt")]
1158 GreaterThan,
1159 #[serde(rename = "gte")]
1160 GreaterThanOrEqual,
1161 #[serde(rename = "lt")]
1162 LessThan,
1163 #[serde(rename = "lte")]
1164 LessThanOrEqual,
1165 #[serde(rename = "in")]
1166 In,
1167 #[serde(rename = "nin")]
1168 NotIn,
1169}
1170
1171/// Combine multiple filters using `and` or `or`.
1172#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1173pub struct CompoundFilter {
1174 /// 'Type of operation: `and` or `or`.'
1175 pub r#type: CompoundType,
1176 /// Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.
1177 pub filters: Vec<Filter>,
1178}
1179
1180#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1181#[serde(rename_all = "lowercase")]
1182pub enum CompoundType {
1183 And,
1184 Or,
1185}
1186
1187#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1188#[serde(rename_all = "lowercase")]
1189pub enum WebSearchApproximateLocationType {
1190 #[default]
1191 Approximate,
1192}
1193
1194/// Approximate user location for web search.
1195#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1196#[builder(
1197 name = "WebSearchApproximateLocationArgs",
1198 pattern = "mutable",
1199 setter(into, strip_option),
1200 default
1201)]
1202#[builder(build_fn(error = "OpenAIError"))]
1203pub struct WebSearchApproximateLocation {
1204 /// The type of location approximation. Always `approximate`.
1205 pub r#type: WebSearchApproximateLocationType,
1206 /// Free text input for the city of the user, e.g. `San Francisco`.
1207 #[serde(skip_serializing_if = "Option::is_none")]
1208 pub city: Option<String>,
1209 /// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user,
1210 /// e.g. `US`.
1211 #[serde(skip_serializing_if = "Option::is_none")]
1212 pub country: Option<String>,
1213 /// Free text input for the region of the user, e.g. `California`.
1214 #[serde(skip_serializing_if = "Option::is_none")]
1215 pub region: Option<String>,
1216 /// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the user, e.g.
1217 /// `America/Los_Angeles`.
1218 #[serde(skip_serializing_if = "Option::is_none")]
1219 pub timezone: Option<String>,
1220}
1221
1222/// Container configuration for a code interpreter.
1223#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1224#[serde(tag = "type", rename_all = "snake_case")]
1225pub enum CodeInterpreterToolContainer {
1226 /// Configuration for a code interpreter container. Optionally specify the IDs of the
1227 /// files to run the code on.
1228 Auto(CodeInterpreterContainerAuto),
1229
1230 /// The container ID.
1231 #[serde(untagged)]
1232 ContainerID(String),
1233}
1234
1235impl Default for CodeInterpreterToolContainer {
1236 fn default() -> Self {
1237 Self::Auto(CodeInterpreterContainerAuto::default())
1238 }
1239}
1240
1241/// Auto configuration for code interpreter container.
1242#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1243pub struct CodeInterpreterContainerAuto {
1244 /// An optional list of uploaded files to make available to your code.
1245 #[serde(skip_serializing_if = "Option::is_none")]
1246 pub file_ids: Option<Vec<String>>,
1247
1248 #[serde(skip_serializing_if = "Option::is_none")]
1249 pub memory_limit: Option<u64>,
1250}
1251
1252#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1253#[builder(
1254 name = "CodeInterpreterToolArgs",
1255 pattern = "mutable",
1256 setter(into, strip_option),
1257 default
1258)]
1259#[builder(build_fn(error = "OpenAIError"))]
1260pub struct CodeInterpreterTool {
1261 /// The code interpreter container. Can be a container ID or an object that
1262 /// specifies uploaded file IDs to make available to your code.
1263 pub container: CodeInterpreterToolContainer,
1264}
1265
1266#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1267pub struct ImageGenToolInputImageMask {
1268 /// Base64-encoded mask image.
1269 #[serde(skip_serializing_if = "Option::is_none")]
1270 pub image_url: Option<String>,
1271 /// File ID for the mask image.
1272 #[serde(skip_serializing_if = "Option::is_none")]
1273 pub file_id: Option<String>,
1274}
1275
1276#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1277#[serde(rename_all = "lowercase")]
1278pub enum InputFidelity {
1279 #[default]
1280 High,
1281 Low,
1282}
1283
1284#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1285#[serde(rename_all = "lowercase")]
1286pub enum ImageGenToolModeration {
1287 #[default]
1288 Auto,
1289 Low,
1290}
1291
1292/// Image generation tool definition.
1293#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
1294#[builder(
1295 name = "ImageGenerationArgs",
1296 pattern = "mutable",
1297 setter(into, strip_option),
1298 default
1299)]
1300#[builder(build_fn(error = "OpenAIError"))]
1301pub struct ImageGenTool {
1302 /// Background type for the generated image. One of `transparent`,
1303 /// `opaque`, or `auto`. Default: `auto`.
1304 #[serde(skip_serializing_if = "Option::is_none")]
1305 pub background: Option<ImageGenToolBackground>,
1306 /// Control how much effort the model will exert to match the style and features, especially facial features,
1307 /// of input images. This parameter is only supported for `gpt-image-1`. Unsupported
1308 /// for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.
1309 #[serde(skip_serializing_if = "Option::is_none")]
1310 pub input_fidelity: Option<InputFidelity>,
1311 /// Optional mask for inpainting. Contains `image_url`
1312 /// (string, optional) and `file_id` (string, optional).
1313 #[serde(skip_serializing_if = "Option::is_none")]
1314 pub input_image_mask: Option<ImageGenToolInputImageMask>,
1315 /// The image generation model to use. Default: `gpt-image-1`.
1316 #[serde(skip_serializing_if = "Option::is_none")]
1317 pub model: Option<String>,
1318 /// Moderation level for the generated image. Default: `auto`.
1319 #[serde(skip_serializing_if = "Option::is_none")]
1320 pub moderation: Option<ImageGenToolModeration>,
1321 /// Compression level for the output image. Default: 100.
1322 #[serde(skip_serializing_if = "Option::is_none")]
1323 pub output_compression: Option<u8>,
1324 /// The output format of the generated image. One of `png`, `webp`, or
1325 /// `jpeg`. Default: `png`.
1326 #[serde(skip_serializing_if = "Option::is_none")]
1327 pub output_format: Option<ImageGenToolOutputFormat>,
1328 /// Number of partial images to generate in streaming mode, from 0 (default value) to 3.
1329 #[serde(skip_serializing_if = "Option::is_none")]
1330 pub partial_images: Option<u8>,
1331 /// The quality of the generated image. One of `low`, `medium`, `high`,
1332 /// or `auto`. Default: `auto`.
1333 #[serde(skip_serializing_if = "Option::is_none")]
1334 pub quality: Option<ImageGenToolQuality>,
1335 /// The size of the generated image. One of `1024x1024`, `1024x1536`,
1336 /// `1536x1024`, or `auto`. Default: `auto`.
1337 #[serde(skip_serializing_if = "Option::is_none")]
1338 pub size: Option<ImageGenToolSize>,
1339}
1340
1341#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1342#[serde(rename_all = "lowercase")]
1343pub enum ImageGenToolBackground {
1344 Transparent,
1345 Opaque,
1346 #[default]
1347 Auto,
1348}
1349
1350#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1351#[serde(rename_all = "lowercase")]
1352pub enum ImageGenToolOutputFormat {
1353 #[default]
1354 Png,
1355 Webp,
1356 Jpeg,
1357}
1358
1359#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1360#[serde(rename_all = "lowercase")]
1361pub enum ImageGenToolQuality {
1362 Low,
1363 Medium,
1364 High,
1365 #[default]
1366 Auto,
1367}
1368
1369#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1370#[serde(rename_all = "lowercase")]
1371pub enum ImageGenToolSize {
1372 #[default]
1373 Auto,
1374 #[serde(rename = "1024x1024")]
1375 Size1024x1024,
1376 #[serde(rename = "1024x1536")]
1377 Size1024x1536,
1378 #[serde(rename = "1536x1024")]
1379 Size1536x1024,
1380}
1381
1382#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1383#[serde(rename_all = "lowercase")]
1384pub enum ToolChoiceAllowedMode {
1385 Auto,
1386 Required,
1387}
1388
1389#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1390pub struct ToolChoiceAllowed {
1391 /// Constrains the tools available to the model to a pre-defined set.
1392 ///
1393 /// `auto` allows the model to pick from among the allowed tools and generate a
1394 /// message.
1395 ///
1396 /// `required` requires the model to call one or more of the allowed tools.
1397 mode: ToolChoiceAllowedMode,
1398 /// A list of tool definitions that the model should be allowed to call.
1399 ///
1400 /// For the Responses API, the list of tool definitions might look like:
1401 /// ```json
1402 /// [
1403 /// { "type": "function", "name": "get_weather" },
1404 /// { "type": "mcp", "server_label": "deepwiki" },
1405 /// { "type": "image_generation" }
1406 /// ]
1407 /// ```
1408 tools: Vec<serde_json::Value>,
1409}
1410
1411/// The type of hosted tool the model should to use. Learn more about
1412/// [built-in tools](https://platform.openai.com/docs/guides/tools).
1413#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1414#[serde(tag = "type", rename_all = "snake_case")]
1415pub enum ToolChoiceTypes {
1416 FileSearch,
1417 WebSearchPreview,
1418 ComputerUsePreview,
1419 CodeInterpreter,
1420 ImageGeneration,
1421}
1422
1423#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1424pub struct ToolChoiceFunction {
1425 /// The name of the function to call.
1426 name: String,
1427}
1428
1429#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1430pub struct ToolChoiceMCP {
1431 /// The name of the tool to call on the server.
1432 name: String,
1433 /// The label of the MCP server to use.
1434 server_label: String,
1435}
1436
1437#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1438pub struct ToolChoiceCustom {
1439 /// The name of the custom tool to call.
1440 name: String,
1441}
1442
1443#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1444#[serde(tag = "type", rename_all = "snake_case")]
1445pub enum ToolChoiceParam {
1446 /// Constrains the tools available to the model to a pre-defined set.
1447 AllowedTools(ToolChoiceAllowed),
1448
1449 /// Use this option to force the model to call a specific function.
1450 Function(ToolChoiceFunction),
1451
1452 /// Use this option to force the model to call a specific tool on a remote MCP server.
1453 Mcp(ToolChoiceMCP),
1454
1455 /// Use this option to force the model to call a custom tool.
1456 Custom(ToolChoiceCustom),
1457
1458 /// Indicates that the model should use a built-in tool to generate a response.
1459 /// [Learn more about built-in tools](https://platform.openai.com/docs/guides/tools).
1460 #[serde(untagged)]
1461 Hosted(ToolChoiceTypes),
1462
1463 /// Controls which (if any) tool is called by the model.
1464 ///
1465 /// `none` means the model will not call any tool and instead generates a message.
1466 ///
1467 /// `auto` means the model can pick between generating a message or calling one or
1468 /// more tools.
1469 ///
1470 /// `required` means the model must call one or more tools.
1471 #[serde(untagged)]
1472 Mode(ToolChoiceOptions),
1473}
1474
1475#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
1476#[serde(rename_all = "lowercase")]
1477pub enum ToolChoiceOptions {
1478 None,
1479 Auto,
1480 Required,
1481}
1482
1483/// Error returned by the API when a request fails.
1484#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1485pub struct ErrorObject {
1486 /// The error code for the response.
1487 pub code: String,
1488 /// A human-readable description of the error.
1489 pub message: String,
1490}
1491
1492/// Details about an incomplete response.
1493#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1494pub struct IncompleteDetails {
1495 /// The reason why the response is incomplete.
1496 pub reason: String,
1497}
1498
1499#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1500pub struct TopLogProb {
1501 pub bytes: Vec<u8>,
1502 pub logprob: f64,
1503 pub token: String,
1504}
1505
1506#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1507pub struct LogProb {
1508 pub bytes: Vec<u8>,
1509 pub logprob: f64,
1510 pub token: String,
1511 pub top_logprobs: Vec<TopLogProb>,
1512}
1513
1514#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1515pub struct ResponseTopLobProb {
1516 /// The log probability of this token.
1517 pub logprob: f64,
1518 /// A possible text token.
1519 pub token: String,
1520}
1521
1522#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1523pub struct ResponseLogProb {
1524 /// The log probability of this token.
1525 pub logprob: f64,
1526 /// A possible text token.
1527 pub token: String,
1528 /// The log probability of the top 20 most likely tokens.
1529 pub top_logprobs: Vec<ResponseTopLobProb>,
1530}
1531
1532/// A simple text output from the model.
1533#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1534pub struct OutputTextContent {
1535 /// The annotations of the text output.
1536 pub annotations: Vec<Annotation>,
1537 pub logprobs: Option<Vec<LogProb>>,
1538 /// The text output from the model.
1539 pub text: String,
1540}
1541
1542#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1543#[serde(tag = "type", rename_all = "snake_case")]
1544pub enum Annotation {
1545 /// A citation to a file.
1546 FileCitation(FileCitationBody),
1547 /// A citation for a web resource used to generate a model response.
1548 UrlCitation(UrlCitationBody),
1549 /// A citation for a container file used to generate a model response.
1550 ContainerFileCitation(ContainerFileCitationBody),
1551 /// A path to a file.
1552 FilePath(FilePath),
1553}
1554
1555#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1556pub struct FileCitationBody {
1557 /// The ID of the file.
1558 file_id: String,
1559 /// The filename of the file cited.
1560 filename: String,
1561 /// The index of the file in the list of files.
1562 index: u32,
1563}
1564
1565#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1566pub struct UrlCitationBody {
1567 /// The index of the last character of the URL citation in the message.
1568 end_index: u32,
1569 /// The index of the first character of the URL citation in the message.
1570 start_index: u32,
1571 /// The title of the web resource.
1572 title: String,
1573 /// The URL of the web resource.
1574 url: String,
1575}
1576
1577#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1578pub struct ContainerFileCitationBody {
1579 /// The ID of the container file.
1580 container_id: String,
1581 /// The index of the last character of the container file citation in the message.
1582 end_index: u32,
1583 /// The ID of the file.
1584 file_id: String,
1585 /// The filename of the container file cited.
1586 filename: String,
1587 /// The index of the first character of the container file citation in the message.
1588 start_index: u32,
1589}
1590
1591#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1592pub struct FilePath {
1593 /// The ID of the file.
1594 file_id: String,
1595 /// The index of the file in the list of files.
1596 index: u32,
1597}
1598
1599/// A refusal explanation from the model.
1600#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1601pub struct RefusalContent {
1602 /// The refusal explanation from the model.
1603 pub refusal: String,
1604}
1605
1606/// A message generated by the model.
1607#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1608pub struct OutputMessage {
1609 /// The content of the output message.
1610 pub content: Vec<OutputMessageContent>,
1611 /// The unique ID of the output message.
1612 pub id: String,
1613 /// The role of the output message. Always `assistant`.
1614 pub role: AssistantRole,
1615 /// The status of the message input. One of `in_progress`, `completed`, or
1616 /// `incomplete`. Populated when input items are returned via API.
1617 pub status: OutputStatus,
1618 ///// The type of the output message. Always `message`.
1619 //pub r#type: MessageType,
1620}
1621
1622#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
1623#[serde(rename_all = "lowercase")]
1624pub enum MessageType {
1625 #[default]
1626 Message,
1627}
1628
1629/// The role for an output message - always `assistant`.
1630/// This type ensures type safety by only allowing the assistant role.
1631#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
1632#[serde(rename_all = "lowercase")]
1633pub enum AssistantRole {
1634 #[default]
1635 Assistant,
1636}
1637
1638#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1639#[serde(tag = "type", rename_all = "snake_case")]
1640pub enum OutputMessageContent {
1641 /// A text output from the model.
1642 OutputText(OutputTextContent),
1643 /// A refusal from the model.
1644 Refusal(RefusalContent),
1645}
1646
1647#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1648#[serde(tag = "type", rename_all = "snake_case")]
1649pub enum OutputContent {
1650 /// A text output from the model.
1651 OutputText(OutputTextContent),
1652 /// A refusal from the model.
1653 Refusal(RefusalContent),
1654 /// Reasoning text from the model.
1655 ReasoningText(ReasoningTextContent),
1656}
1657
1658#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1659pub struct ReasoningTextContent {
1660 /// The reasoning text from the model.
1661 pub text: String,
1662}
1663
1664/// A reasoning item representing the model's chain of thought, including summary paragraphs.
1665#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1666pub struct ReasoningItem {
1667 /// Unique identifier of the reasoning content.
1668 pub id: String,
1669 /// Reasoning summary content.
1670 pub summary: Vec<Summary>,
1671 /// Reasoning text content.
1672 #[serde(skip_serializing_if = "Option::is_none")]
1673 pub content: Option<Vec<ReasoningTextContent>>,
1674 /// The encrypted content of the reasoning item - populated when a response is generated with
1675 /// `reasoning.encrypted_content` in the `include` parameter.
1676 #[serde(skip_serializing_if = "Option::is_none")]
1677 pub encrypted_content: Option<String>,
1678 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1679 /// Populated when items are returned via API.
1680 #[serde(skip_serializing_if = "Option::is_none")]
1681 pub status: Option<OutputStatus>,
1682}
1683
1684/// A single summary text fragment from reasoning.
1685#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1686pub struct Summary {
1687 /// A summary of the reasoning output from the model so far.
1688 pub text: String,
1689}
1690
1691/// File search tool call output.
1692#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1693pub struct FileSearchToolCall {
1694 /// The unique ID of the file search tool call.
1695 pub id: String,
1696 /// The queries used to search for files.
1697 pub queries: Vec<String>,
1698 /// The status of the file search tool call. One of `in_progress`, `searching`,
1699 /// `incomplete`,`failed`, or `completed`.
1700 pub status: FileSearchToolCallStatus,
1701 /// The results of the file search tool call.
1702 #[serde(skip_serializing_if = "Option::is_none")]
1703 pub results: Option<Vec<FileSearchToolCallResult>>,
1704}
1705
1706#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1707#[serde(rename_all = "snake_case")]
1708pub enum FileSearchToolCallStatus {
1709 InProgress,
1710 Searching,
1711 Incomplete,
1712 Failed,
1713 Completed,
1714}
1715
1716/// A single result from a file search.
1717#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1718pub struct FileSearchToolCallResult {
1719 /// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
1720 /// additional information about the object in a structured format, and querying for objects
1721 /// API or the dashboard. Keys are strings with a maximum length of 64 characters
1722 /// . Values are strings with a maximum length of 512 characters, booleans, or numbers.
1723 pub attributes: HashMap<String, serde_json::Value>,
1724 /// The unique ID of the file.
1725 pub file_id: String,
1726 /// The name of the file.
1727 pub filename: String,
1728 /// The relevance score of the file - a value between 0 and 1.
1729 pub score: f32,
1730 /// The text that was retrieved from the file.
1731 pub text: String,
1732}
1733
1734#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1735pub struct ComputerCallSafetyCheckParam {
1736 /// The ID of the pending safety check.
1737 pub id: String,
1738 /// The type of the pending safety check.
1739 #[serde(skip_serializing_if = "Option::is_none")]
1740 pub code: Option<String>,
1741 /// Details about the pending safety check.
1742 #[serde(skip_serializing_if = "Option::is_none")]
1743 pub message: Option<String>,
1744}
1745
1746#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1747#[serde(rename_all = "snake_case")]
1748pub enum WebSearchToolCallStatus {
1749 InProgress,
1750 Searching,
1751 Completed,
1752 Failed,
1753}
1754
1755#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1756pub struct WebSearchActionSearchSource {
1757 /// The type of source. Always `url`.
1758 pub r#type: String,
1759 /// The URL of the source.
1760 pub url: String,
1761}
1762
1763#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1764pub struct WebSearchActionSearch {
1765 /// The search query.
1766 pub query: String,
1767 /// The sources used in the search.
1768 pub sources: Option<Vec<WebSearchActionSearchSource>>,
1769}
1770
1771#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1772pub struct WebSearchActionOpenPage {
1773 /// The URL opened by the model.
1774 pub url: String,
1775}
1776
1777#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1778pub struct WebSearchActionFind {
1779 /// The URL of the page searched for the pattern.
1780 pub url: String,
1781 /// The pattern or text to search for within the page.
1782 pub pattern: String,
1783}
1784
1785#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1786#[serde(tag = "type", rename_all = "snake_case")]
1787pub enum WebSearchToolCallAction {
1788 /// Action type "search" - Performs a web search query.
1789 Search(WebSearchActionSearch),
1790 /// Action type "open_page" - Opens a specific URL from search results.
1791 OpenPage(WebSearchActionOpenPage),
1792 /// Action type "find": Searches for a pattern within a loaded page.
1793 Find(WebSearchActionFind),
1794}
1795
1796/// Web search tool call output.
1797#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1798pub struct WebSearchToolCall {
1799 /// An object describing the specific action taken in this web search call. Includes
1800 /// details on how the model used the web (search, open_page, find).
1801 pub action: WebSearchToolCallAction,
1802 /// The unique ID of the web search tool call.
1803 pub id: String,
1804 /// The status of the web search tool call.
1805 pub status: WebSearchToolCallStatus,
1806}
1807
1808/// Output from a computer tool call.
1809#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1810pub struct ComputerToolCall {
1811 pub action: ComputerAction,
1812 /// An identifier used when responding to the tool call with output.
1813 pub call_id: String,
1814 /// The unique ID of the computer call.
1815 pub id: String,
1816 /// The pending safety checks for the computer call.
1817 pub pending_safety_checks: Vec<ComputerCallSafetyCheckParam>,
1818 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1819 /// Populated when items are returned via API.
1820 pub status: OutputStatus,
1821}
1822
1823/// A point in 2D space.
1824#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1825pub struct DragPoint {
1826 /// The x-coordinate.
1827 pub x: i32,
1828 /// The y-coordinate.
1829 pub y: i32,
1830}
1831
1832/// Represents all user‐triggered actions.
1833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1834#[serde(tag = "type", rename_all = "snake_case")]
1835pub enum ComputerAction {
1836 /// A click action.
1837 Click(ClickParam),
1838
1839 /// A double click action.
1840 DoubleClick(DoubleClickAction),
1841
1842 /// A drag action.
1843 Drag(Drag),
1844
1845 /// A collection of keypresses the model would like to perform.
1846 Keypress(KeyPressAction),
1847
1848 /// A mouse move action.
1849 Move(Move),
1850
1851 /// A screenshot action.
1852 Screenshot,
1853
1854 /// A scroll action.
1855 Scroll(Scroll),
1856
1857 /// An action to type in text.
1858 Type(Type),
1859
1860 /// A wait action.
1861 Wait,
1862}
1863
1864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1865#[serde(rename_all = "lowercase")]
1866pub enum ClickButtonType {
1867 Left,
1868 Right,
1869 Wheel,
1870 Back,
1871 Forward,
1872}
1873
1874/// A click action.
1875#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1876pub struct ClickParam {
1877 /// Indicates which mouse button was pressed during the click. One of `left`,
1878 /// `right`, `wheel`, `back`, or `forward`.
1879 pub button: ClickButtonType,
1880 /// The x-coordinate where the click occurred.
1881 pub x: i32,
1882 /// The y-coordinate where the click occurred.
1883 pub y: i32,
1884}
1885
1886/// A double click action.
1887#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1888pub struct DoubleClickAction {
1889 /// The x-coordinate where the double click occurred.
1890 pub x: i32,
1891 /// The y-coordinate where the double click occurred.
1892 pub y: i32,
1893}
1894
1895/// A drag action.
1896#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1897pub struct Drag {
1898 /// The path of points the cursor drags through.
1899 pub path: Vec<DragPoint>,
1900}
1901
1902/// A keypress action.
1903#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1904pub struct KeyPressAction {
1905 /// The combination of keys the model is requesting to be pressed.
1906 /// This is an array of strings, each representing a key.
1907 pub keys: Vec<String>,
1908}
1909
1910/// A mouse move action.
1911#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1912pub struct Move {
1913 /// The x-coordinate to move to.
1914 pub x: i32,
1915 /// The y-coordinate to move to.
1916 pub y: i32,
1917}
1918
1919/// A scroll action.
1920#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1921pub struct Scroll {
1922 /// The horizontal scroll distance.
1923 pub scroll_x: i32,
1924 /// The vertical scroll distance.
1925 pub scroll_y: i32,
1926 /// The x-coordinate where the scroll occurred.
1927 pub x: i32,
1928 /// The y-coordinate where the scroll occurred.
1929 pub y: i32,
1930}
1931
1932/// A typing (text entry) action.
1933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1934pub struct Type {
1935 /// The text to type.
1936 pub text: String,
1937}
1938
1939#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1940pub struct FunctionToolCall {
1941 /// A JSON string of the arguments to pass to the function.
1942 pub arguments: String,
1943 /// The unique ID of the function tool call generated by the model.
1944 pub call_id: String,
1945 /// The name of the function to run.
1946 pub name: String,
1947 /// The unique ID of the function tool call.
1948 #[serde(skip_serializing_if = "Option::is_none")]
1949 pub id: Option<String>,
1950 /// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
1951 /// Populated when items are returned via API.
1952 #[serde(skip_serializing_if = "Option::is_none")]
1953 pub status: Option<OutputStatus>, // TODO rename OutputStatus?
1954}
1955
1956#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1957#[serde(rename_all = "snake_case")]
1958pub enum ImageGenToolCallStatus {
1959 InProgress,
1960 Completed,
1961 Generating,
1962 Failed,
1963}
1964
1965#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1966pub struct ImageGenToolCall {
1967 /// The unique ID of the image generation call.
1968 pub id: String,
1969 /// The generated image encoded in base64.
1970 pub result: Option<String>,
1971 /// The status of the image generation call.
1972 pub status: ImageGenToolCallStatus,
1973}
1974
1975#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1976#[serde(rename_all = "snake_case")]
1977pub enum CodeInterpreterToolCallStatus {
1978 InProgress,
1979 Completed,
1980 Incomplete,
1981 Interpreting,
1982 Failed,
1983}
1984
1985/// Output of a code interpreter request.
1986#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
1987pub struct CodeInterpreterToolCall {
1988 /// The code to run, or null if not available.
1989 #[serde(skip_serializing_if = "Option::is_none")]
1990 pub code: Option<String>,
1991 /// ID of the container used to run the code.
1992 pub container_id: String,
1993 /// The unique ID of the code interpreter tool call.
1994 pub id: String,
1995 /// The outputs generated by the code interpreter, such as logs or images.
1996 /// Can be null if no outputs are available.
1997 #[serde(skip_serializing_if = "Option::is_none")]
1998 pub outputs: Option<Vec<CodeInterpreterToolCallOutput>>,
1999 /// The status of the code interpreter tool call.
2000 /// Valid values are `in_progress`, `completed`, `incomplete`, `interpreting`, and `failed`.
2001 pub status: CodeInterpreterToolCallStatus,
2002}
2003
2004/// Individual result from a code interpreter: either logs or files.
2005#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2006#[serde(tag = "type", rename_all = "snake_case")]
2007pub enum CodeInterpreterToolCallOutput {
2008 /// Code interpreter output logs
2009 Logs(CodeInterpreterOutputLogs),
2010 /// Code interpreter output image
2011 Image(CodeInterpreterOutputImage),
2012}
2013
2014#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2015pub struct CodeInterpreterOutputLogs {
2016 /// The logs output from the code interpreter.
2017 pub logs: String,
2018}
2019
2020#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2021pub struct CodeInterpreterOutputImage {
2022 /// The URL of the image output from the code interpreter.
2023 pub url: String,
2024}
2025
2026#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2027pub struct CodeInterpreterFile {
2028 /// The ID of the file.
2029 file_id: String,
2030 /// The MIME type of the file.
2031 mime_type: String,
2032}
2033
2034#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2035pub struct LocalShellToolCall {
2036 /// Execute a shell command on the server.
2037 pub action: LocalShellExecAction,
2038 /// The unique ID of the local shell tool call generated by the model.
2039 pub call_id: String,
2040 /// The unique ID of the local shell call.
2041 pub id: String,
2042 /// The status of the local shell call.
2043 pub status: OutputStatus,
2044}
2045
2046/// Define the shape of a local shell action (exec).
2047#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2048pub struct LocalShellExecAction {
2049 /// The command to run.
2050 pub command: Vec<String>,
2051 /// Environment variables to set for the command.
2052 pub env: HashMap<String, String>,
2053 /// Optional timeout in milliseconds for the command.
2054 pub timeout_ms: Option<u64>,
2055 /// Optional user to run the command as.
2056 pub user: Option<String>,
2057 /// Optional working directory to run the command in.
2058 pub working_directory: Option<String>,
2059}
2060
2061/// Output of an MCP server tool invocation.
2062#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2063pub struct MCPToolCall {
2064 /// A JSON string of the arguments passed to the tool.
2065 pub arguments: String,
2066 /// The unique ID of the tool call.
2067 pub id: String,
2068 /// The name of the tool that was run.
2069 pub name: String,
2070 /// The label of the MCP server running the tool.
2071 pub server_label: String,
2072 /// Unique identifier for the MCP tool call approval request. Include this value
2073 /// in a subsequent `mcp_approval_response` input to approve or reject the corresponding
2074 /// tool call.
2075 pub approval_request_id: Option<String>,
2076 /// Error message from the call, if any.
2077 pub error: Option<String>,
2078 /// The output from the tool call.
2079 pub output: Option<String>,
2080 /// The status of the tool call. One of `in_progress`, `completed`, `incomplete`,
2081 /// `calling`, or `failed`.
2082 pub status: Option<MCPToolCallStatus>,
2083}
2084
2085#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2086#[serde(rename_all = "snake_case")]
2087pub enum MCPToolCallStatus {
2088 InProgress,
2089 Completed,
2090 Incomplete,
2091 Calling,
2092 Failed,
2093}
2094
2095#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2096pub struct MCPListTools {
2097 /// The unique ID of the list.
2098 pub id: String,
2099 /// The label of the MCP server.
2100 pub server_label: String,
2101 /// The tools available on the server.
2102 pub tools: Vec<MCPListToolsTool>,
2103 /// Error message if listing failed.
2104 #[serde(skip_serializing_if = "Option::is_none")]
2105 pub error: Option<String>,
2106}
2107
2108#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2109pub struct MCPApprovalRequest {
2110 /// JSON string of arguments for the tool.
2111 pub arguments: String,
2112 /// The unique ID of the approval request.
2113 pub id: String,
2114 /// The name of the tool to run.
2115 pub name: String,
2116 /// The label of the MCP server making the request.
2117 pub server_label: String,
2118}
2119
2120#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2121pub struct InputTokenDetails {
2122 /// The number of tokens that were retrieved from the cache.
2123 /// [More on prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
2124 pub cached_tokens: u32,
2125}
2126
2127#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2128pub struct OutputTokenDetails {
2129 /// The number of reasoning tokens.
2130 pub reasoning_tokens: u32,
2131}
2132
2133/// Usage statistics for a response.
2134#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2135pub struct ResponseUsage {
2136 /// The number of input tokens.
2137 pub input_tokens: u32,
2138 /// A detailed breakdown of the input tokens.
2139 pub input_tokens_details: InputTokenDetails,
2140 /// The number of output tokens.
2141 pub output_tokens: u32,
2142 /// A detailed breakdown of the output tokens.
2143 pub output_tokens_details: OutputTokenDetails,
2144 /// The total number of tokens used.
2145 pub total_tokens: u32,
2146}
2147
2148#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2149#[serde(untagged)]
2150pub enum Instructions {
2151 /// A text input to the model, equivalent to a text input with the `developer` role.
2152 Text(String),
2153 /// A list of one or many input items to the model, containing different content types.
2154 Array(Vec<InputItem>),
2155}
2156
2157/// The complete response returned by the Responses API.
2158#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2159pub struct Response {
2160 /// Whether to run the model response in the background.
2161 /// [Learn more](https://platform.openai.com/docs/guides/background).
2162 #[serde(skip_serializing_if = "Option::is_none")]
2163 pub background: Option<bool>,
2164
2165 /// Billing information for the response.
2166 #[serde(skip_serializing_if = "Option::is_none")]
2167 pub billing: Option<Billing>,
2168
2169 /// The conversation that this response belongs to. Input items and output
2170 /// items from this response are automatically added to this conversation.
2171 #[serde(skip_serializing_if = "Option::is_none")]
2172 pub conversation: Option<Conversation>,
2173
2174 /// Unix timestamp (in seconds) when this Response was created.
2175 pub created_at: u64,
2176
2177 /// An error object returned when the model fails to generate a Response.
2178 #[serde(skip_serializing_if = "Option::is_none")]
2179 pub error: Option<ErrorObject>,
2180
2181 /// Unique identifier for this response.
2182 pub id: String,
2183
2184 /// Details about why the response is incomplete, if any.
2185 #[serde(skip_serializing_if = "Option::is_none")]
2186 pub incomplete_details: Option<IncompleteDetails>,
2187
2188 /// A system (or developer) message inserted into the model's context.
2189 ///
2190 /// When using along with `previous_response_id`, the instructions from a previous response
2191 /// will not be carried over to the next response. This makes it simple to swap out
2192 /// system (or developer) messages in new responses.
2193 #[serde(skip_serializing_if = "Option::is_none")]
2194 pub instructions: Option<Instructions>,
2195
2196 /// An upper bound for the number of tokens that can be generated for a response,
2197 /// including visible output tokens and
2198 /// [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
2199 #[serde(skip_serializing_if = "Option::is_none")]
2200 pub max_output_tokens: Option<u32>,
2201
2202 /// Set of 16 key-value pairs that can be attached to an object. This can be
2203 /// useful for storing additional information about the object in a structured
2204 /// format, and querying for objects via API or the dashboard.
2205 ///
2206 /// Keys are strings with a maximum length of 64 characters. Values are strings
2207 /// with a maximum length of 512 characters.
2208 #[serde(skip_serializing_if = "Option::is_none")]
2209 pub metadata: Option<HashMap<String, String>>,
2210
2211 /// Model ID used to generate the response, like gpt-4o or o3. OpenAI offers a
2212 /// wide range of models with different capabilities, performance characteristics,
2213 /// and price points. Refer to the [model guide](https://platform.openai.com/docs/models) to browse and compare available models.
2214 pub model: String,
2215
2216 /// The object type of this resource - always set to `response`.
2217 pub object: String,
2218
2219 /// An array of content items generated by the model.
2220 ///
2221 /// - The length and order of items in the output array is dependent on the model's response.
2222 /// - Rather than accessing the first item in the output array and assuming it's an assistant
2223 /// message with the content generated by the model, you might consider using
2224 /// the `output_text` property where supported in SDKs.
2225 pub output: Vec<OutputItem>,
2226
2227 /// SDK-only convenience property that contains the aggregated text output from all
2228 /// `output_text` items in the `output` array, if any are present.
2229 /// Supported in the Python and JavaScript SDKs.
2230 // #[serde(skip_serializing_if = "Option::is_none")]
2231 // pub output_text: Option<String>,
2232
2233 /// Whether to allow the model to run tool calls in parallel.
2234 #[serde(skip_serializing_if = "Option::is_none")]
2235 pub parallel_tool_calls: Option<bool>,
2236
2237 /// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
2238 /// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
2239 /// Cannot be used in conjunction with `conversation`.
2240 #[serde(skip_serializing_if = "Option::is_none")]
2241 pub previous_response_id: Option<String>,
2242
2243 /// Reference to a prompt template and its variables.
2244 /// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
2245 #[serde(skip_serializing_if = "Option::is_none")]
2246 pub prompt: Option<Prompt>,
2247
2248 /// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
2249 /// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
2250 #[serde(skip_serializing_if = "Option::is_none")]
2251 pub prompt_cache_key: Option<String>,
2252
2253 /// **gpt-5 and o-series models only**
2254 /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
2255 #[serde(skip_serializing_if = "Option::is_none")]
2256 pub reasoning: Option<Reasoning>,
2257
2258 /// A stable identifier used to help detect users of your application that may be violating OpenAI's
2259 /// usage policies.
2260 ///
2261 /// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
2262 /// or email address, in order to avoid sending us any identifying information. [Learn
2263 /// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
2264 #[serde(skip_serializing_if = "Option::is_none")]
2265 pub safety_identifier: Option<String>,
2266
2267 /// Specifies the processing type used for serving the request.
2268 /// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
2269 /// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
2270 /// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
2271 /// - When not set, the default behavior is 'auto'.
2272 ///
2273 /// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
2274 #[serde(skip_serializing_if = "Option::is_none")]
2275 pub service_tier: Option<ServiceTier>,
2276
2277 /// The status of the response generation.
2278 /// One of `completed`, `failed`, `in_progress`, `cancelled`, `queued`, or `incomplete`.
2279 pub status: Status,
2280
2281 /// What sampling temperature was used, between 0 and 2. Higher values like 0.8 make
2282 /// outputs more random, lower values like 0.2 make output more focused and deterministic.
2283 ///
2284 /// We generally recommend altering this or `top_p` but not both.
2285 #[serde(skip_serializing_if = "Option::is_none")]
2286 pub temperature: Option<f32>,
2287
2288 /// Configuration options for a text response from the model. Can be plain
2289 /// text or structured JSON data. Learn more:
2290 /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
2291 /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
2292 #[serde(skip_serializing_if = "Option::is_none")]
2293 pub text: Option<ResponseTextParam>,
2294
2295 /// How the model should select which tool (or tools) to use when generating
2296 /// a response. See the `tools` parameter to see how to specify which tools
2297 /// the model can call.
2298 #[serde(skip_serializing_if = "Option::is_none")]
2299 pub tool_choice: Option<ToolChoiceParam>,
2300
2301 /// An array of tools the model may call while generating a response. You
2302 /// can specify which tool to use by setting the `tool_choice` parameter.
2303 ///
2304 /// We support the following categories of tools:
2305 /// - **Built-in tools**: Tools that are provided by OpenAI that extend the
2306 /// model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
2307 /// or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
2308 /// [built-in tools](https://platform.openai.com/docs/guides/tools).
2309 /// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
2310 /// or predefined connectors such as Google Drive and SharePoint. Learn more about
2311 /// [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
2312 /// - **Function calls (custom tools)**: Functions that are defined by you,
2313 /// enabling the model to call your own code with strongly typed arguments
2314 /// and outputs. Learn more about
2315 /// [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
2316 /// custom tools to call your own code.
2317 #[serde(skip_serializing_if = "Option::is_none")]
2318 pub tools: Option<Vec<Tool>>,
2319
2320 /// An integer between 0 and 20 specifying the number of most likely tokens to return at each
2321 /// token position, each with an associated log probability.
2322 #[serde(skip_serializing_if = "Option::is_none")]
2323 pub top_logprobs: Option<u8>,
2324
2325 /// An alternative to sampling with temperature, called nucleus sampling,
2326 /// where the model considers the results of the tokens with top_p probability
2327 /// mass. So 0.1 means only the tokens comprising the top 10% probability mass
2328 /// are considered.
2329 ///
2330 /// We generally recommend altering this or `temperature` but not both.
2331 #[serde(skip_serializing_if = "Option::is_none")]
2332 pub top_p: Option<f32>,
2333
2334 ///The truncation strategy to use for the model response.
2335 /// - `auto`: If the input to this Response exceeds
2336 /// the model's context window size, the model will truncate the
2337 /// response to fit the context window by dropping items from the beginning of the conversation.
2338 /// - `disabled` (default): If the input size will exceed the context window
2339 /// size for a model, the request will fail with a 400 error.
2340 #[serde(skip_serializing_if = "Option::is_none")]
2341 pub truncation: Option<Truncation>,
2342
2343 /// Represents token usage details including input tokens, output tokens,
2344 /// a breakdown of output tokens, and the total tokens used.
2345 #[serde(skip_serializing_if = "Option::is_none")]
2346 pub usage: Option<ResponseUsage>,
2347}
2348
2349#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2350#[serde(rename_all = "snake_case")]
2351pub enum Status {
2352 Completed,
2353 Failed,
2354 InProgress,
2355 Cancelled,
2356 Queued,
2357 Incomplete,
2358}
2359
2360/// Output item
2361#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2362#[serde(tag = "type")]
2363#[serde(rename_all = "snake_case")]
2364pub enum OutputItem {
2365 /// An output message from the model.
2366 Message(OutputMessage),
2367 /// The results of a file search tool call. See the
2368 /// [file search guide](https://platform.openai.com/docs/guides/tools-file-search)
2369 /// for more information.
2370 FileSearchCall(FileSearchToolCall),
2371 /// A tool call to run a function. See the
2372 /// [function calling guide](https://platform.openai.com/docs/guides/function-calling)
2373 /// for more information.
2374 FunctionCall(FunctionToolCall),
2375 /// The results of a web search tool call. See the
2376 /// [web search guide](https://platform.openai.com/docs/guides/tools-web-search)
2377 /// for more information.
2378 WebSearchCall(WebSearchToolCall),
2379 /// A tool call to a computer use tool. See the
2380 /// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use)
2381 /// for more information.
2382 ComputerCall(ComputerToolCall),
2383 /// A description of the chain of thought used by a reasoning model while generating
2384 /// a response. Be sure to include these items in your `input` to the Responses API for
2385 /// subsequent turns of a conversation if you are manually
2386 /// [managing context](https://platform.openai.com/docs/guides/conversation-state).
2387 Reasoning(ReasoningItem),
2388 /// An image generation request made by the model.
2389 ImageGenerationCall(ImageGenToolCall),
2390 /// A tool call to run code.
2391 CodeInterpreterCall(CodeInterpreterToolCall),
2392 /// A tool call to run a command on the local shell.
2393 LocalShellCall(LocalShellToolCall),
2394 /// An invocation of a tool on an MCP server.
2395 McpCall(MCPToolCall),
2396 /// A list of tools available on an MCP server.
2397 McpListTools(MCPListTools),
2398 /// A request for human approval of a tool invocation.
2399 McpApprovalRequest(MCPApprovalRequest),
2400 /// A call to a custom tool created by the model.
2401 CustomToolCall(CustomToolCall),
2402}
2403
2404#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2405#[non_exhaustive]
2406pub struct CustomToolCall {
2407 /// An identifier used to map this custom tool call to a tool call output.
2408 pub call_id: String,
2409 /// The input for the custom tool call generated by the model.
2410 pub input: String,
2411 /// The name of the custom tool being called.
2412 pub name: String,
2413 /// The unique ID of the custom tool call in the OpenAI platform.
2414 pub id: String,
2415}
2416
2417#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2418pub struct DeleteResponse {
2419 pub object: String,
2420 pub deleted: bool,
2421 pub id: String,
2422}
2423
2424#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2425pub struct AnyItemReference {
2426 pub r#type: Option<String>,
2427 pub id: String,
2428}
2429
2430#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2431#[serde(tag = "type", rename_all = "snake_case")]
2432pub enum ItemResourceItem {
2433 Message(MessageItem),
2434 FileSearchCall(FileSearchToolCall),
2435 ComputerCall(ComputerToolCall),
2436 ComputerCallOutput(ComputerCallOutputItemParam),
2437 WebSearchCall(WebSearchToolCall),
2438 FunctionCall(FunctionToolCall),
2439 FunctionCallOutput(FunctionCallOutputItemParam),
2440 ImageGenerationCall(ImageGenToolCall),
2441 CodeInterpreterCall(CodeInterpreterToolCall),
2442 LocalShellCall(LocalShellToolCall),
2443 LocalShellCallOutput(LocalShellToolCallOutput),
2444 McpListTools(MCPListTools),
2445 McpApprovalRequest(MCPApprovalRequest),
2446 McpApprovalResponse(MCPApprovalResponse),
2447 McpCall(MCPToolCall),
2448}
2449
2450#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2451#[serde(untagged)]
2452pub enum ItemResource {
2453 ItemReference(AnyItemReference),
2454 Item(ItemResourceItem),
2455}
2456
2457/// A list of Response items.
2458#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2459pub struct ResponseItemList {
2460 /// The type of object returned, must be `list`.
2461 pub object: String,
2462 /// The ID of the first item in the list.
2463 pub first_id: Option<String>,
2464 /// The ID of the last item in the list.
2465 pub last_id: Option<String>,
2466 /// Whether there are more items in the list.
2467 pub has_more: bool,
2468 /// The list of items.
2469 pub data: Vec<ItemResource>,
2470}
2471
2472#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
2473#[builder(
2474 name = "TokenCountsBodyArgs",
2475 pattern = "mutable",
2476 setter(into, strip_option),
2477 default
2478)]
2479#[builder(build_fn(error = "OpenAIError"))]
2480pub struct TokenCountsBody {
2481 /// The conversation that this response belongs to. Items from this
2482 /// conversation are prepended to `input_items` for this response request.
2483 /// Input items and output items from this response are automatically added to this
2484 /// conversation after this response completes.
2485 #[serde(skip_serializing_if = "Option::is_none")]
2486 pub conversation: Option<ConversationParam>,
2487
2488 /// Text, image, or file inputs to the model, used to generate a response
2489 #[serde(skip_serializing_if = "Option::is_none")]
2490 pub input: Option<InputParam>,
2491
2492 /// A system (or developer) message inserted into the model's context.
2493 ///
2494 /// When used along with `previous_response_id`, the instructions from a previous response will
2495 /// not be carried over to the next response. This makes it simple to swap out system (or
2496 /// developer) messages in new responses.
2497 #[serde(skip_serializing_if = "Option::is_none")]
2498 pub instructions: Option<String>,
2499
2500 /// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
2501 /// wide range of models with different capabilities, performance characteristics,
2502 /// and price points. Refer to the [model guide](https://platform.openai.com/docs/models)
2503 /// to browse and compare available models.
2504 #[serde(skip_serializing_if = "Option::is_none")]
2505 pub model: Option<String>,
2506
2507 /// Whether to allow the model to run tool calls in parallel.
2508 #[serde(skip_serializing_if = "Option::is_none")]
2509 pub parallel_tool_calls: Option<bool>,
2510
2511 /// The unique ID of the previous response to the model. Use this to create multi-turn
2512 /// conversations. Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
2513 /// Cannot be used in conjunction with `conversation`.
2514 #[serde(skip_serializing_if = "Option::is_none")]
2515 pub previous_response_id: Option<String>,
2516
2517 /// **gpt-5 and o-series models only**
2518 /// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
2519 #[serde(skip_serializing_if = "Option::is_none")]
2520 pub reasoning: Option<Reasoning>,
2521
2522 /// Configuration options for a text response from the model. Can be plain
2523 /// text or structured JSON data. Learn more:
2524 /// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
2525 /// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
2526 #[serde(skip_serializing_if = "Option::is_none")]
2527 pub text: Option<ResponseTextParam>,
2528
2529 /// How the model should select which tool (or tools) to use when generating
2530 /// a response. See the `tools` parameter to see how to specify which tools
2531 /// the model can call.
2532 #[serde(skip_serializing_if = "Option::is_none")]
2533 pub tool_choice: Option<ToolChoiceParam>,
2534
2535 /// An array of tools the model may call while generating a response. You can specify which tool
2536 /// to use by setting the `tool_choice` parameter.
2537 #[serde(skip_serializing_if = "Option::is_none")]
2538 pub tools: Option<Vec<Tool>>,
2539
2540 ///The truncation strategy to use for the model response.
2541 /// - `auto`: If the input to this Response exceeds
2542 /// the model's context window size, the model will truncate the
2543 /// response to fit the context window by dropping items from the beginning of the conversation.
2544 /// - `disabled` (default): If the input size will exceed the context window
2545 /// size for a model, the request will fail with a 400 error.
2546 #[serde(skip_serializing_if = "Option::is_none")]
2547 pub truncation: Option<Truncation>,
2548}
2549
2550#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2551pub struct TokenCountsResource {
2552 pub object: String,
2553 pub input_tokens: u32,
2554}