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