use crate::error::OpenAIError;
use crate::types::mcp::{MCPListToolsTool, MCPTool};
use crate::types::responses::{
CustomGrammarFormatParam, Filter, ImageDetail, ImageGenInputUsageDetails,
ImageGenOutputTokensDetails, MessagePhase, MessageRole, MisalignmentErrorDetailsResource,
ModerationParam, ModerationResultBody, PromptCacheBreakpointTTLEnum, PromptCacheModeEnum,
PromptCacheOptionsParam, PromptCacheTTLEnum, ReasoningEffort, ResponseFormatJsonSchema,
ResponseUsage, SummaryTextContent,
};
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Whether tool search was executed by the server or by the client.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ToolSearchExecutionType {
Server,
Client,
}
/// The type of content to search for.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum SearchContentType {
Text,
Image,
}
/// The status of a function call.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum FunctionCallStatus {
InProgress,
Completed,
Incomplete,
}
/// The status of a function call output.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum FunctionCallOutputStatusEnum {
InProgress,
Completed,
Incomplete,
}
/// Groups function/custom tools under a shared namespace.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Builder, Default)]
#[builder(
name = "NamespaceToolParamArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct NamespaceToolParam {
/// The namespace name used in tool calls (for example, `crm`).
pub name: String,
/// A description of the namespace shown to the model.
pub description: String,
/// The function/custom tools available inside this namespace.
pub tools: Vec<NamespaceToolParamTool>,
}
/// A function or custom tool that belongs to a namespace.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum NamespaceToolParamTool {
Function(FunctionToolParam),
Custom(CustomToolParam),
}
/// A function tool that can be used within a namespace or with tool search.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "FunctionToolParamArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct FunctionToolParam {
/// The name of the function.
pub name: String,
/// A description of the function.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// A JSON schema object describing the parameters of the function.
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<serde_json::Value>,
/// Whether to enforce strict parameter validation.
#[serde(skip_serializing_if = "Option::is_none")]
pub strict: Option<bool>,
/// Whether this function should be deferred and discovered via tool search.
#[serde(skip_serializing_if = "Option::is_none")]
pub defer_loading: Option<bool>,
/// Whether the tool response can be returned asynchronously versus immediately returned on next
/// response creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub output_schema: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
/// Hosted or BYOT tool search configuration for deferred tools.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "ToolSearchToolParamArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct ToolSearchToolParam {
/// Whether tool search is executed by the server or by the client.
#[serde(skip_serializing_if = "Option::is_none")]
pub execution: Option<ToolSearchExecutionType>,
/// Description shown to the model for a client-executed tool search tool.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Parameter schema for a client-executed tool search tool.
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<serde_json::Value>,
}
/// A tool search call output item.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ToolSearchCall {
/// The unique ID of the tool search call item.
pub id: String,
/// The unique ID of the tool search call generated by the model.
pub call_id: Option<String>,
/// Whether tool search was executed by the server or by the client.
pub execution: ToolSearchExecutionType,
/// Arguments used for the tool search call.
pub arguments: serde_json::Value,
/// The status of the tool search call item.
pub status: FunctionCallStatus,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
/// A tool search call input item.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ToolSearchCallItemParam {
/// The unique ID of this tool search call.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the tool search call generated by the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub call_id: Option<String>,
/// Whether tool search was executed by the server or by the client.
#[serde(skip_serializing_if = "Option::is_none")]
pub execution: Option<ToolSearchExecutionType>,
/// The arguments supplied to the tool search call.
#[serde(default)]
pub arguments: serde_json::Value,
/// The status of the tool search call.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
}
/// A tool search output item.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ToolSearchOutput {
/// The unique ID of the tool search output item.
pub id: String,
/// The unique ID of the tool search call generated by the model.
pub call_id: Option<String>,
/// Whether tool search was executed by the server or by the client.
pub execution: ToolSearchExecutionType,
/// The loaded tool definitions returned by tool search.
pub tools: Vec<Tool>,
/// The status of the tool search output item.
pub status: FunctionCallOutputStatusEnum,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
/// A tool search output input item.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ToolSearchOutputItemParam {
/// The unique ID of this tool search output.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the tool search call generated by the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub call_id: Option<String>,
/// Whether tool search was executed by the server or by the client.
#[serde(skip_serializing_if = "Option::is_none")]
pub execution: Option<ToolSearchExecutionType>,
/// The loaded tool definitions returned by the tool search output.
pub tools: Vec<ToolSearchOutputTool>,
/// The status of the tool search output.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
}
/// Role of messages in the API.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum Role {
#[default]
User,
Assistant,
System,
Developer,
}
/// Status of input/output items.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum OutputStatus {
InProgress,
Completed,
Incomplete,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum InputParam {
/// A text input to the model, equivalent to a text input with the
/// `user` role.
Text(String),
/// A list of one or many input items to the model, containing
/// different content types.
Items(Vec<InputItem>),
}
/// Content item used to generate a response.
///
/// This is a properly discriminated union based on the `type` field, using Rust's
/// type-safe enum with serde's tag attribute for efficient deserialization.
///
/// # OpenAPI Specification
/// Corresponds to the `Item` schema in the OpenAPI spec with a `type` discriminator.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Item {
/// A message (type: "message").
/// Can represent InputMessage (user/system/developer) or OutputMessage (assistant).
///
/// InputMessage:
/// A message input to the model with a role indicating instruction following hierarchy.
/// Instructions given with the developer or system role take precedence over instructions given with the user role.
/// OutputMessage:
/// A message output from the model.
Message(MessageItem),
/// The results of a file search tool call. See the
/// [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
FileSearchCall(FileSearchToolCall),
/// A tool call to a computer use tool. See the
/// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
ComputerCall(ComputerToolCall),
/// The output of a computer tool call.
ComputerCallOutput(ComputerCallOutputItemParam),
/// The results of a web search tool call. See the
/// [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
WebSearchCall(WebSearchToolCall),
/// A tool call to run a function. See the
///
/// [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
FunctionCall(FunctionToolCall),
/// The output of a function tool call.
FunctionCallOutput(FunctionCallOutputItemParam),
/// A tool search call.
ToolSearchCall(ToolSearchCallItemParam),
/// A tool search output.
ToolSearchOutput(ToolSearchOutputItemParam),
AdditionalTools(AdditionalToolsItemParam),
/// An update to the conversation's response configuration. The configuration
/// remains in effect for subsequent responses until it is replaced by another
/// configuration update.
ConfigurationUpdate(ResponseConfigurationUpdateItemParam),
/// A description of the chain of thought used by a reasoning model while generating
/// a response. Be sure to include these items in your `input` to the Responses API
/// for subsequent turns of a conversation if you are manually
/// [managing context](https://platform.openai.com/docs/guides/conversation-state).
Reasoning(ReasoningItem),
/// A compaction item generated by the [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).
Compaction(CompactionSummaryItemParam),
/// An image generation request made by the model.
ImageGenerationCall(ImageGenToolCall),
/// A tool call to run code.
CodeInterpreterCall(CodeInterpreterToolCall),
/// A tool call to run a command on the local shell.
LocalShellCall(LocalShellToolCall),
/// The output of a local shell tool call.
LocalShellCallOutput(LocalShellToolCallOutput),
/// A tool representing a request to execute one or more shell commands.
ShellCall(FunctionShellCallItemParam),
/// The streamed output items emitted by a shell tool call.
ShellCallOutput(FunctionShellCallOutputItemParam),
/// A tool call representing a request to create, delete, or update files using diff patches.
ApplyPatchCall(ApplyPatchToolCallItemParam),
/// The streamed output emitted by an apply patch tool call.
ApplyPatchCallOutput(ApplyPatchToolCallOutputItemParam),
/// A list of tools available on an MCP server.
McpListTools(MCPListTools),
/// A request for human approval of a tool invocation.
McpApprovalRequest(MCPApprovalRequest),
/// A response to an MCP approval request.
McpApprovalResponse(MCPApprovalResponse),
/// An invocation of a tool on an MCP server.
McpCall(MCPToolCall),
/// The output of a custom tool call from your code, being sent back to the model.
CustomToolCallOutput(CustomToolCallOutput),
/// A call to a custom tool created by the model.
CustomToolCall(CustomToolCall),
}
/// Input item that can be used in the context for generating a response.
///
/// This represents the OpenAPI `InputItem` schema which is a `oneOf`:
/// 1. `EasyInputMessage` - Simple, user-friendly message input (can use string content)
/// 2. `Item` - Structured items with proper type discrimination (including InputMessage, OutputMessage, tool calls)
/// 3. `ItemReferenceParam` - Reference to an existing item by ID (type can be null)
/// 4. `CompactionTriggerItemParam` - An explicit compaction trigger
/// 5. `ProgramItemParam` - A program replay item
/// 6. `ProgramOutputItemParam` - A program output replay item
///
/// Program and compaction-trigger items use the `type` discriminator directly.
/// References, structured items, and easy messages retain untagged alternatives
/// because their shapes overlap and some allow an omitted or null `type`.
///
/// # OpenAPI Specification
/// Corresponds to the `InputItem` schema, including the alternatives outside `Item`.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type")]
pub enum InputItem {
/// An explicit compaction trigger.
#[serde(rename = "compaction_trigger")]
CompactionTrigger(CompactionTriggerItemParam),
/// A program item echoed back for replay.
#[serde(rename = "program")]
Program(ProgramItemParam),
/// A program output echoed back for replay.
#[serde(rename = "program_output")]
ProgramOutput(ProgramOutputItemParam),
/// A reference to an existing item by ID.
/// Has a required `id` field and optional `type` (can be "item_reference" or null).
/// Tried first among the untagged alternatives as it's the most minimal structure.
#[serde(untagged)]
ItemReference(ItemReference),
/// All structured items with proper type discrimination.
/// Includes InputMessage, OutputMessage, and all tool calls/outputs.
/// Uses the discriminated `Item` enum for efficient, type-safe deserialization.
#[serde(untagged)]
Item(Item),
/// A simple, user-friendly message input (EasyInputMessage).
/// Supports string content and can include assistant role for previous responses.
/// Must be tried last as it's the most flexible structure.
///
/// A message input to the model with a role indicating instruction following
/// hierarchy. Instructions given with the `developer` or `system` role take
/// precedence over instructions given with the `user` role. Messages with the
/// `assistant` role are presumed to have been generated by the model in previous
/// interactions.
#[serde(untagged)]
EasyMessage(EasyInputMessage),
}
/// A message item used within the `Item` enum.
///
/// Both InputMessage and OutputMessage have `type: "message"`, so we use an untagged
/// enum to distinguish them based on their structure:
/// - OutputMessage: role=assistant, required id & status fields
/// - InputMessage: role=user/system/developer, content is `Vec<ContentType>`, optional id/status
///
/// Note: EasyInputMessage is NOT included here - it's a separate variant in `InputItem`,
/// not part of the structured `Item` enum.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum MessageItem {
/// An output message from the model (role: assistant, has required id & status).
/// This must come first as it has the most specific structure (required id and status fields).
Output(OutputMessage),
/// A structured input message (role: user/system/developer, content is `Vec<ContentType>`).
/// Has structured content list and optional id/status fields.
///
/// A message input to the model with a role indicating instruction following hierarchy.
/// Instructions given with the `developer` or `system` role take precedence over instructions
/// given with the `user` role.
Input(InputMessage),
}
/// A reference to an existing item by ID.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ItemReference {
/// The type of item to reference. Can be "item_reference" or null.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<ItemReferenceType>,
/// The ID of the item to reference.
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ItemReferenceType {
ItemReference,
}
/// Output from a function call that you're providing back to the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionCallOutputItemParam {
/// The unique ID of the function tool call generated by the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub call_id: Option<String>,
/// Text, image, or file output of the function tool call.
pub output: FunctionCallOutput,
/// The unique ID of the function tool call output.
/// Populated when this item is returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when items are returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
/// The name of the tool that produced the output.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// The namespace of the tool that produced the output.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
/// The execution context that produced this tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum FunctionCallOutput {
/// A JSON string of the output of the function tool call.
Text(String),
Content(Vec<InputContent>), // TODO use shape which allows null from OpenAPI spec?
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ComputerCallOutputItemParam {
/// The ID of the computer tool call that produced the output.
pub call_id: String,
/// A computer screenshot image used with the computer use tool.
pub output: ComputerScreenshotImage,
/// The safety checks reported by the API that have been acknowledged by the developer.
#[serde(skip_serializing_if = "Option::is_none")]
pub acknowledged_safety_checks: Option<Vec<ComputerCallSafetyCheckParam>>,
/// The unique ID of the computer tool call output. Optional when creating.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The status of the message input. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when input items are returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>, // TODO rename OutputStatus?
}
/// The status of a computer tool call output item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ComputerCallOutputStatus {
InProgress,
Completed,
Incomplete,
Failed,
}
/// A computer tool call output item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ComputerToolCallOutputResource {
/// The ID of the computer tool call that produced the output.
pub call_id: String,
/// A computer screenshot image used with the computer use tool.
pub output: ComputerScreenshotImage,
/// The safety checks reported by the API that have been acknowledged by the developer.
#[serde(skip_serializing_if = "Option::is_none")]
pub acknowledged_safety_checks: Option<Vec<ComputerCallSafetyCheckParam>>,
/// The ID of the computer tool call output.
pub id: String,
/// The status of the item returned by the API.
pub status: ComputerCallOutputStatus,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ComputerScreenshotImageType {
ComputerScreenshot,
}
/// A computer screenshot image used with the computer use tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ComputerScreenshotImage {
/// Specifies the event type. For a computer screenshot, this property is always
/// set to `computer_screenshot`.
pub r#type: ComputerScreenshotImageType,
/// The identifier of an uploaded file that contains the screenshot.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_id: Option<String>,
/// The URL of the screenshot image.
#[serde(skip_serializing_if = "Option::is_none")]
pub image_url: Option<String>,
}
/// Output from a local shell tool call that you're providing back to the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LocalShellToolCallOutput {
/// The unique ID of the local shell tool call generated by the model.
pub id: String,
/// A JSON string of the output of the local shell tool call.
pub output: String,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
}
/// Output from a local shell command execution.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LocalShellOutput {
/// The stdout output from the command.
#[serde(skip_serializing_if = "Option::is_none")]
pub stdout: Option<String>,
/// The stderr output from the command.
#[serde(skip_serializing_if = "Option::is_none")]
pub stderr: Option<String>,
/// The exit code of the command.
#[serde(skip_serializing_if = "Option::is_none")]
pub exit_code: Option<i32>,
}
/// An MCP approval response that you're providing back to the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct MCPApprovalResponse {
/// The ID of the approval request being answered.
pub approval_request_id: String,
/// Whether the request was approved.
pub approve: bool,
/// The unique ID of the approval response
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// Optional reason for the decision.
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum CustomToolCallOutputOutput {
/// A string of the output of the custom tool call.
Text(String),
/// Text, image, or file output of the custom tool call.
List(Vec<InputContent>),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct CustomToolCallOutput {
/// The call ID, used to map this custom tool call output to a custom tool call.
pub call_id: String,
/// The output from the custom tool call generated by your code.
/// Can be a string or an list of output content.
pub output: CustomToolCallOutputOutput,
/// The unique ID of the custom tool call output in the OpenAI platform.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// A custom tool call output item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct CustomToolCallOutputResource {
/// The call ID, used to map this custom tool call output to a custom tool call.
pub call_id: String,
/// The output from the custom tool call generated by your code.
/// Can be a string or a list of output content.
pub output: CustomToolCallOutputOutput,
/// The unique ID of the custom tool call output item.
pub id: String,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionCallOutputStatusEnum,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// A simplified message input to the model (EasyInputMessage in the OpenAPI spec).
///
/// This is the most user-friendly way to provide messages, supporting both simple
/// string content and structured content. Role can include `assistant` for providing
/// previous assistant responses.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "EasyInputMessageArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct EasyInputMessage {
/// The type of the message input. Defaults to `message` when omitted in JSON input.
#[serde(default)]
pub r#type: MessageType,
/// The role of the message input. One of `user`, `assistant`, `system`, or `developer`.
pub role: Role,
/// Text, image, or audio input to the model, used to generate a response.
/// Can also contain previous assistant responses.
pub content: EasyInputContent,
/// Labels an `assistant` message as intermediate commentary (`commentary`) or
/// the final answer (`final_answer`). Not used for user messages.
#[serde(skip_serializing_if = "Option::is_none")]
pub phase: Option<MessagePhase>,
}
/// A structured message input to the model (InputMessage in the OpenAPI spec).
///
/// This variant requires structured content (not a simple string) and does not support
/// the `assistant` role (use OutputMessage for that). status is populated when items are returned via API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "InputMessageArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct InputMessage {
/// A list of one or many input items to the model, containing different content types.
pub content: Vec<InputContent>,
/// The role of the message input. One of `user`, `system`, or `developer`.
/// Note: `assistant` is NOT allowed here; use OutputMessage instead.
pub role: InputRole,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when items are returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
/////The type of the message input. Always set to `message`.
//pub r#type: MessageType,
}
/// The role for an input message - can only be `user`, `system`, or `developer`.
/// This type ensures type safety by excluding the `assistant` role (use OutputMessage for that).
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum InputRole {
#[default]
User,
System,
Developer,
}
/// Content for EasyInputMessage - can be a simple string or structured list.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum EasyInputContent {
/// A text input to the model.
Text(String),
/// A list of one or many input items to the model, containing different content types.
ContentList(Vec<InputContent>),
}
/// Parts of a message: text, image, file, or audio.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputContent {
/// A text input to the model.
InputText(InputTextContent),
/// An image input to the model. Learn about
/// [image inputs](https://platform.openai.com/docs/guides/vision).
InputImage(InputImageContent),
/// A file input to the model.
InputFile(InputFileContent),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct InputTextContent {
/// The text input to the model.
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_breakpoint: Option<PromptCacheBreakpointConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "InputImageArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct InputImageContent {
/// The detail level of the image to be sent to the model. One of `high`, `low`, or `auto`.
/// Defaults to `auto` when omitted in JSON input.
#[serde(default)]
pub detail: ImageDetail,
/// The ID of the file to be sent to the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_id: Option<String>,
/// The URL of the image to be sent to the model. A fully qualified URL or base64 encoded image
/// in a data URL.
#[serde(skip_serializing_if = "Option::is_none")]
pub image_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_breakpoint: Option<PromptCacheBreakpointConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "InputFileArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct InputFileContent {
/// The content of the file to be sent to the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_data: Option<String>,
/// The ID of the file to be sent to the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_id: Option<String>,
/// The URL of the file to be sent to the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_url: Option<String>,
/// The name of the file to be sent to the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,
/// The detail level of the file to be sent to the model. Use `auto` to let the system select the detail
/// level; for GPT-5.6 and later models, `auto` uses high-quality rendering, which may increase input
/// token usage. Use `low` for lower-cost rendering, or `high` to render the file at higher quality.
/// Defaults to `auto`.
#[serde(skip_serializing_if = "Option::is_none")]
pub detail: Option<FileInputDetail>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_breakpoint: Option<PromptCacheBreakpointConfig>,
}
/// The conversation that this response belonged to. Input items and output items from this
/// response were automatically added to this conversation.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Conversation {
/// The unique ID of the conversation that this response was associated with.
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum ConversationParam {
/// The unique ID of the conversation.
ConversationID(String),
/// The conversation that this response belongs to.
Object(Conversation),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum IncludeEnum {
#[serde(rename = "file_search_call.results")]
FileSearchCallResults,
#[serde(rename = "web_search_call.results")]
WebSearchCallResults,
#[serde(rename = "web_search_call.action.sources")]
WebSearchCallActionSources,
#[serde(rename = "message.input_image.image_url")]
MessageInputImageImageUrl,
#[serde(rename = "computer_call_output.output.image_url")]
ComputerCallOutputOutputImageUrl,
#[serde(rename = "code_interpreter_call.outputs")]
CodeInterpreterCallOutputs,
#[serde(rename = "reasoning.encrypted_content")]
ReasoningEncryptedContent,
#[serde(rename = "message.output_text.logprobs")]
MessageOutputTextLogprobs,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ResponseStreamOptions {
/// When true, stream obfuscation will be enabled. Stream obfuscation adds
/// random characters to an `obfuscation` field on streaming delta events to
/// normalize payload sizes as a mitigation to certain side-channel attacks.
/// These obfuscation fields are included by default, but add a small amount
/// of overhead to the data stream. You can set `include_obfuscation` to
/// false to optimize for bandwidth if you trust the network links between
/// your application and the OpenAI API.
#[serde(skip_serializing_if = "Option::is_none")]
pub include_obfuscation: Option<bool>,
}
/// Builder for a Responses API request.
#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
#[builder(
name = "CreateResponseArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CreateResponse {
/// Whether to run the model response in the background.
/// [Learn more](https://platform.openai.com/docs/guides/background).
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<bool>,
/// The conversation that this response belongs to. Items from this conversation are prepended to
/// `input_items` for this response request.
///
/// Input items and output items from this response are automatically added to this conversation after
/// this response completes.
#[serde(skip_serializing_if = "Option::is_none")]
pub conversation: Option<ConversationParam>,
/// Specify additional output data to include in the model response. Currently supported
/// values are:
///
/// - `web_search_call.action.sources`: Include the sources of the web search tool call.
///
/// - `code_interpreter_call.outputs`: Includes the outputs of python code execution in code
/// interpreter tool call items.
///
/// - `computer_call_output.output.image_url`: Include image urls from the computer call
/// output.
///
/// - `file_search_call.results`: Include the search results of the file search tool call.
///
/// - `message.input_image.image_url`: Include image urls from the input message.
///
/// - `message.output_text.logprobs`: Include logprobs with assistant messages.
///
/// - `reasoning.encrypted_content`: Includes an encrypted version of reasoning tokens in
/// reasoning item outputs. This enables reasoning items to be used in multi-turn
/// conversations when using the Responses API statelessly (like when the `store` parameter is
/// set to `false`, or when an organization is enrolled in the zero data retention program).
#[serde(skip_serializing_if = "Option::is_none")]
pub include: Option<Vec<IncludeEnum>>,
/// Text, image, or file inputs to the model, used to generate a response.
///
/// Learn more:
/// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
/// - [Image inputs](https://platform.openai.com/docs/guides/images)
/// - [File inputs](https://platform.openai.com/docs/guides/pdf-files)
/// - [Conversation state](https://platform.openai.com/docs/guides/conversation-state)
/// - [Function calling](https://platform.openai.com/docs/guides/function-calling)
pub input: InputParam,
/// A system (or developer) message inserted into the model's context.
///
/// When using along with `previous_response_id`, the instructions from a previous
/// response will not be carried over to the next response. This makes it simple
/// to swap out system (or developer) messages in new responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
/// An upper bound for the number of tokens that can be generated for a response, including
/// visible output tokens and [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
#[serde(skip_serializing_if = "Option::is_none")]
pub max_output_tokens: Option<u32>,
/// The maximum number of total calls to built-in tools that can be processed in a response. This
/// maximum number applies across all built-in tool calls, not per individual tool. Any further
/// attempts to call a tool by the model will be ignored.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tool_calls: Option<u32>,
/// Set of 16 key-value pairs that can be attached to an object. This can be
/// useful for storing additional information about the object in a structured
/// format, and querying for objects via API or the dashboard.
///
/// Keys are strings with a maximum length of 64 characters. Values are
/// strings with a maximum length of 512 characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, String>>,
/// Model ID used to generate the response, like `gpt-6-astra`. OpenAI
/// offers a wide range of models with different capabilities, performance
/// characteristics, and price points. Refer to the [model guide](/docs/models)
/// to browse and compare available models.
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// Whether to allow the model to run tool calls in parallel.
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
/// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
/// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
/// Cannot be used in conjunction with `conversation`.
#[serde(skip_serializing_if = "Option::is_none")]
pub previous_response_id: Option<String>,
/// Reference to a prompt template and its variables.
/// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<Prompt>,
/// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
/// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_key: Option<String>,
/// The retention policy for the prompt cache. Set to `24h` to enable extended prompt caching,
/// which keeps cached prefixes active for longer, up to a maximum of 24 hours. [Learn
/// more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Use prompt_cache_options instead.")]
pub prompt_cache_retention: Option<PromptCacheRetention>,
/// **gpt-5 and o-series models only**
/// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<Reasoning>,
/// A stable identifier used to help detect users of your application that may be violating OpenAI's
/// usage policies.
///
/// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
/// or email address, in order to avoid sending us any identifying information. [Learn
/// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
#[serde(skip_serializing_if = "Option::is_none")]
pub safety_identifier: Option<String>,
/// Specifies the processing type used for serving the request.
/// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
/// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
/// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
/// - When not set, the default behavior is 'auto'.
///
/// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<ServiceTierResponses>,
/// Whether to store the generated model response for later retrieval via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub store: Option<bool>,
/// If set to true, the model response data will be streamed to the client
/// 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).
/// See the [Streaming section below](https://platform.openai.com/docs/api-reference/responses-streaming)
/// for more information.
#[serde(skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
/// Options for streaming responses. Only set this when you set `stream: true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub stream_options: Option<ResponseStreamOptions>,
/// What sampling temperature to use, between 0 and 2. Higher values like 0.8
/// will make the output more random, while lower values like 0.2 will make it
/// more focused and deterministic. We generally recommend altering this or
/// `top_p` but not both.
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
/// Configuration options for a text response from the model. Can be plain
/// text or structured JSON data. Learn more:
/// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
/// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseTextParam>,
/// How the model should select which tool (or tools) to use when generating
/// a response. See the `tools` parameter to see how to specify which tools
/// the model can call.
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<ToolChoiceParam>,
/// An array of tools the model may call while generating a response. You
/// can specify which tool to use by setting the `tool_choice` parameter.
///
/// We support the following categories of tools:
/// - **Built-in tools**: Tools that are provided by OpenAI that extend the
/// model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
/// or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
/// [built-in tools](https://platform.openai.com/docs/guides/tools).
/// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
/// or predefined connectors such as Google Drive and SharePoint. Learn more about
/// [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
/// - **Function calls (custom tools)**: Functions that are defined by you,
/// enabling the model to call your own code with strongly typed arguments
/// and outputs. Learn more about
/// [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
/// custom tools to call your own code.
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<Tool>>,
/// An integer between 0 and 20 specifying the number of most likely tokens to return at each
/// token position, each with an associated log probability. In some cases, the number of returned
/// tokens may be fewer than requested.
#[serde(skip_serializing_if = "Option::is_none")]
pub top_logprobs: Option<u8>,
/// An alternative to sampling with temperature, called nucleus sampling,
/// where the model considers the results of the tokens with top_p probability
/// mass. So 0.1 means only the tokens comprising the top 10% probability mass
/// are considered.
///
/// We generally recommend altering this or `temperature` but not both.
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f32>,
///The truncation strategy to use for the model response.
/// - `auto`: If the input to this Response exceeds
/// the model's context window size, the model will truncate the
/// response to fit the context window by dropping items from the beginning of the conversation.
/// - `disabled` (default): If the input size will exceed the context window
/// size for a model, the request will fail with a 400 error.
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Deprecated by the API; use context_management for compaction.")]
pub truncation: Option<Truncation>,
/// Context management configuration for this request.
#[serde(skip_serializing_if = "Option::is_none")]
pub context_management: Option<Vec<ContextManagementParam>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_options: Option<ResponsePromptCacheOptionsParam>,
#[serde(skip_serializing_if = "Option::is_none")]
pub moderation: Option<ModerationParam>,
/// Domain-specific access programs to use for this request.
#[serde(skip_serializing_if = "Option::is_none")]
pub access_programs: Option<AccessProgramsParam>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum ResponsePromptVariables {
String(String),
Content(InputContent),
Custom(serde_json::Value),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Prompt {
/// The unique identifier of the prompt template to use.
pub id: String,
/// Optional version of the prompt template.
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
/// Optional map of values to substitute in for variables in your
/// prompt. The substitution values can either be strings, or other
/// Response input types like images or files.
#[serde(skip_serializing_if = "Option::is_none")]
pub variables: Option<ResponsePromptVariables>,
}
/// Truncation strategies.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Truncation {
Auto,
Disabled,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Billing {
pub payer: String,
}
/// o-series reasoning settings.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "ReasoningArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct Reasoning {
/// Constrains effort on reasoning for
/// [reasoning models](https://platform.openai.com/docs/guides/reasoning).
/// Currently supported values are `minimal`, `low`, `medium`, and `high`. Reducing
/// reasoning effort can result in faster responses and fewer tokens used
/// on reasoning in a response.
///
/// Note: The `gpt-5-pro` model defaults to (and only supports) `high` reasoning effort.
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<ReasoningEffort>,
/// A summary of the reasoning performed by the model. This can be
/// useful for debugging and understanding the model's reasoning process.
/// One of `auto`, `concise`, or `detailed`.
///
/// `concise` is supported for `computer-use-preview` models and all reasoning models after
/// `gpt-5`.
#[serde(skip_serializing_if = "Option::is_none")]
pub summary: Option<ReasoningSummary>,
/// Controls the reasoning execution mode for the request.
///
/// When returned on a response, this is the effective execution mode.
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<ReasoningModeEnum>,
/// Controls which reasoning items are rendered back to the model on later turns.
///
/// If omitted or set to `auto`, the model determines the context mode. The
/// `gpt-5.6` model family defaults to `all_turns`; earlier models default to `current_turn`.
///
/// When returned on a response, this is the effective reasoning context mode used for the response.
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<ReasoningContext>,
}
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ReasoningContext {
Auto,
CurrentTurn,
AllTurns,
}
/// o-series reasoning settings.
#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Verbosity {
Low,
Medium,
High,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ReasoningSummary {
Auto,
Concise,
Detailed,
}
/// The retention policy for the prompt cache.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum PromptCacheRetention {
#[serde(rename = "in_memory")]
InMemory,
#[serde(rename = "24h")]
Hours24,
}
/// The detail level of a file input sent to the model.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum FileInputDetail {
Low,
High,
Auto,
}
/// Configuration for text response format.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ResponseTextParam {
/// An object specifying the format that the model must output.
///
/// Configuring `{ "type": "json_schema" }` enables Structured Outputs,
/// which ensures the model will match your supplied JSON schema. Learn more in the
/// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
///
/// The default format is `{ "type": "text" }` with no additional options.
///
/// **Not recommended for gpt-4o and newer models:**
///
/// Setting to `{ "type": "json_object" }` enables the older JSON mode, which
/// ensures the message the model generates is valid JSON. Using `json_schema`
/// is preferred for models that support it.
#[serde(default)]
pub format: TextResponseFormatConfiguration,
/// Constrains the verbosity of the model's response. Lower values will result in
/// more concise responses, while higher values will result in more verbose responses.
///
/// Currently supported values are `low`, `medium`, and `high`.
#[serde(skip_serializing_if = "Option::is_none")]
pub verbosity: Option<Verbosity>,
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TextResponseFormatConfiguration {
/// Default response format. Used to generate text responses.
#[default]
Text,
/// JSON object response format. An older method of generating JSON responses.
/// Using `json_schema` is recommended for models that support it.
/// Note that the model will not generate JSON without a system or user message
/// instructing it to do so.
JsonObject,
/// JSON Schema response format. Used to generate structured JSON responses.
/// Learn more about [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
JsonSchema(ResponseFormatJsonSchema),
}
/// Definitions for model-callable tools.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Tool {
/// Defines a function in your own code the model can choose to call. Learn more about [function
/// calling](https://platform.openai.com/docs/guides/tools).
Function(FunctionTool),
/// A tool that searches for relevant content from uploaded files. Learn more about the [file search
/// tool](https://platform.openai.com/docs/guides/tools-file-search).
FileSearch(FileSearchTool),
/// A tool that controls a virtual computer. Learn more about the [computer
/// use tool](https://platform.openai.com/docs/guides/tools-computer-use).
ComputerUsePreview(ComputerUsePreviewTool),
/// Search the Internet for sources related to the prompt. Learn more about the
/// [web search tool](https://platform.openai.com/docs/guides/tools-web-search).
WebSearch(WebSearchTool),
/// type: web_search_2025_08_26
#[serde(rename = "web_search_2025_08_26")]
WebSearch20250826(WebSearchTool),
/// Give the model access to additional tools via remote Model Context Protocol
/// (MCP) servers. [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).
Mcp(MCPTool),
/// A tool that runs Python code to help generate a response to a prompt.
CodeInterpreter(CodeInterpreterTool),
ProgrammaticToolCalling,
/// A tool that generates images using a model like `gpt-image-1`.
ImageGeneration(ImageGenTool),
/// A tool that allows the model to execute shell commands in a local environment.
LocalShell,
/// A tool that allows the model to execute shell commands.
Shell(FunctionShellToolParam),
/// A custom tool that processes input using a specified format. Learn more about [custom
/// tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
Custom(CustomToolParam),
/// A tool that controls a virtual computer. Learn more about the
/// [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).
Computer,
/// Groups function/custom tools under a shared namespace.
Namespace(NamespaceToolParam),
/// Hosted or BYOT tool search configuration for deferred tools.
ToolSearch(ToolSearchToolParam),
/// This tool searches the web for relevant results to use in a response. Learn more about the [web search
///tool](https://platform.openai.com/docs/guides/tools-web-search).
WebSearchPreview(WebSearchTool),
/// type: web_search_preview_2025_03_11
#[serde(rename = "web_search_preview_2025_03_11")]
WebSearchPreview20250311(WebSearchTool),
/// Allows the assistant to create, delete, or update files using unified diffs.
ApplyPatch(ApplyPatchToolParam),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
pub struct CustomToolParam {
/// The name of the custom tool, used to identify it in tool calls.
pub name: String,
/// Optional description of the custom tool, used to provide more context.
pub description: Option<String>,
/// The input format for the custom tool. Default is unconstrained text.
pub format: CustomToolParamFormat,
/// Whether this tool should be deferred and discovered via tool search.
#[serde(skip_serializing_if = "Option::is_none")]
pub defer_loading: Option<bool>,
/// Whether the tool response can be returned asynchronously versus immediately returned on next
/// response creation.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum CustomToolParamFormat {
/// Unconstrained free-form text.
#[default]
Text,
/// A grammar defined by the user.
Grammar(CustomGrammarFormatParam),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "FileSearchToolArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct FileSearchTool {
/// The IDs of the vector stores to search.
pub vector_store_ids: Vec<String>,
/// The maximum number of results to return. This number should be between 1 and 50 inclusive.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_num_results: Option<u32>,
/// A filter to apply.
#[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<Filter>,
/// Ranking options for search.
#[serde(skip_serializing_if = "Option::is_none")]
pub ranking_options: Option<RankingOptions>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "FunctionToolArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
pub struct FunctionTool {
/// The name of the function to call.
pub name: String,
/// A JSON schema object describing the parameters of the function.
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<serde_json::Value>,
/// Whether to enforce strict parameter validation. Default `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub strict: Option<bool>,
/// A description of the function. Used by the model to determine whether or not to call the
/// function.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Whether this function is deferred and loaded via tool search.
#[serde(skip_serializing_if = "Option::is_none")]
pub defer_loading: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub output_schema: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct WebSearchToolFilters {
/// Allowed domains for the search. If not provided, all domains are allowed.
/// Subdomains of the provided domains are allowed as well.
///
/// Example: `["pubmed.ncbi.nlm.nih.gov"]`
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_domains: Option<Vec<String>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "WebSearchToolArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
pub struct WebSearchTool {
/// Filters for the search.
#[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<WebSearchToolFilters>,
/// The approximate location of the user. If omitted or null, defaults to the
/// United States. To avoid this fallback, pass `{"type": "approximate"}` without
/// location fields. To localize results, provide the relevant location fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub user_location: Option<WebSearchApproximateLocation>,
/// High level guidance for the amount of context window space to use for the search. One of `low`,
/// `medium`, or `high`. `medium` is the default.
#[serde(skip_serializing_if = "Option::is_none")]
pub search_context_size: Option<WebSearchToolSearchContextSize>,
/// The types of content to search for.
#[serde(skip_serializing_if = "Option::is_none")]
pub search_content_types: Option<Vec<SearchContentType>>,
/// Allow live internet access for web search. Defaults to true when omitted. When false, the web search
/// tool runs in offline/cache-only mode and will not fetch new external content.
#[serde(skip_serializing_if = "Option::is_none")]
pub external_web_access: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum WebSearchToolSearchContextSize {
Low,
#[default]
Medium,
High,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ComputerEnvironment {
Windows,
Mac,
Linux,
Ubuntu,
#[default]
Browser,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "ComputerUsePreviewToolArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
pub struct ComputerUsePreviewTool {
/// The type of computer environment to control.
environment: ComputerEnvironment,
/// The width of the computer display.
display_width: u32,
/// The height of the computer display.
display_height: u32,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum RankVersionType {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "default-2024-11-15")]
Default20241115,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct HybridSearch {
/// The weight of the embedding in the reciprocal ranking fusion.
pub embedding_weight: f32,
/// The weight of the text in the reciprocal ranking fusion.
pub text_weight: f32,
}
/// Options for search result ranking.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct RankingOptions {
/// Weights that control how reciprocal rank fusion balances semantic embedding matches versus
/// sparse keyword matches when hybrid search is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub hybrid_search: Option<HybridSearch>,
/// The ranker to use for the file search.
pub ranker: RankVersionType,
/// The score threshold for the file search, a number between 0 and 1. Numbers closer to 1 will
/// attempt to return only the most relevant results, but may return fewer results.
#[serde(skip_serializing_if = "Option::is_none")]
pub score_threshold: Option<f32>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum WebSearchApproximateLocationType {
#[default]
Approximate,
}
/// Approximate user location for web search.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "WebSearchApproximateLocationArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct WebSearchApproximateLocation {
/// The type of location approximation. Defaults to `approximate` when omitted in JSON input.
#[serde(default)]
pub r#type: WebSearchApproximateLocationType,
/// Free text input for the city of the user, e.g. `San Francisco`.
#[serde(skip_serializing_if = "Option::is_none")]
pub city: Option<String>,
/// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user,
/// e.g. `US`.
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
/// Free text input for the region of the user, e.g. `California`.
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
/// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the user, e.g.
/// `America/Los_Angeles`.
#[serde(skip_serializing_if = "Option::is_none")]
pub timezone: Option<String>,
}
/// Container configuration for a code interpreter.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum CodeInterpreterToolContainer {
/// Configuration for a code interpreter container. Optionally specify the IDs of the
/// files to run the code on.
Auto(CodeInterpreterContainerAuto),
/// The container ID.
#[serde(untagged)]
ContainerID(String),
}
/// Auto configuration for code interpreter container.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CodeInterpreterContainerAuto {
/// An optional list of uploaded files to make available to your code.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_ids: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_limit: Option<u64>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "CodeInterpreterToolArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CodeInterpreterTool {
/// The code interpreter container. Can be a container ID or an object that
/// specifies uploaded file IDs to make available to your code, along with an
/// optional `memory_limit` setting.
pub container: CodeInterpreterToolContainer,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ImageGenToolInputImageMask {
/// Base64-encoded mask image.
#[serde(skip_serializing_if = "Option::is_none")]
pub image_url: Option<String>,
/// File ID for the mask image.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum InputFidelity {
#[default]
High,
Low,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenToolModeration {
#[default]
Auto,
Low,
}
/// Whether to generate a new image or edit an existing image.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenActionEnum {
/// Generate a new image.
Generate,
/// Edit an existing image.
Edit,
/// Automatically determine whether to generate or edit.
#[default]
Auto,
}
/// Image generation tool definition.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default, Builder)]
#[builder(
name = "ImageGenerationArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct ImageGenTool {
/// Set the background of the generated image. One of `transparent`,
/// `opaque`, or `auto`. Transparent backgrounds are available for
/// supported GPT Image models. For `gpt-image-2` and
/// `gpt-image-2-2026-04-21`, this support is in preview. When using
/// `transparent`, set the output format to `png` or `webp`. Default: `auto`.
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<ImageGenToolBackground>,
/// Control how much effort the model will exert to match the style and features, especially facial features,
/// of input images. This parameter is only supported for `gpt-image-1`. Unsupported
/// for `gpt-image-1-mini`. Supports `high` and `low`. Defaults to `low`.
#[serde(skip_serializing_if = "Option::is_none")]
pub input_fidelity: Option<InputFidelity>,
/// Optional mask for inpainting. Contains `image_url`
/// (string, optional) and `file_id` (string, optional).
#[serde(skip_serializing_if = "Option::is_none")]
pub input_image_mask: Option<ImageGenToolInputImageMask>,
/// The image generation model to use. Default: `gpt-image-1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// Moderation level for the generated image. Default: `auto`.
#[serde(skip_serializing_if = "Option::is_none")]
pub moderation: Option<ImageGenToolModeration>,
/// Compression level for the output image. Default: 100.
#[serde(skip_serializing_if = "Option::is_none")]
pub output_compression: Option<u8>,
/// The output format of the generated image. One of `png`, `webp`, or
/// `jpeg`. Default: `png`.
#[serde(skip_serializing_if = "Option::is_none")]
pub output_format: Option<ImageGenToolOutputFormat>,
/// Number of partial images to generate in streaming mode, from 0 (default value) to 3.
#[serde(skip_serializing_if = "Option::is_none")]
pub partial_images: Option<u8>,
/// The quality of the generated image. One of `low`, `medium`, `high`,
/// `xhigh`, `max`, or `auto`. Default: `auto`.
#[serde(skip_serializing_if = "Option::is_none")]
pub quality: Option<ImageGenToolQuality>,
/// The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`,
/// `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and
/// `gpt-image-2.5-flare-2026-09-08`, arbitrary resolutions are supported as `WIDTHxHEIGHT` strings, for
/// example `1536x864`. Width and height must both be divisible by 16 and the requested aspect ratio
/// must be between 1:3 and 3:1. Resolutions above `2560x1440` are experimental, and the maximum
/// supported resolution is `3840x2160`. The requested size must also satisfy the model's current pixel
/// and edge limits. The standard sizes `1024x1024`, `1536x1024`, and `1024x1536` are supported by the
/// GPT image models; `auto` is supported for models that allow automatic sizing.
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<ImageGenToolSize>,
/// Whether to generate a new image or edit an existing image. Default: `auto`.
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<ImageGenActionEnum>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenToolBackground {
Transparent,
Opaque,
#[default]
Auto,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenToolOutputFormat {
#[default]
Png,
Webp,
Jpeg,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenToolQuality {
Low,
Medium,
High,
XHigh,
Max,
#[default]
Auto,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ImageGenToolSize {
#[default]
Auto,
#[serde(rename = "1024x1024")]
Size1024x1024,
#[serde(rename = "1024x1536")]
Size1024x1536,
#[serde(rename = "1536x1024")]
Size1536x1024,
#[serde(untagged)]
Other(String),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ToolChoiceAllowedMode {
Auto,
Required,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ToolChoiceAllowed {
/// Constrains the tools available to the model to a pre-defined set.
///
/// `auto` allows the model to pick from among the allowed tools and generate a
/// message.
///
/// `required` requires the model to call one or more of the allowed tools.
pub mode: ToolChoiceAllowedMode,
/// A list of tool definitions that the model should be allowed to call.
///
/// For the Responses API, the list of tool definitions might look like:
/// ```json
/// [
/// { "type": "function", "name": "get_weather" },
/// { "type": "mcp", "server_label": "deepwiki" },
/// { "type": "image_generation" }
/// ]
/// ```
pub tools: Vec<serde_json::Value>,
}
/// The type of hosted tool the model should to use. Learn more about
/// [built-in tools](https://platform.openai.com/docs/guides/tools).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ToolChoiceTypes {
FileSearch,
WebSearchPreview,
Computer,
ComputerUsePreview,
ComputerUse,
#[serde(rename = "web_search_preview_2025_03_11")]
WebSearchPreview20250311,
CodeInterpreter,
ImageGeneration,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ToolChoiceFunction {
/// The name of the function to call.
pub name: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ToolChoiceMCP {
/// The name of the tool to call on the server.
pub name: String,
/// The label of the MCP server to use.
pub server_label: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ToolChoiceCustom {
/// The name of the custom tool to call.
pub name: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ToolChoiceParam {
/// Constrains the tools available to the model to a pre-defined set.
AllowedTools(ToolChoiceAllowed),
/// Use this option to force the model to call a specific function.
Function(ToolChoiceFunction),
/// Use this option to force the model to call a specific tool on a remote MCP server.
Mcp(ToolChoiceMCP),
/// Use this option to force the model to call a custom tool.
Custom(ToolChoiceCustom),
ProgrammaticToolCalling,
/// Forces the model to call the apply_patch tool when executing a tool call.
ApplyPatch,
/// Forces the model to call the function shell tool when a tool call is required.
Shell,
/// Indicates that the model should use a built-in tool to generate a response.
/// [Learn more about built-in tools](https://platform.openai.com/docs/guides/tools).
#[serde(untagged)]
BuiltIn(ToolChoiceTypes),
/// Controls which (if any) tool is called by the model.
///
/// `none` means the model will not call any tool and instead generates a message.
///
/// `auto` means the model can pick between generating a message or calling one or
/// more tools.
///
/// `required` means the model must call one or more tools.
#[serde(untagged)]
Option(ToolChoiceOptions),
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ToolChoiceOptions {
None,
Auto,
Required,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ResponseErrorCode {
ServerError,
RateLimitExceeded,
InvalidPrompt,
DataResidencyMismatch,
BioPolicy,
MisalignmentPolicyViolation,
VectorStoreTimeout,
InvalidImage,
InvalidImageFormat,
InvalidBase64Image,
InvalidImageUrl,
ImageTooLarge,
ImageTooSmall,
ImageParseError,
ImageContentPolicyViolation,
InvalidImageMode,
ImageFileTooLarge,
UnsupportedImageMediaType,
EmptyImageFile,
FailedToDownloadImage,
ImageFileNotFound,
#[serde(untagged)]
Other(String),
}
/// An error that occurred while generating the response.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ResponseError {
/// A machine-readable error code that was returned.
pub code: ResponseErrorCode,
/// A human-readable description of the error that was returned.
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub misalignment: Option<MisalignmentErrorDetailsResource>,
/// The related request parameter.
#[serde(skip_serializing_if = "Option::is_none")]
pub param: Option<String>,
/// The error type.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<String>,
}
/// Details about an incomplete response.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct IncompleteDetails {
/// The reason why the response is incomplete.
pub reason: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct TopLogProb {
pub bytes: Vec<u8>,
pub logprob: f64,
pub token: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LogProb {
pub bytes: Vec<u8>,
pub logprob: f64,
pub token: String,
pub top_logprobs: Vec<TopLogProb>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ResponseTopLobProb {
/// The log probability of this token.
pub logprob: f64,
/// A possible text token.
pub token: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ResponseLogProb {
/// The log probability of this token.
pub logprob: f64,
/// A possible text token.
pub token: String,
/// The log probability of the top 20 most likely tokens.
pub top_logprobs: Vec<ResponseTopLobProb>,
}
/// A simple text output from the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct OutputTextContent {
/// The annotations of the text output.
pub annotations: Vec<Annotation>,
pub logprobs: Option<Vec<LogProb>>,
/// The text output from the model.
pub text: String,
}
/// An annotation that applies to a span of output text.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Annotation {
/// A citation to a file.
FileCitation(FileCitationBody),
/// A citation for a web resource used to generate a model response.
UrlCitation(UrlCitationBody),
/// A citation for a container file used to generate a model response.
ContainerFileCitation(ContainerFileCitationBody),
/// A path to a file.
FilePath(FilePath),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FileCitationBody {
/// The ID of the file.
file_id: String,
/// The filename of the file cited.
filename: String,
/// The index of the file in the list of files.
index: u32,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct UrlCitationBody {
/// The index of the last character of the URL citation in the message.
end_index: u32,
/// The index of the first character of the URL citation in the message.
start_index: u32,
/// The title of the web resource.
title: String,
/// The URL of the web resource.
url: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerFileCitationBody {
/// The ID of the container file.
container_id: String,
/// The index of the last character of the container file citation in the message.
end_index: u32,
/// The ID of the file.
file_id: String,
/// The filename of the container file cited.
filename: String,
/// The index of the first character of the container file citation in the message.
start_index: u32,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FilePath {
/// The ID of the file.
file_id: String,
/// The index of the file in the list of files.
index: u32,
}
/// A refusal explanation from the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct RefusalContent {
/// The refusal explanation from the model.
pub refusal: String,
}
/// A message generated by the model.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct OutputMessage {
/// The content of the output message.
pub content: Vec<OutputMessageContent>,
/// The unique ID of the output message.
pub id: String,
/// The role of the output message. Always `assistant`.
pub role: AssistantRole,
/// Labels this assistant message as intermediate commentary (`commentary`) or
/// the final answer (`final_answer`).
#[serde(skip_serializing_if = "Option::is_none")]
pub phase: Option<MessagePhase>,
/// The status of the message input. One of `in_progress`, `completed`, or
/// `incomplete`. Populated when input items are returned via API.
pub status: OutputStatus,
///// The type of the output message. Always `message`.
//pub r#type: MessageType,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum MessageType {
#[default]
Message,
}
/// The role for an output message - always `assistant`.
/// This type ensures type safety by only allowing the assistant role.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum AssistantRole {
#[default]
Assistant,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputMessageContent {
/// A text output from the model.
OutputText(OutputTextContent),
/// A refusal from the model.
Refusal(RefusalContent),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputContent {
/// A text output from the model.
OutputText(OutputTextContent),
/// A refusal from the model.
Refusal(RefusalContent),
/// Reasoning text from the model.
ReasoningText(ReasoningTextContent),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ReasoningTextContent {
/// The reasoning text from the model.
pub text: String,
}
/// [ReasoningTextContent] used elsewhere which adds type,
/// but here in [ReasoningItem] content field we need type too hence an enum:
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ReasoningItemContent {
ReasoningText(ReasoningTextContent),
}
/// A reasoning item representing the model's chain of thought, including summary paragraphs.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ReasoningItem {
/// Unique identifier of the reasoning content.
pub id: Option<String>,
/// Reasoning summary content.
pub summary: Vec<SummaryPart>,
/// Reasoning text content.
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<Vec<ReasoningItemContent>>,
/// The encrypted content of the reasoning item - populated when a response is generated with
/// `reasoning.encrypted_content` in the `include` parameter.
#[serde(skip_serializing_if = "Option::is_none")]
pub encrypted_content: Option<String>,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when items are returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum SummaryPart {
SummaryText(SummaryTextContent),
}
/// File search tool call output.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FileSearchToolCall {
/// The unique ID of the file search tool call.
pub id: String,
/// The queries used to search for files.
pub queries: Vec<String>,
/// The status of the file search tool call. One of `in_progress`, `searching`,
/// `incomplete`,`failed`, or `completed`.
pub status: FileSearchToolCallStatus,
/// The results of the file search tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub results: Option<Vec<FileSearchToolCallResult>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FileSearchToolCallStatus {
InProgress,
Searching,
Incomplete,
Failed,
Completed,
}
/// A single result from a file search.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FileSearchToolCallResult {
/// Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
/// additional information about the object in a structured format, and querying for objects
/// API or the dashboard. Keys are strings with a maximum length of 64 characters
/// . Values are strings with a maximum length of 512 characters, booleans, or numbers.
pub attributes: HashMap<String, serde_json::Value>,
/// The unique ID of the file.
pub file_id: String,
/// The name of the file.
pub filename: String,
/// The relevance score of the file - a value between 0 and 1.
pub score: f32,
/// The text that was retrieved from the file.
pub text: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ComputerCallSafetyCheckParam {
/// The ID of the pending safety check.
pub id: String,
/// The type of the pending safety check.
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
/// Details about the pending safety check.
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum WebSearchCallStatus {
InProgress,
Searching,
Completed,
Failed,
Incomplete,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct WebSearchActionSearchSource {
/// The type of source. Always `url`.
pub r#type: String,
/// The URL of the source.
pub url: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct WebSearchActionSearch {
/// The search query.
#[deprecated(note = "Use queries instead.")]
#[serde(skip_serializing_if = "Option::is_none")]
pub query: Option<String>,
/// Search queries
pub queries: Option<Vec<String>>,
/// The sources used in the search.
pub sources: Option<Vec<WebSearchActionSearchSource>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct WebSearchActionOpenPage {
/// The URL opened by the model.
pub url: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct WebSearchActionFind {
/// The URL of the page searched for the pattern, when available.
pub url: Option<String>,
/// The pattern or text to search for within the page.
pub pattern: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum WebSearchToolCallAction {
/// Action type "search" - Performs a web search query.
Search(WebSearchActionSearch),
/// Action type "open_page" - Opens a specific URL from search results.
OpenPage(WebSearchActionOpenPage),
/// Action type "find": Searches for a pattern within a loaded page.
Find(WebSearchActionFind),
/// Action type "find_in_page": <https://platform.openai.com/docs/guides/tools-web-search#output-and-citations>
FindInPage(WebSearchActionFind),
}
/// Web search tool call output.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebSearchToolCall {
/// An object describing the specific action taken in this web search call. Includes
/// details on how the model used the web (search, open_page, find, find_in_page).
///
/// This is optional because `response.output_item.added` events can include
/// in-progress web search calls before OpenAI has populated the action.
/// See <https://github.com/64bit/async-openai/issues/548>.
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<WebSearchToolCallAction>,
/// The unique ID of the web search tool call.
pub id: String,
/// The status of the web search tool call.
pub status: WebSearchCallStatus,
}
/// Output from a computer tool call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ComputerToolCall {
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<ComputerAction>,
/// Flattened batched actions for `computer_use`. Each action includes a
/// `type` discriminator and action-specific fields.
#[serde(skip_serializing_if = "Option::is_none")]
pub actions: Option<Vec<ComputerAction>>,
/// An identifier used when responding to the tool call with output.
pub call_id: String,
/// The unique ID of the computer call.
pub id: String,
/// The pending safety checks for the computer call.
pub pending_safety_checks: Vec<ComputerCallSafetyCheckParam>,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when items are returned via API.
pub status: OutputStatus,
}
/// An x/y coordinate pair.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct CoordParam {
/// The x-coordinate.
pub x: i32,
/// The y-coordinate.
pub y: i32,
}
/// Represents all user‐triggered actions.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ComputerAction {
/// A click action.
Click(ClickParam),
/// A double click action.
DoubleClick(DoubleClickAction),
/// A drag action.
Drag(DragParam),
/// A collection of keypresses the model would like to perform.
Keypress(KeyPressAction),
/// A mouse move action.
Move(MoveParam),
/// A screenshot action.
Screenshot,
/// A scroll action.
Scroll(ScrollParam),
/// An action to type in text.
Type(TypeParam),
/// A wait action.
Wait,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ClickButtonType {
Left,
Right,
Wheel,
Back,
Forward,
}
/// A click action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ClickParam {
/// Indicates which mouse button was pressed during the click. One of `left`,
/// `right`, `wheel`, `back`, or `forward`.
pub button: ClickButtonType,
/// The x-coordinate where the click occurred.
pub x: i32,
/// The y-coordinate where the click occurred.
pub y: i32,
/// The keys being held while clicking.
#[serde(skip_serializing_if = "Option::is_none")]
pub keys: Option<Vec<String>>,
}
/// A double click action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct DoubleClickAction {
/// The x-coordinate where the double click occurred.
pub x: i32,
/// The y-coordinate where the double click occurred.
pub y: i32,
/// The keys being held while double clicking.
pub keys: Option<Vec<String>>,
}
/// A drag action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct DragParam {
/// An array of coordinates representing the path of the drag action.
pub path: Vec<CoordParam>,
/// The keys being held while dragging the mouse.
#[serde(skip_serializing_if = "Option::is_none")]
pub keys: Option<Vec<String>>,
}
/// A keypress action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct KeyPressAction {
/// The combination of keys the model is requesting to be pressed.
/// This is an array of strings, each representing a key.
pub keys: Vec<String>,
}
/// A mouse move action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct MoveParam {
/// The x-coordinate to move to.
pub x: i32,
/// The y-coordinate to move to.
pub y: i32,
/// The keys being held while moving the mouse.
#[serde(skip_serializing_if = "Option::is_none")]
pub keys: Option<Vec<String>>,
}
/// A scroll action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ScrollParam {
/// The horizontal scroll distance.
pub scroll_x: i32,
/// The vertical scroll distance.
pub scroll_y: i32,
/// The x-coordinate where the scroll occurred.
pub x: i32,
/// The y-coordinate where the scroll occurred.
pub y: i32,
/// The keys being held while scrolling.
#[serde(skip_serializing_if = "Option::is_none")]
pub keys: Option<Vec<String>>,
}
/// A typing (text entry) action.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct TypeParam {
/// The text to type.
pub text: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionToolCall {
/// A JSON string of the arguments to pass to the function.
pub arguments: String,
/// The unique ID of the function tool call generated by the model.
pub call_id: String,
/// The namespace of the function to run.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
/// The name of the function to run.
pub name: String,
/// The unique ID of the function tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
/// Populated when items are returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<OutputStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
/// Whether the function tool call runs asynchronously.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
}
/// A function tool call item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionToolCallResource {
/// A JSON string of the arguments to pass to the function.
pub arguments: String,
/// The unique ID of the function tool call generated by the model.
pub call_id: String,
/// The namespace of the function to run.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
/// The name of the function to run.
pub name: String,
/// The unique ID of the function tool call.
pub id: String,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionCallStatus,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
/// Whether the function tool call runs asynchronously.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
}
/// A function tool call output item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionToolCallOutputResource {
/// The unique ID of the function tool call generated by the model.
#[serde(skip_serializing_if = "Option::is_none")]
pub call_id: Option<String>,
/// Text, image, or file output of the function tool call.
pub output: FunctionCallOutput,
/// The unique ID of the function tool call output.
pub id: String,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionCallOutputStatusEnum,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
/// The name of the tool that produced the output.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// The namespace of the tool that produced the output.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ImageGenToolCallStatus {
InProgress,
Completed,
Generating,
Failed,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ImageGenToolCall {
/// The unique ID of the image generation call.
pub id: String,
/// The generated image encoded in base64.
pub result: Option<String>,
/// The status of the image generation call.
pub status: ImageGenToolCallStatus,
/// The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<ImageGenToolSize>,
/// The quality of the image generated by the image generation tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub quality: Option<ImageGenToolQuality>,
/// The background used for the generated image.
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<ImageGenToolBackground>,
/// The output format.
#[serde(skip_serializing_if = "Option::is_none")]
pub output_format: Option<ImageGenToolOutputFormat>,
/// The action performed.
#[serde(skip_serializing_if = "Option::is_none")]
pub action: Option<ImageGenActionEnum>,
/// The revised prompt.
#[serde(skip_serializing_if = "Option::is_none")]
pub revised_prompt: Option<String>,
/// Details of a moderation failure, when available.
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<ImageGenToolCallError>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CodeInterpreterToolCallStatus {
InProgress,
Completed,
Incomplete,
Interpreting,
Failed,
}
/// Output of a code interpreter request.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct CodeInterpreterToolCall {
/// The code to run, or null if not available.
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
/// ID of the container used to run the code.
pub container_id: String,
/// The unique ID of the code interpreter tool call.
pub id: String,
/// The outputs generated by the code interpreter, such as logs or images.
/// Can be null if no outputs are available.
#[serde(skip_serializing_if = "Option::is_none")]
pub outputs: Option<Vec<CodeInterpreterToolCallOutput>>,
/// The status of the code interpreter tool call.
/// Valid values are `in_progress`, `completed`, `incomplete`, `interpreting`, and `failed`.
pub status: CodeInterpreterToolCallStatus,
}
/// Individual result from a code interpreter: either logs or files.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum CodeInterpreterToolCallOutput {
/// Code interpreter output logs
Logs(CodeInterpreterOutputLogs),
/// Code interpreter output image
Image(CodeInterpreterOutputImage),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CodeInterpreterOutputLogs {
/// The logs output from the code interpreter.
pub logs: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CodeInterpreterOutputImage {
/// The URL of the image output from the code interpreter.
pub url: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CodeInterpreterFile {
/// The ID of the file.
file_id: String,
/// The MIME type of the file.
mime_type: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct LocalShellToolCall {
/// Execute a shell command on the server.
pub action: LocalShellExecAction,
/// The unique ID of the local shell tool call generated by the model.
pub call_id: String,
/// The unique ID of the local shell call.
pub id: String,
/// The status of the local shell call.
pub status: OutputStatus,
}
/// Define the shape of a local shell action (exec).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LocalShellExecAction {
/// The command to run.
pub command: Vec<String>,
/// Environment variables to set for the command.
pub env: HashMap<String, String>,
/// Optional timeout in milliseconds for the command.
pub timeout_ms: Option<u64>,
/// Optional user to run the command as.
pub user: Option<String>,
/// Optional working directory to run the command in.
pub working_directory: Option<String>,
}
/// Commands and limits describing how to run the shell tool call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellActionParam {
/// Ordered shell commands for the execution environment to run.
pub commands: Vec<String>,
/// Maximum wall-clock time in milliseconds to allow the shell commands to run.
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout_ms: Option<u64>,
/// Maximum number of UTF-8 characters to capture from combined stdout and stderr output.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_output_length: Option<u64>,
}
/// Status values reported for shell tool calls.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FunctionShellCallItemStatus {
InProgress,
Completed,
Incomplete,
}
/// The environment for a shell call item (request side).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum FunctionShellCallItemEnvironment {
/// Use a local computer environment.
Local(LocalEnvironmentParam),
/// Reference an existing container by ID.
ContainerReference(ContainerReferenceParam),
}
/// A tool representing a request to execute one or more shell commands.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellCallItemParam {
/// The unique ID of the shell tool call. Populated when this item is returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the shell tool call generated by the model.
pub call_id: String,
/// The shell commands and limits that describe how to run the tool call.
pub action: FunctionShellActionParam,
/// The status of the shell call. One of `in_progress`, `completed`, or `incomplete`.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<FunctionShellCallItemStatus>,
/// The environment to execute the shell commands in.
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<FunctionShellCallItemEnvironment>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Indicates that the shell commands finished and returned an exit code.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellCallOutputExitOutcomeParam {
/// The exit code returned by the shell process.
pub exit_code: i32,
}
/// The exit or timeout outcome associated with this chunk.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum FunctionShellCallOutputOutcomeParam {
Timeout,
Exit(FunctionShellCallOutputExitOutcomeParam),
}
/// Captured stdout and stderr for a portion of a shell tool call output.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionShellCallOutputContentParam {
/// Captured stdout output for this chunk of the shell call.
pub stdout: String,
/// Captured stderr output for this chunk of the shell call.
pub stderr: String,
/// The exit or timeout outcome associated with this chunk.
pub outcome: FunctionShellCallOutputOutcomeParam,
}
/// The streamed output items emitted by a shell tool call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellCallOutputItemParam {
/// The unique ID of the shell tool call output. Populated when this item is returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the shell tool call generated by the model.
pub call_id: String,
/// Captured chunks of stdout and stderr output, along with their associated outcomes.
pub output: Vec<FunctionShellCallOutputContentParam>,
/// The maximum number of UTF-8 characters captured for this shell call's combined output.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_output_length: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<FunctionShellCallItemStatus>,
}
/// Status values reported for apply_patch tool calls.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ApplyPatchCallStatusParam {
InProgress,
Completed,
}
/// Instruction for creating a new file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchCreateFileOperationParam {
/// Path of the file to create relative to the workspace root.
pub path: String,
/// Unified diff content to apply when creating the file.
pub diff: String,
}
/// Instruction for deleting an existing file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchDeleteFileOperationParam {
/// Path of the file to delete relative to the workspace root.
pub path: String,
}
/// Instruction for updating an existing file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchUpdateFileOperationParam {
/// Path of the file to update relative to the workspace root.
pub path: String,
/// Unified diff content to apply to the existing file.
pub diff: String,
}
/// One of the create_file, delete_file, or update_file operations supplied to the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ApplyPatchOperationParam {
CreateFile(ApplyPatchCreateFileOperationParam),
DeleteFile(ApplyPatchDeleteFileOperationParam),
UpdateFile(ApplyPatchUpdateFileOperationParam),
}
/// A tool call representing a request to create, delete, or update files using diff patches.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ApplyPatchToolCallItemParam {
/// The unique ID of the apply patch tool call. Populated when this item is returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the apply patch tool call generated by the model.
pub call_id: String,
/// The status of the apply patch tool call. One of `in_progress` or `completed`.
pub status: ApplyPatchCallStatusParam,
/// The specific create, delete, or update instruction for the apply_patch tool call.
pub operation: ApplyPatchOperationParam,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Outcome values reported for apply_patch tool call outputs.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ApplyPatchCallOutputStatusParam {
Completed,
Failed,
}
/// The streamed output emitted by an apply patch tool call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ApplyPatchToolCallOutputItemParam {
/// The unique ID of the apply patch tool call output. Populated when this item is returned via API.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The unique ID of the apply patch tool call generated by the model.
pub call_id: String,
/// The status of the apply patch tool call output. One of `completed` or `failed`.
pub status: ApplyPatchCallOutputStatusParam,
/// Optional human-readable log text from the apply patch tool (e.g., patch results or errors).
#[serde(skip_serializing_if = "Option::is_none")]
pub output: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Shell exec action
/// Execute a shell command.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellAction {
/// A list of commands to run.
pub commands: Vec<String>,
/// Optional timeout in milliseconds for the commands.
pub timeout_ms: Option<u64>,
/// Optional maximum number of characters to return from each command.
pub max_output_length: Option<u64>,
}
/// Status values reported for function shell tool calls.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FunctionShellCallStatus {
InProgress,
Completed,
Incomplete,
}
/// Status values reported for function shell tool call outputs.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum FunctionShellCallOutputStatusEnum {
InProgress,
Completed,
Incomplete,
}
/// The environment for a shell call (response side).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum FunctionShellCallEnvironment {
/// A local computer environment.
Local,
/// A referenced container.
ContainerReference(ContainerReferenceResource),
}
/// A tool call that executes one or more shell commands in a managed environment.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionShellCall {
/// The unique ID of the function shell tool call. Populated when this item is returned via API.
pub id: String,
/// The unique ID of the function shell tool call generated by the model.
pub call_id: String,
/// The shell commands and limits that describe how to run the tool call.
pub action: FunctionShellAction,
/// The status of the shell call. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionShellCallStatus,
/// The environment in which the shell commands were executed.
pub environment: Option<FunctionShellCallEnvironment>,
/// The ID of the entity that created this tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// The content of a shell tool call output that was emitted.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionShellCallOutputContent {
/// The standard output that was captured.
pub stdout: String,
/// The standard error output that was captured.
pub stderr: String,
/// Represents either an exit outcome (with an exit code) or a timeout outcome for a shell call output chunk.
#[serde(flatten)]
pub outcome: FunctionShellCallOutputOutcome,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
/// Function shell call outcome
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum FunctionShellCallOutputOutcome {
Timeout,
Exit(FunctionShellCallOutputExitOutcome),
}
/// Indicates that the shell commands finished and returned an exit code.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellCallOutputExitOutcome {
/// Exit code from the shell process.
pub exit_code: i32,
}
/// The output of a shell tool call that was emitted.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct FunctionShellCallOutput {
/// The unique ID of the shell call output. Populated when this item is returned via API.
pub id: String,
/// The unique ID of the shell tool call generated by the model.
pub call_id: String,
/// The status of the shell call output. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionShellCallOutputStatusEnum,
/// An array of shell call output contents
pub output: Vec<FunctionShellCallOutputContent>,
/// The maximum length of the shell command output. This is generated by the model and should be
/// passed back with the raw output.
pub max_output_length: Option<u64>,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Status values reported for apply_patch tool calls.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ApplyPatchCallStatus {
InProgress,
Completed,
}
/// Instruction describing how to create a file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchCreateFileOperation {
/// Path of the file to create.
pub path: String,
/// Diff to apply.
pub diff: String,
}
/// Instruction describing how to delete a file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchDeleteFileOperation {
/// Path of the file to delete.
pub path: String,
}
/// Instruction describing how to update a file via the apply_patch tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ApplyPatchUpdateFileOperation {
/// Path of the file to update.
pub path: String,
/// Diff to apply.
pub diff: String,
}
/// One of the create_file, delete_file, or update_file operations applied via apply_patch.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ApplyPatchOperation {
CreateFile(ApplyPatchCreateFileOperation),
DeleteFile(ApplyPatchDeleteFileOperation),
UpdateFile(ApplyPatchUpdateFileOperation),
}
/// A tool call that applies file diffs by creating, deleting, or updating files.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ApplyPatchToolCall {
/// The unique ID of the apply patch tool call. Populated when this item is returned via API.
pub id: String,
/// The unique ID of the apply patch tool call generated by the model.
pub call_id: String,
/// The status of the apply patch tool call. One of `in_progress` or `completed`.
pub status: ApplyPatchCallStatus,
/// One of the create_file, delete_file, or update_file operations applied via apply_patch.
pub operation: ApplyPatchOperation,
/// The ID of the entity that created this tool call.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Outcome values reported for apply_patch tool call outputs.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ApplyPatchCallOutputStatus {
Completed,
Failed,
}
/// The output emitted by an apply patch tool call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ApplyPatchToolCallOutput {
/// The unique ID of the apply patch tool call output. Populated when this item is returned via API.
pub id: String,
/// The unique ID of the apply patch tool call generated by the model.
pub call_id: String,
/// The status of the apply patch tool call output. One of `completed` or `failed`.
pub status: ApplyPatchCallOutputStatus,
/// Optional textual output returned by the apply patch tool.
pub output: Option<String>,
/// The ID of the entity that created this tool call output.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
}
/// Output of an MCP server tool invocation.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct MCPToolCall {
/// A JSON string of the arguments passed to the tool.
pub arguments: String,
/// The unique ID of the tool call.
pub id: String,
/// The name of the tool that was run.
pub name: String,
/// The label of the MCP server running the tool.
pub server_label: String,
/// Unique identifier for the MCP tool call approval request. Include this value
/// in a subsequent `mcp_approval_response` input to approve or reject the corresponding
/// tool call.
pub approval_request_id: Option<String>,
/// The error from the tool call, if any.
pub error: Option<MCPToolCallError>,
/// The output from the tool call.
pub output: Option<String>,
/// The status of the tool call. One of `in_progress`, `completed`, `incomplete`,
/// `calling`, or `failed`.
pub status: Option<MCPToolCallStatus>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum MCPToolCallStatus {
InProgress,
Completed,
Incomplete,
Calling,
Failed,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct MCPListTools {
/// The unique ID of the list.
pub id: String,
/// The label of the MCP server.
pub server_label: String,
/// The tools available on the server.
pub tools: Vec<MCPListToolsTool>,
/// Error message if listing failed.
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct MCPApprovalRequest {
/// JSON string of arguments for the tool.
pub arguments: String,
/// The unique ID of the approval request.
pub id: String,
/// The name of the tool to run.
pub name: String,
/// The label of the MCP server making the request.
pub server_label: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum Instructions {
/// A text input to the model, equivalent to a text input with the `developer` role.
Text(String),
/// A list of one or many input items to the model, containing different content types.
Array(Vec<InputItem>),
}
/// The complete response returned by the Responses API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Response {
/// Whether to run the model response in the background.
/// [Learn more](https://platform.openai.com/docs/guides/background).
#[serde(skip_serializing_if = "Option::is_none")]
pub background: Option<bool>,
/// Billing information for the response.
#[serde(skip_serializing_if = "Option::is_none")]
pub billing: Option<Billing>,
/// The conversation that this response belongs to. Input items and output
/// items from this response are automatically added to this conversation.
#[serde(skip_serializing_if = "Option::is_none")]
pub conversation: Option<Conversation>,
/// Unix timestamp (in seconds) when this Response was created.
pub created_at: u64,
/// Unix timestamp (in seconds) of when this Response was completed.
/// Only present when the status is `completed`.
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_at: Option<u64>,
/// An error object returned when the model fails to generate a Response.
#[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<ResponseError>,
/// Unique identifier for this response.
pub id: String,
/// Details about why the response is incomplete, if any.
#[serde(skip_serializing_if = "Option::is_none")]
pub incomplete_details: Option<IncompleteDetails>,
/// A system (or developer) message inserted into the model's context.
///
/// When using along with `previous_response_id`, the instructions from a previous response
/// will not be carried over to the next response. This makes it simple to swap out
/// system (or developer) messages in new responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<Instructions>,
/// An upper bound for the number of tokens that can be generated for a response,
/// including visible output tokens and
/// [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
#[serde(skip_serializing_if = "Option::is_none")]
pub max_output_tokens: Option<u32>,
/// Set of 16 key-value pairs that can be attached to an object. This can be
/// useful for storing additional information about the object in a structured
/// format, and querying for objects via API or the dashboard.
///
/// Keys are strings with a maximum length of 64 characters. Values are strings
/// with a maximum length of 512 characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, String>>,
/// Model ID used to generate the response, like `gpt-6-astra`. OpenAI
/// offers a wide range of models with different capabilities, performance
/// characteristics, and price points. Refer to the [model guide](/docs/models)
/// to browse and compare available models.
pub model: String,
/// The object type of this resource - always set to `response`.
pub object: String,
/// An array of content items generated by the model.
///
/// - The length and order of items in the output array is dependent on the model's response.
/// - Rather than accessing the first item in the output array and assuming it's an assistant
/// message with the content generated by the model, you might consider using
/// the `output_text` property where supported in SDKs.
pub output: Vec<OutputItem>,
/// SDK-only convenience property that contains the aggregated text output from all
/// `output_text` items in the `output` array, if any are present.
/// Supported in the Python and JavaScript SDKs.
// #[serde(skip_serializing_if = "Option::is_none")]
// pub output_text: Option<String>,
/// Whether to allow the model to run tool calls in parallel.
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
/// The unique ID of the previous response to the model. Use this to create multi-turn conversations.
/// Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
/// Cannot be used in conjunction with `conversation`.
#[serde(skip_serializing_if = "Option::is_none")]
pub previous_response_id: Option<String>,
/// Reference to a prompt template and its variables.
/// [Learn more](https://platform.openai.com/docs/guides/text?api-mode=responses#reusable-prompts).
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<Prompt>,
/// Used by OpenAI to cache responses for similar requests to optimize your cache hit rates. Replaces
/// the `user` field. [Learn more](https://platform.openai.com/docs/guides/prompt-caching).
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_key: Option<String>,
/// The retention policy for the prompt cache. Set to `24h` to enable extended prompt caching,
/// which keeps cached prefixes active for longer, up to a maximum of 24 hours. [Learn
/// more](https://platform.openai.com/docs/guides/prompt-caching#prompt-cache-retention).
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Use prompt_cache_options instead.")]
pub prompt_cache_retention: Option<PromptCacheRetention>,
/// **gpt-5 and o-series models only**
/// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<Reasoning>,
/// A stable identifier used to help detect users of your application that may be violating OpenAI's
/// usage policies.
///
/// The IDs should be a string that uniquely identifies each user. We recommend hashing their username
/// or email address, in order to avoid sending us any identifying information. [Learn
/// more](https://platform.openai.com/docs/guides/safety-best-practices#safety-identifiers).
#[serde(skip_serializing_if = "Option::is_none")]
pub safety_identifier: Option<String>,
/// Specifies the processing type used for serving the request.
/// - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
/// - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
/// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)' or '[priority](https://openai.com/api-priority-processing/)', then the request will be processed with the corresponding service tier.
/// - When not set, the default behavior is 'auto'.
///
/// When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<ServiceTierResponses>,
/// The status of the response generation.
/// One of `completed`, `failed`, `in_progress`, `cancelled`, `queued`, or `incomplete`.
pub status: Status,
/// What sampling temperature was used, between 0 and 2. Higher values like 0.8 make
/// outputs more random, lower values like 0.2 make output more focused and deterministic.
///
/// We generally recommend altering this or `top_p` but not both.
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
/// Configuration options for a text response from the model. Can be plain
/// text or structured JSON data. Learn more:
/// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
/// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseTextParam>,
/// How the model should select which tool (or tools) to use when generating
/// a response. See the `tools` parameter to see how to specify which tools
/// the model can call.
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<ToolChoiceParam>,
/// An array of tools the model may call while generating a response. You
/// can specify which tool to use by setting the `tool_choice` parameter.
///
/// We support the following categories of tools:
/// - **Built-in tools**: Tools that are provided by OpenAI that extend the
/// model's capabilities, like [web search](https://platform.openai.com/docs/guides/tools-web-search)
/// or [file search](https://platform.openai.com/docs/guides/tools-file-search). Learn more about
/// [built-in tools](https://platform.openai.com/docs/guides/tools).
/// - **MCP Tools**: Integrations with third-party systems via custom MCP servers
/// or predefined connectors such as Google Drive and SharePoint. Learn more about
/// [MCP Tools](https://platform.openai.com/docs/guides/tools-connectors-mcp).
/// - **Function calls (custom tools)**: Functions that are defined by you,
/// enabling the model to call your own code with strongly typed arguments
/// and outputs. Learn more about
/// [function calling](https://platform.openai.com/docs/guides/function-calling). You can also use
/// custom tools to call your own code.
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<Tool>>,
/// An integer between 0 and 20 specifying the number of most likely tokens to return at each
/// token position, each with an associated log probability.
#[serde(skip_serializing_if = "Option::is_none")]
pub top_logprobs: Option<u8>,
/// An alternative to sampling with temperature, called nucleus sampling,
/// where the model considers the results of the tokens with top_p probability
/// mass. So 0.1 means only the tokens comprising the top 10% probability mass
/// are considered.
///
/// We generally recommend altering this or `temperature` but not both.
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f32>,
///The truncation strategy to use for the model response.
/// - `auto`: If the input to this Response exceeds
/// the model's context window size, the model will truncate the
/// response to fit the context window by dropping items from the beginning of the conversation.
/// - `disabled` (default): If the input size will exceed the context window
/// size for a model, the request will fail with a 400 error.
#[serde(skip_serializing_if = "Option::is_none")]
pub truncation: Option<Truncation>,
/// Represents token usage details including input tokens, output tokens,
/// a breakdown of output tokens, and the total tokens used.
#[serde(skip_serializing_if = "Option::is_none")]
pub usage: Option<ResponseUsage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_options: Option<PromptCacheOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_diagnostics: Option<PromptCacheDiagnostics>,
#[serde(skip_serializing_if = "Option::is_none")]
pub moderation: Option<Moderation>,
/// Domain-specific access programs applied to this response.
#[serde(skip_serializing_if = "Option::is_none")]
pub access_programs: Option<AccessProgramsBody>,
/// Usage reported by hosted tools, separate from base model `usage`. The field
/// can be omitted when tool usage is unavailable. When present, tool families
/// with no recorded usage have zero counts.
///
/// `image_gen` sums available token counts across image generation calls.
/// Calls with missing or incomplete usage records may be skipped. Output
/// token details and cached input counts can be omitted. An omitted cache
/// count means cache usage is unknown.
///
/// `web_search.num_requests` counts billable searches. Discounted searches
/// and actions such as opening a page are excluded. Use billing records to
/// reconcile final charges.
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_usage: Option<ResponseToolUsage>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum Status {
Completed,
Failed,
InProgress,
Cancelled,
Queued,
Incomplete,
}
/// Output item
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum OutputItem {
/// An output message from the model.
Message(OutputMessage),
/// The results of a file search tool call. See the
/// [file search guide](https://platform.openai.com/docs/guides/tools-file-search)
/// for more information.
FileSearchCall(FileSearchToolCall),
/// A tool call to run a function. See the
/// [function calling guide](https://platform.openai.com/docs/guides/function-calling)
/// for more information.
FunctionCall(FunctionToolCall),
/// The output of a function tool call.
FunctionCallOutput(FunctionToolCallOutputResource),
/// The results of a web search tool call. See the
/// [web search guide](https://platform.openai.com/docs/guides/tools-web-search)
/// for more information.
WebSearchCall(WebSearchToolCall),
/// A tool call to a computer use tool. See the
/// [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use)
/// for more information.
ComputerCall(ComputerToolCall),
/// The output of a computer tool call.
ComputerCallOutput(ComputerToolCallOutputResource),
/// A description of the chain of thought used by a reasoning model while generating
/// a response. Be sure to include these items in your `input` to the Responses API for
/// subsequent turns of a conversation if you are manually
/// [managing context](https://platform.openai.com/docs/guides/conversation-state).
Reasoning(ReasoningItem),
Program(Program),
ProgramOutput(ProgramOutput),
/// A tool search call.
ToolSearchCall(ToolSearchCall),
/// A tool search output.
ToolSearchOutput(ToolSearchOutput),
AdditionalTools(AdditionalTools),
/// A compaction item generated by the [`v1/responses/compact` API](https://platform.openai.com/docs/api-reference/responses/compact).
Compaction(CompactionBody),
/// An image generation request made by the model.
ImageGenerationCall(ImageGenToolCall),
/// A tool call to run code.
CodeInterpreterCall(CodeInterpreterToolCall),
/// A tool call to run a command on the local shell.
LocalShellCall(LocalShellToolCall),
/// A tool call that executes one or more shell commands in a managed environment.
ShellCall(FunctionShellCall),
/// The output of a shell tool call.
ShellCallOutput(FunctionShellCallOutput),
/// A tool call that applies file diffs by creating, deleting, or updating files.
ApplyPatchCall(ApplyPatchToolCall),
/// The output emitted by an apply patch tool call.
ApplyPatchCallOutput(ApplyPatchToolCallOutput),
/// An invocation of a tool on an MCP server.
McpCall(MCPToolCall),
/// A list of tools available on an MCP server.
McpListTools(MCPListTools),
/// A request for human approval of a tool invocation.
McpApprovalRequest(MCPApprovalRequest),
/// A call to a custom tool created by the model.
CustomToolCall(CustomToolCall),
/// The output of a custom tool call.
CustomToolCallOutput(CustomToolCallOutputResource),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
#[non_exhaustive]
pub struct CustomToolCall {
/// An identifier used to map this custom tool call to a tool call output.
pub call_id: String,
/// The namespace of the custom tool being called.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
/// The input for the custom tool call generated by the model.
pub input: String,
/// The name of the custom tool being called.
pub name: String,
/// The unique ID of the custom tool call in the OpenAI platform.
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
/// Whether the custom tool call runs asynchronously.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
}
/// A custom tool call item returned by the API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[non_exhaustive]
pub struct CustomToolCallResource {
/// An identifier used to map this custom tool call to a tool call output.
pub call_id: String,
/// The namespace of the custom tool being called.
#[serde(skip_serializing_if = "Option::is_none")]
pub namespace: Option<String>,
/// The input for the custom tool call generated by the model.
pub input: String,
/// The name of the custom tool being called.
pub name: String,
/// The unique ID of the custom tool call in the OpenAI platform.
pub id: String,
/// The status of the item. One of `in_progress`, `completed`, or `incomplete`.
pub status: FunctionCallStatus,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caller: Option<ToolCallCaller>,
/// Whether the custom tool call runs asynchronously.
#[serde(skip_serializing_if = "Option::is_none")]
pub r#async: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct DeleteResponse {
pub object: String,
pub deleted: bool,
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct AnyItemReference {
pub r#type: Option<String>,
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ItemResourceItem {
Message(MessageItem),
FileSearchCall(FileSearchToolCall),
ComputerCall(ComputerToolCall),
ComputerCallOutput(ComputerToolCallOutputResource),
WebSearchCall(WebSearchToolCall),
FunctionCall(FunctionToolCallResource),
FunctionCallOutput(FunctionToolCallOutputResource),
ToolSearchCall(ToolSearchCall),
ToolSearchOutput(ToolSearchOutput),
AdditionalTools(AdditionalTools),
ConfigurationUpdate(ResponseConfigurationUpdate),
Reasoning(ReasoningItem),
Program(Program),
ProgramOutput(ProgramOutput),
Compaction(CompactionBody),
ImageGenerationCall(ImageGenToolCall),
CodeInterpreterCall(CodeInterpreterToolCall),
LocalShellCall(LocalShellToolCall),
LocalShellCallOutput(LocalShellToolCallOutput),
ShellCall(FunctionShellCallItemParam),
ShellCallOutput(FunctionShellCallOutputItemParam),
ApplyPatchCall(ApplyPatchToolCallItemParam),
ApplyPatchCallOutput(ApplyPatchToolCallOutputItemParam),
McpListTools(MCPListTools),
McpApprovalRequest(MCPApprovalRequest),
McpApprovalResponse(MCPApprovalResponse),
McpCall(MCPToolCall),
CustomToolCall(CustomToolCallResource),
CustomToolCallOutput(CustomToolCallOutputResource),
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum ItemResource {
ItemReference(AnyItemReference),
Item(ItemResourceItem),
}
/// A list of Response items.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ResponseItemList {
/// The type of object returned, must be `list`.
pub object: String,
/// The ID of the first item in the list.
pub first_id: Option<String>,
/// The ID of the last item in the list.
pub last_id: Option<String>,
/// Whether there are more items in the list.
pub has_more: bool,
/// The list of items.
pub data: Vec<ItemResource>,
}
#[derive(Clone, Serialize, Deserialize, Debug, Default, Builder, PartialEq)]
#[builder(
name = "TokenCountsBodyArgs",
pattern = "mutable",
setter(into, strip_option),
default
)]
#[builder(build_fn(error = "OpenAIError"))]
pub struct TokenCountsBody {
/// The conversation that this response belongs to. Items from this
/// conversation are prepended to `input_items` for this response request.
/// Input items and output items from this response are automatically added to this
/// conversation after this response completes.
#[serde(skip_serializing_if = "Option::is_none")]
pub conversation: Option<ConversationParam>,
/// Text, image, or file inputs to the model, used to generate a response
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<InputParam>,
/// A system (or developer) message inserted into the model's context.
///
/// When used along with `previous_response_id`, the instructions from a previous response will
/// not be carried over to the next response. This makes it simple to swap out system (or
/// developer) messages in new responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
/// Model ID used to generate the response, like `gpt-4o` or `o3`. OpenAI offers a
/// wide range of models with different capabilities, performance characteristics,
/// and price points. Refer to the [model guide](https://platform.openai.com/docs/models)
/// to browse and compare available models.
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
/// Whether to allow the model to run tool calls in parallel.
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
/// The unique ID of the previous response to the model. Use this to create multi-turn
/// conversations. Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
/// Cannot be used in conjunction with `conversation`.
#[serde(skip_serializing_if = "Option::is_none")]
pub previous_response_id: Option<String>,
/// **gpt-5 and o-series models only**
/// Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<Reasoning>,
/// Configuration options for a text response from the model. Can be plain
/// text or structured JSON data. Learn more:
/// - [Text inputs and outputs](https://platform.openai.com/docs/guides/text)
/// - [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseTextParam>,
/// How the model should select which tool (or tools) to use when generating
/// a response. See the `tools` parameter to see how to specify which tools
/// the model can call.
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_choice: Option<ToolChoiceParam>,
/// An array of tools the model may call while generating a response. You can specify which tool
/// to use by setting the `tool_choice` parameter.
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<Tool>>,
///The truncation strategy to use for the model response.
/// - `auto`: If the input to this Response exceeds
/// the model's context window size, the model will truncate the
/// response to fit the context window by dropping items from the beginning of the conversation.
/// - `disabled` (default): If the input size will exceed the context window
/// size for a model, the request will fail with a 400 error.
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Deprecated by the API")]
pub truncation: Option<Truncation>,
/// A model-owned style preset to apply to this request. Omit this parameter to use the model's default
/// style. Supported values may expand over time. Values must be at most 64 characters.
#[serde(skip_serializing_if = "Option::is_none")]
pub personality: Option<PersonalityEnum>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct TokenCountsResource {
pub object: String,
pub input_tokens: u32,
}
/// A compaction item generated by the `/v1/responses/compact` API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CompactionSummaryItemParam {
/// The ID of the compaction item.
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The encrypted content of the compaction summary.
pub encrypted_content: String,
}
/// A compaction item generated by the `/v1/responses/compact` API.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CompactionBody {
/// The unique ID of the compaction item.
pub id: String,
/// The encrypted content that was produced by compaction.
pub encrypted_content: String,
/// The identifier of the actor that created the item.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Default)]
#[serde(rename_all = "lowercase")]
pub enum ServiceTierEnum {
#[default]
Auto,
Default,
Flex,
Priority,
Fast,
}
/// Request to compact a conversation.
/// type in openapi spec: CompactResponseMethodPublicBody
#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
#[builder(name = "CompactResponseRequestArgs")]
#[builder(pattern = "mutable")]
#[builder(setter(into, strip_option), default)]
#[builder(derive(Debug))]
#[builder(build_fn(error = "OpenAIError"))]
pub struct CompactResponseRequest {
/// Model ID used to generate the response, like `gpt-5` or `o3`. OpenAI offers a wide range of models
/// with different capabilities, performance characteristics, and price points. Refer to the
/// [model guide](https://platform.openai.com/docs/models) to browse and compare available models.
pub model: String,
/// Text, image, or file inputs to the model, used to generate a response
#[serde(skip_serializing_if = "Option::is_none")]
pub input: Option<InputParam>,
/// The unique ID of the previous response to the model. Use this to create multi-turn
/// conversations. Learn more about [conversation state](https://platform.openai.com/docs/guides/conversation-state).
/// Cannot be used in conjunction with `conversation`.
#[serde(skip_serializing_if = "Option::is_none")]
pub previous_response_id: Option<String>,
/// A system (or developer) message inserted into the model's context.
///
/// When used along with `previous_response_id`, the instructions from a previous response will
/// not be carried over to the next response. This makes it simple to swap out system (or
/// developer) messages in new responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub instructions: Option<String>,
/// A key to use when reading from or writing to the prompt cache.
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_key: Option<String>,
/// How long to retain a prompt cache entry created by this request.
#[serde(skip_serializing_if = "Option::is_none")]
#[deprecated(note = "Use prompt_cache_options instead.")]
pub prompt_cache_retention: Option<PromptCacheRetention>,
/// The service tier to use for this request.
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<ServiceTierEnum>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt_cache_options: Option<PromptCacheOptionsParam>,
}
/// The compacted response object.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct CompactResource {
/// The unique identifier for the compacted response.
pub id: String,
/// The object type. Always `response.compaction`.
pub object: String,
/// The compacted list of output items. This is a list of all user messages,
/// followed by a single compaction item.
pub output: Vec<OutputItem>,
/// Unix timestamp (in seconds) when the compacted conversation was created.
pub created_at: u64,
/// Token accounting for the compaction pass, including cached, reasoning, and total tokens.
pub usage: ResponseUsage,
}
// ============================================================
// Container / Environment Types
// ============================================================
/// A domain-scoped secret injected for allowlisted domains.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerNetworkPolicyDomainSecretParam {
/// The domain associated with the secret.
pub domain: String,
/// The name of the secret to inject for the domain.
pub name: String,
/// The secret value to inject for the domain.
pub value: String,
}
/// Details for an allowlist network policy.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerNetworkPolicyAllowlistDetails {
/// A list of allowed domains.
pub allowed_domains: Vec<String>,
/// Optional domain-scoped secrets for allowlisted domains.
#[serde(skip_serializing_if = "Option::is_none")]
pub domain_secrets: Option<Vec<ContainerNetworkPolicyDomainSecretParam>>,
}
/// Network access policy for a container.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ContainerNetworkPolicy {
/// Disable all outbound network access.
Disabled,
/// Allow access only to specified domains.
Allowlist(ContainerNetworkPolicyAllowlistDetails),
}
/// A skill referenced by ID.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct SkillReferenceParam {
/// The ID of the skill to reference.
pub skill_id: String,
/// An optional specific version to use.
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
}
/// An inline skill source (base64-encoded zip).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct InlineSkillSourceParam {
/// The media type. Always `"application/zip"`.
pub media_type: String,
/// The base64-encoded skill data.
pub data: String,
}
/// An inline skill definition.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct InlineSkillParam {
/// The name of the skill.
pub name: String,
/// The description of the skill.
pub description: String,
/// The inline source for the skill.
pub source: InlineSkillSourceParam,
}
/// A skill parameter — either a reference or inline definition.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum SkillParam {
/// Reference a skill by ID.
SkillReference(SkillReferenceParam),
/// Provide an inline skill definition.
Inline(InlineSkillParam),
}
/// Automatically creates a container for the request.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerAutoParam {
/// An optional list of uploaded file IDs to make available in the container.
#[serde(skip_serializing_if = "Option::is_none")]
pub file_ids: Option<Vec<String>>,
/// Network access policy for the container.
#[serde(skip_serializing_if = "Option::is_none")]
pub network_policy: Option<ContainerNetworkPolicy>,
/// An optional list of skills to make available in the container.
#[serde(skip_serializing_if = "Option::is_none")]
pub skills: Option<Vec<SkillParam>>,
}
/// A local skill available in a local environment.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LocalSkillParam {
/// The name of the skill.
pub name: String,
/// The description of the skill.
pub description: String,
/// The path to the directory containing the skill.
pub path: String,
}
/// Uses a local computer environment.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct LocalEnvironmentParam {
/// An optional list of local skills.
#[serde(skip_serializing_if = "Option::is_none")]
pub skills: Option<Vec<LocalSkillParam>>,
}
/// References a container created with the /v1/containers endpoint.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerReferenceParam {
/// The ID of the referenced container.
pub container_id: String,
}
/// A resource reference to a container by ID.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct ContainerReferenceResource {
/// The ID of the referenced container.
pub container_id: String,
}
/// The execution environment for a shell tool — container or local.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum FunctionShellEnvironment {
/// Automatically creates a container for this request.
ContainerAuto(ContainerAutoParam),
/// Use a local computer environment.
Local(LocalEnvironmentParam),
/// Reference an existing container by ID.
ContainerReference(ContainerReferenceParam),
}
/// Parameters for the shell function tool.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct FunctionShellToolParam {
/// The execution environment for the shell tool.
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<FunctionShellEnvironment>,
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ContextManagementParamType {
Compaction,
}
/// Context management configuration.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ContextManagementParam {
/// The context management strategy type.
pub r#type: ContextManagementParamType,
/// Minimum number of tokens to retain before compacting.
#[serde(skip_serializing_if = "Option::is_none")]
pub compact_threshold: Option<u32>,
}
/// Apply-patch tool configuration.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct ApplyPatchToolParam {
/// Which callers may invoke this tool.
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_callers: Option<Vec<CallableToolAllowedCaller>>,
}
/// Moderation results or errors for the response input and output.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Moderation {
/// Moderation for the response input.
pub input: ModerationInput,
/// Moderation for the response output.
pub output: ModerationOutput,
}
/// An error produced while attempting moderation for the response input or output.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ModerationErrorBody {
/// The error code.
pub code: String,
/// The error message.
pub message: String,
}
/// Moderation for the response input.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ModerationInput {
ModerationResult(ModerationResultBody),
Error(ModerationErrorBody),
}
/// Moderation for the response output.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ModerationOutput {
ModerationResult(ModerationResultBody),
Error(ModerationErrorBody),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CacheMissReasonTypeEnum {
ModelChanged,
PromptCacheKeyChanged,
ToolsChanged,
TextFormatChanged,
ReasoningEffortChanged,
VerbosityChanged,
ContextCompacted,
InputChanged,
ServiceTierChanged,
}
/// Marks the exact end of a reusable prompt prefix. When ttl is omitted, the breakpoint inherits
/// the request TTL. The boundary is not rounded to a token block.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptCacheBreakpointConfig {
/// The breakpoint mode. Always `explicit`.
pub mode: PromptCacheBreakpointConfigMode,
/// The minimum lifetime of this cache breakpoint. Defaults to the request TTL.
#[serde(skip_serializing_if = "Option::is_none")]
pub ttl: Option<PromptCacheBreakpointTTLEnum>,
}
/// The breakpoint mode. Always `explicit`.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum PromptCacheBreakpointConfigMode {
Explicit,
}
/// Prompt cache diagnostics requested for this response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PromptCacheDiagnostics {
CacheMiss(PromptCacheMissDiagnosticsBody),
CacheHit,
ComparisonResponseNotFound,
Unavailable,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptCacheMissDiagnosticsBody {
/// The reason prompt cache reuse did not occur.
pub reason: CacheMissReasonTypeEnum,
/// The estimated number of input tokens affected after the first detected divergence.
pub cache_missed_tokens: u64,
/// The raw token count of the reusable prefix in the compared response.
#[serde(skip_serializing_if = "Option::is_none")]
pub comparison_reusable_tokens: Option<u64>,
}
/// The prompt-caching options that were applied to the response. Supported for `gpt-5.6` and later
/// models.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PromptCacheOptions {
/// The minimum lifetime applied to each cache breakpoint.
pub ttl: PromptCacheTTLEnum,
/// Whether implicit prompt-cache breakpoints were enabled.
pub mode: PromptCacheModeEnum,
#[serde(skip_serializing_if = "Option::is_none")]
pub comparison_response_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AdditionalTools {
/// The unique ID of the additional tools item.
pub id: String,
/// The role that provided the additional tools.
pub role: MessageRole,
/// The additional tool definitions made available at this item.
pub tools: Vec<Tool>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AdditionalToolsItemParam {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The item type. Always `additional_tools`.
/// The role that provided the additional tools. Only `developer` is supported.
pub role: AdditionalToolsItemParamRole,
/// A list of additional tools made available at this item.
pub tools: Vec<Tool>,
}
/// The role that provided the additional tools. Only `developer` is supported.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum AdditionalToolsItemParamRole {
Developer,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum CallableToolAllowedCaller {
Direct,
Programmatic,
}
/// Compacts the current context. Must be the final input item.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct CompactionTriggerItemParam {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ContainerFileCitationParam {
/// The citation type. Always `container_file_citation`.
pub r#type: String,
/// The index of the first character of the citation in the message.
pub start_index: u64,
/// The index of the last character of the citation in the message.
pub end_index: u64,
/// The ID of the container.
pub container_id: String,
/// The ID of the container file.
pub file_id: String,
/// The filename of the container file cited.
pub filename: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct FileCitationParam {
/// The citation type. Always `file_citation`.
pub r#type: String,
/// The index of the file in the list of files.
pub index: u64,
/// The ID of the file.
pub file_id: String,
/// The filename of the file cited.
pub filename: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct HTTPError {
pub code: i64,
pub message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct MCPProtocolError {
pub code: i64,
pub message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MCPToolCallError {
McpProtocolError(MCPProtocolError),
McpToolExecutionError(MCPToolExecutionError),
HttpError(HTTPError),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct MCPToolExecutionError {
pub content: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum PersonalityEnum {
Friendly,
Pragmatic,
Other(String),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct Program {
/// The unique ID of the program item.
pub id: String,
/// The stable call ID of the program item.
pub call_id: String,
/// The JavaScript source executed by programmatic tool calling.
pub code: String,
/// Opaque program replay fingerprint that must be round-tripped.
pub fingerprint: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ProgramItemParam {
/// The unique ID of this program item.
pub id: String,
/// The stable call ID of the program item.
pub call_id: String,
/// The JavaScript source executed by programmatic tool calling.
pub code: String,
/// Opaque program replay fingerprint that must be round-tripped.
pub fingerprint: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProgramOutput {
/// The unique ID of the program output item.
pub id: String,
/// The call ID of the program item.
pub call_id: String,
/// The result produced by the program item.
pub result: String,
/// The terminal status of the program output item.
pub status: ProgramOutputStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProgramOutputItemParam {
/// The unique ID of this program output item.
pub id: String,
/// The call ID of the program item.
pub call_id: String,
/// The result produced by the program item.
pub result: String,
/// The terminal status of the program output.
pub status: ProgramOutputItemStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ProgramOutputItemStatus {
Completed,
Incomplete,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ProgramOutputStatus {
Completed,
Incomplete,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ProgramToolCallCaller {
/// The call ID of the program item that produced this tool call.
pub caller_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ReasoningModeEnum {
Pro,
Standard,
#[serde(untagged)]
Other(String),
}
/// A configuration update that applies to subsequent responses until it is
/// replaced by another configuration update.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ResponseConfigurationUpdate {
/// The unique ID of the configuration update item.
pub id: String,
/// The reasoning configuration applied by this update.
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<ResponseConfigurationUpdateReasoning>,
/// The text output configuration for subsequent responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseConfigurationUpdateText>,
}
/// An update to the conversation's response configuration. The configuration
/// remains in effect for subsequent responses until it is replaced by another
/// configuration update.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ResponseConfigurationUpdateItemParam {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// Updates to reasoning configuration. Only effort is supported.
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<ResponseConfigurationUpdateReasoning>,
/// The text output configuration for subsequent responses.
#[serde(skip_serializing_if = "Option::is_none")]
pub text: Option<ResponseConfigurationUpdateText>,
}
/// The reasoning configuration applied by this update.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ResponseConfigurationUpdateReasoning {
/// The reasoning effort used for subsequent responses until another
/// configuration update replaces it.
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<ReasoningEffort>,
}
/// Options for prompt caching. Supported for `gpt-5.6` and later models. By default, OpenAI
/// automatically chooses one implicit cache breakpoint. You can add explicit breakpoints to content
/// blocks with `prompt_cache_breakpoint`. Each request can write up to four breakpoints. For cache
/// matching, OpenAI considers up to the latest 80 breakpoints in the conversation, without a content-
/// block lookback limit. Set `mode` to `explicit` to disable the implicit breakpoint. The `ttl`
/// defaults to `30m`, which is currently the only supported value. See the [prompt caching
/// guide](https://platform.openai.com/docs/guides/prompt-caching) for current details.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ResponsePromptCacheOptionsParam {
/// The minimum lifetime applied to every implicit and explicit cache breakpoint written by the request.
/// Defaults to `30m`, which is currently the only supported value. The backend may retain cache entries
/// for longer.
#[serde(skip_serializing_if = "Option::is_none")]
pub ttl: Option<PromptCacheTTLEnum>,
/// Controls whether OpenAI automatically creates an implicit cache breakpoint. Defaults to `implicit`.
/// With `implicit`, OpenAI creates one implicit breakpoint and writes up to the latest three explicit
/// breakpoints in the request. With `explicit`, OpenAI does not create an implicit breakpoint and
/// writes up to the latest four explicit breakpoints. If there are no explicit breakpoints, the request
/// does not use prompt caching.
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<PromptCacheModeEnum>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comparison_response_id: Option<String>,
/// Prepares the prompt cache without generating output. Defaults to `false`. When set to `true`,
/// overrides the `generate` field to `false`.
#[serde(skip_serializing_if = "Option::is_none")]
pub prewarm: Option<bool>,
}
/// Specifies the processing type used for serving the request.
/// - If set to 'auto', then the request will be processed with the service tier configured in the
/// Project settings. Unless otherwise configured, the Project will use 'default'.
/// - If set to 'default', then the request will be processed with the standard pricing and
/// performance for the selected model.
/// - If set to '[flex](https://platform.openai.com/docs/guides/flex-processing)', then the request will be processed with the
/// Flex Processing service tier.
/// - To opt-in to [Fast mode](https://platform.openai.com/api/docs/guides/fast-mode) at the request level, include the
/// `service_tier=fast` or `service_tier=priority` parameter for Responses or Chat Completions. The
/// response will show `service_tier=priority` regardless of if you specify `service_tier=fast` or
/// `priority` in your request.
/// - If set to 'ultrafast', then the request will be processed with the access-controlled Ultrafast
/// Processing service tier. This tier is currently available for `gpt-5.6-sol`; a response served
/// through it will show `service_tier=ultrafast`.
/// - When not set, the default behavior is 'auto'.
///
/// When the `service_tier` parameter is set, the response body will include the `service_tier` value
/// based on the processing mode actually used to serve the request. This response value may be
/// different from the value set in the parameter.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ServiceTierResponses {
Auto,
Default,
Flex,
Scale,
Priority,
Fast,
Ultrafast,
}
/// The execution context that produced this tool call.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ToolCallCaller {
Direct,
Program(ProgramToolCallCaller),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct UrlCitationParam {
/// The citation type. Always `url_citation`.
pub r#type: String,
/// The index of the first character of the citation in the message.
pub start_index: u64,
/// The index of the last character of the citation in the message.
pub end_index: u64,
/// The URL of the cited resource.
pub url: String,
/// The title of the cited resource.
pub title: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResponseConfigurationUpdateText {
pub format: ResponseConfigurationUpdateTextFormat,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ResponseConfigurationUpdateTextFormat {
Text,
JsonSchema(ResponseFormatJsonSchema),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AccessProgramsBody {
/// The effective Cyber access program used for this response.
pub cyber: CyberAccessProgramEnum,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CyberAccessProgramEnum {
Standard,
DaybreakBlue,
DaybreakRed,
}
/// Domain-specific access programs to use for this request.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct AccessProgramsParam {
/// The Cyber access program to use for this request. Supported values are `standard`, `daybreak_blue`, and `daybreak_red`. If omitted, the API resolves the program from the model's Cyber tier and your organization and project access, subject to model-specific eligibility restrictions. By default, models without a Cyber tier use Standard. Blue-tier models use Daybreak Blue when authorized; otherwise they fall back to Standard unless the model requires Daybreak access. Red-tier models use Daybreak Red and require authorization. Requests that require unavailable Daybreak access return 403. An implicit Standard fallback is represented by null in the response's access_programs field, rather than an explicit Standard selection.
#[serde(skip_serializing_if = "Option::is_none")]
pub cyber: Option<CyberAccessProgramEnum>,
}
/// Aggregated usage details for billable tools that ran while generating the response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ResponseToolUsage {
/// Aggregated usage statistics for image generation tool calls.
pub image_gen: ImageGenToolUsage,
/// Aggregated billable usage statistics for web search tool calls.
pub web_search: WebSearchUsage,
}
/// Usage details for web search requests that ran while generating the response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct WebSearchUsage {
/// The number of billable web search requests issued.
pub num_requests: u32,
}
/// Token usage for image generation tool calls in a response.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ImageGenToolUsage {
/// The number of tokens (images and text) in the input prompt.
pub input_tokens: u32,
/// The total number of tokens (images and text) used for the image generation.
pub total_tokens: u32,
/// The number of output tokens generated by the model.
pub output_tokens: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub output_tokens_details: Option<ImageGenOutputTokensDetails>,
pub input_tokens_details: ImageGenInputUsageDetails,
#[serde(skip_serializing_if = "Option::is_none")]
pub cached_tokens: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cached_tokens_details: Option<CachedUsageDetails>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct CachedUsageDetails {
pub cached_text_tokens: u32,
pub cached_image_tokens: u32,
}
/// An error returned by the image generation tool.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ImageGenToolCallError {
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
/// The error type.
pub r#type: String,
/// A description of the error.
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub param: Option<String>,
/// Public details for a `moderation_blocked` error, when available.
#[serde(skip_serializing_if = "Option::is_none")]
pub moderation_details: Option<ImageGenToolCallModerationDetails>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ImageGenToolCallModerationDetails {
/// The stage where moderation blocked the image generation call.
pub moderation_stage: ImageGenToolCallModerationDetailsModerationStage,
/// Public moderation categories. New category values may be added over time.
pub categories: Vec<String>,
}
/// The stage where moderation blocked the image generation call.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ImageGenToolCallModerationDetailsModerationStage {
Input,
Output,
Unknown,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ToolSearchOutputTool {
/// Defines a function in your own code the model can choose to call. Learn more about [function
/// calling](https://platform.openai.com/docs/guides/tools).
Function(FunctionTool),
/// A tool that searches for relevant content from uploaded files. Learn more about the [file search
/// tool](https://platform.openai.com/docs/guides/tools-file-search).
FileSearch(FileSearchTool),
/// A tool that controls a virtual computer. Learn more about the
/// [computer tool](https://platform.openai.com/docs/guides/tools-computer-use).
Computer,
/// A tool that controls a virtual computer. Learn more about the [computer
/// use tool](https://platform.openai.com/docs/guides/tools-computer-use).
ComputerUsePreview(ComputerUsePreviewTool),
/// Search the Internet for sources related to the prompt. Learn more about the
/// [web search tool](https://platform.openai.com/docs/guides/tools-web-search).
WebSearch(WebSearchTool),
/// type: web_search_2025_08_26
#[serde(rename = "web_search_2025_08_26")]
WebSearch20250826(WebSearchTool),
/// Give the model access to additional tools via remote Model Context Protocol
/// (MCP) servers. [Learn more about MCP](https://platform.openai.com/docs/guides/tools-remote-mcp).
Mcp(MCPTool),
/// A tool that runs Python code to help generate a response to a prompt.
CodeInterpreter(CodeInterpreterTool),
ProgrammaticToolCalling,
/// A tool that generates images using a model like `gpt-image-1`.
ImageGeneration(ImageGenTool),
/// A tool that allows the model to execute shell commands in a local environment.
LocalShell,
/// A tool that allows the model to execute shell commands.
Shell(FunctionShellToolParam),
/// A custom tool that processes input using a specified format. Learn more about [custom
/// tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
Custom(CustomToolParam),
/// Groups function/custom tools under a shared namespace.
Namespace(ToolSearchOutputNamespaceToolParam),
/// Hosted or BYOT tool search configuration for deferred tools.
ToolSearch(ToolSearchToolParam),
/// This tool searches the web for relevant results to use in a response. Learn more about the [web search
///tool](https://platform.openai.com/docs/guides/tools-web-search).
WebSearchPreview(WebSearchTool),
/// type: web_search_preview_2025_03_11
#[serde(rename = "web_search_preview_2025_03_11")]
WebSearchPreview20250311(WebSearchTool),
/// Allows the assistant to create, delete, or update files using unified diffs.
ApplyPatch(ApplyPatchToolParam),
}
/// A namespace containing loaded function and custom tool definitions.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct ToolSearchOutputNamespaceToolParam {
pub name: String,
pub description: String,
pub tools: Vec<NamespaceToolParamTool>,
}
/// Loaded function tool parameters have the same shape as function tool parameters.
pub type ToolSearchOutputFunctionToolParam = FunctionToolParam;