Skip to main content

openai_types/responses/
input.rs

1// MANUAL — hand-maintained. py2rust sync will not overwrite.
2// Input items for the Responses API.
3
4use serde::{Deserialize, Serialize};
5
6use super::common::{ImageDetail, Role};
7use super::output::{FunctionToolCall, ReasoningItem};
8
9/// Input for the Responses API — text or structured items.
10#[derive(Debug, Clone, Serialize)]
11#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
12#[serde(untagged)]
13#[non_exhaustive]
14pub enum ResponseInput {
15    /// Plain text input.
16    Text(String),
17    /// Structured message list.
18    Messages(Vec<ResponseInputItem>),
19    /// Raw items array — for mixed types (messages + function_call_output).
20    Items(Vec<serde_json::Value>),
21}
22
23impl From<&str> for ResponseInput {
24    fn from(s: &str) -> Self {
25        ResponseInput::Text(s.to_string())
26    }
27}
28
29impl From<String> for ResponseInput {
30    fn from(s: String) -> Self {
31        ResponseInput::Text(s)
32    }
33}
34
35/// An input message for the Responses API.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
38pub struct ResponseInputItem {
39    /// Message role.
40    pub role: Role,
41    /// Message content (text string or structured content array).
42    pub content: serde_json::Value,
43}
44
45/// A simplified message input with role and content.
46///
47/// Used for easy construction of user/assistant/system/developer messages.
48/// Maps to Python SDK `EasyInputMessage`.
49#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
50#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
51pub struct EasyInputMessage {
52    /// The type of the message input. Always `message`.
53    #[serde(rename = "type")]
54    pub r#type: MessageType,
55    /// The role of the message.
56    pub role: Role,
57    /// Text or structured content.
58    pub content: EasyInputContent,
59}
60
61/// Message type marker — always "message".
62#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
63#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
64#[non_exhaustive]
65pub enum MessageType {
66    /// Message type.
67    #[serde(rename = "message")]
68    Message,
69}
70
71/// Content for an `EasyInputMessage` — either plain text or a structured content list.
72#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
73#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
74#[serde(untagged)]
75#[non_exhaustive]
76pub enum EasyInputContent {
77    /// Plain text content.
78    Text(String),
79    /// Structured content list (text + images + files).
80    ContentList(Vec<InputContent>),
81}
82
83/// A single content item within an input message content list.
84///
85/// Maps to Python SDK `ResponseInputContent` union.
86#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
87#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
88#[serde(tag = "type")]
89#[non_exhaustive]
90pub enum InputContent {
91    /// Text content.
92    #[serde(rename = "input_text")]
93    InputText(InputTextContent),
94    /// Image content.
95    #[serde(rename = "input_image")]
96    InputImage(InputImageContent),
97}
98
99/// Text content within an input message.
100#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
101#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
102pub struct InputTextContent {
103    /// The text input.
104    pub text: String,
105}
106
107/// Image content within an input message.
108///
109/// Maps to Python SDK `ResponseInputImageContent`.
110#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
111#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
112pub struct InputImageContent {
113    /// Image detail level.
114    pub detail: ImageDetail,
115    /// File ID for uploaded images.
116    #[serde(default)]
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub file_id: Option<String>,
119    /// URL or base64 data URL.
120    #[serde(default)]
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub image_url: Option<String>,
123}
124
125/// An input item for the Responses API.
126///
127/// Union of easy messages and typed items (function calls, reasoning, etc.).
128#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
129#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
130#[serde(untagged)]
131#[non_exhaustive]
132pub enum InputItem {
133    /// A simplified message input.
134    EasyMessage(EasyInputMessage),
135    /// A typed item (function call, function call output, reasoning, etc.).
136    Item(Item),
137}
138
139/// A typed input item — function call, function call output, or reasoning.
140///
141/// Maps to the discriminated union in the Python SDK `ResponseInputItem`.
142#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
143#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
144#[serde(tag = "type")]
145#[non_exhaustive]
146pub enum Item {
147    /// A function call from the model.
148    #[serde(rename = "function_call")]
149    FunctionCall(FunctionToolCall),
150    /// Output from a function call (sent back by the client).
151    #[serde(rename = "function_call_output")]
152    FunctionCallOutput(FunctionCallOutputItemParam),
153    /// Reasoning chain-of-thought item.
154    #[serde(rename = "reasoning")]
155    Reasoning(ReasoningItem),
156}
157
158/// Output from a function call, sent back to the model.
159///
160/// Maps to Python SDK `FunctionCallOutput` input item.
161#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
162#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
163pub struct FunctionCallOutputItemParam {
164    /// The call ID matching the function call.
165    pub call_id: String,
166    /// The output content.
167    pub output: FunctionCallOutput,
168    /// Unique ID (populated when returned via API).
169    #[serde(default)]
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub id: Option<String>,
172    /// Item status.
173    #[serde(default)]
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub status: Option<String>,
176}
177
178/// The output content of a function call.
179#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
180#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
181#[serde(untagged)]
182#[non_exhaustive]
183pub enum FunctionCallOutput {
184    /// Plain text output.
185    Text(String),
186}
187
188/// Additional data to include in the response.
189///
190/// Maps to Python SDK `ResponseIncludable`.
191#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
192#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
193#[non_exhaustive]
194pub enum IncludeEnum {
195    /// Include file search call results.
196    #[serde(rename = "file_search_call.results")]
197    FileSearchCallResults,
198    /// Include web search call results.
199    #[serde(rename = "web_search_call.results")]
200    WebSearchCallResults,
201    /// Include reasoning encrypted content.
202    #[serde(rename = "reasoning.encrypted_content")]
203    ReasoningEncryptedContent,
204    /// Include message input image URLs.
205    #[serde(rename = "message.input_image.image_url")]
206    MessageInputImageUrl,
207    /// Include computer call output image URLs.
208    #[serde(rename = "computer_call_output.output.image_url")]
209    ComputerCallOutputImageUrl,
210    /// Include code interpreter call outputs.
211    #[serde(rename = "code_interpreter_call.outputs")]
212    CodeInterpreterCallOutputs,
213    /// Include message output text log probabilities.
214    #[serde(rename = "message.output_text.logprobs")]
215    MessageOutputTextLogprobs,
216}
217
218/// Input parameter for the Responses API — text or structured items.
219///
220/// Used in `CreateResponse` builder.
221#[derive(Debug, Clone, Serialize, Deserialize)]
222#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
223#[serde(untagged)]
224#[non_exhaustive]
225pub enum InputParam {
226    /// Plain text input.
227    Text(String),
228    /// Structured input items.
229    Items(Vec<InputItem>),
230}