Skip to main content

RequestBody

Struct RequestBody 

Source
pub struct RequestBody {
Show 27 fields pub background: Option<bool>, pub conversation: Option<String>, pub include: Option<Vec<String>>, pub input: Input, pub instructions: Option<String>, pub max_output_tokens: Option<u32>, pub max_tool_calls: Option<u32>, pub metadata: Option<HashMap<String, String>>, pub model: String, pub parallel_tool_calls: Option<bool>, pub previous_response_id: Option<String>, pub prompt_cache_key: Option<String>, pub enable_thinking: Option<bool>, pub reasoning: Option<ReasoningConfig>, pub safety_identifier: Option<String>, pub service_tier: Option<ServiceTier>, pub store: Option<bool>, pub stream: Option<bool>, pub temperature: Option<f32>, pub text: Option<TextConfig>, pub tool_choice: Option<ToolChoice>, pub tools: Option<Vec<Tool>>, pub top_logprobs: Option<u32>, pub top_p: Option<f32>, pub truncation: Option<Truncation>, pub user: Option<String>, pub extra_body_map: Option<Map<String, Value>>,
}
Expand description

Creates a model response for the given input.

§Example

use openai_interface::responses::create::request::{Input, RequestBody};
use openai_interface::rest::{default_client, post::PostNoStream, RequestOptions};

const DEEPSEEK_URL: &'static str = "https://api.deepseek.com";
const DEEPSEEK_MODEL: &'static str = "deepseek-v4-flash";

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Needs the `ferritls` cargo feature; drop this line if you install
    // your own rustls crypto provider (see `openai_interface::rest`).
    openai_interface::rest::install_crypto_provider().ok();

    let request = RequestBody {
        model: DEEPSEEK_MODEL.to_string(),
        input: Input::Text("Hello!".to_string()),
        instructions: Some("You are a helpful assistant.".to_string()),
        ..Default::default()
    };

    let response = request
        .get_response(&default_client(), DEEPSEEK_URL, &RequestOptions::bearer("YOUR_API_KEY"))
        .await?;
    println!("{}", response.output_text());
    Ok(())
}

Fields§

§background: Option<bool>

Whether to run the model response in the background, returning a queued response immediately. Not supported by DeepSeek and Qwen (synchronous calls only).

§conversation: Option<String>

The ID of an existing conversation to prepend to the input. Items from this response are automatically added to the conversation after it completes. Mutually exclusive with previous_response_id. Not supported by DeepSeek (stateless API).

§include: Option<Vec<String>>

Additional output data to include in the model response, e.g. "message.output_text.logprobs" or "reasoning.encrypted_content".

§input: Input

Text, image, or file inputs to the model, used to generate a response. Either a plain string (treated as one user message) or a list of input items. Together with Self::instructions, at least one must be provided.

§instructions: 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 are not carried over.

§max_output_tokens: Option<u32>

An upper bound for the number of tokens that can be generated for a response, including visible output tokens and reasoning tokens.

§max_tool_calls: Option<u32>

The maximum number of total calls to built-in tools that can be processed in a response.

§metadata: Option<HashMap<String, String>>

Set of 16 key-value pairs that can be attached to an object. Keys are strings with a maximum length of 64 characters; values are strings with a maximum length of 512 characters. Not supported by DeepSeek.

§model: String

Model ID used to generate the response, e.g. deepseek-v4-flash or qwen3.8-max.

§parallel_tool_calls: Option<bool>

Whether to allow the model to run tool calls in parallel. Ignored by DeepSeek (parallel tool calls are always enabled).

§previous_response_id: Option<String>

The unique ID of the previous response to the model. Use this to create multi-turn conversations without resending the full input history. Mutually exclusive with conversation. Not supported by DeepSeek (stateless API); supported by Qwen.

§prompt_cache_key: Option<String>

Used by OpenAI to cache responses for similar requests to optimize cache hit rates. Replaces the user field. Not supported by DeepSeek (caching is automatic there).

§enable_thinking: Option<bool>

Qwen: whether to enable thinking mode for hybrid-thinking models. The thinking content is returned via reasoning output items. Non-standard parameter; reasoning.effort is preferred.

§reasoning: Option<ReasoningConfig>

Configuration options for reasoning models.

§safety_identifier: Option<String>

A stable identifier used to help detect users of your application that may be violating the usage policies.

§service_tier: Option<ServiceTier>

Specifies the processing type used for serving the request. Not supported by DeepSeek.

§store: Option<bool>

Whether to store the generated model response for later retrieval via the retrieve endpoint. DeepSeek always stores nothing (its Responses API is stateless).

§stream: Option<bool>

If set to true, the response is streamed back as semantic server-sent events (see super::response::ResponseStreamEvent).

§temperature: Option<f32>

What sampling temperature to use, between 0 and 2. Higher values make the output more random. Has no effect in thinking mode.

§text: Option<TextConfig>

Configuration options for a text response from the model: plain text or structured JSON data.

§tool_choice: Option<ToolChoice>

How the model should select which tool (or tools) to use when generating a response.

§tools: Option<Vec<Tool>>

An array of tools the model may call while generating a response.

§top_logprobs: Option<u32>

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.

§top_p: Option<f32>

An alternative to sampling with temperature, called nucleus sampling. Has no effect in thinking mode.

§truncation: Option<Truncation>

The truncation strategy to use for the model response. DeepSeek only supports disabled (over-long inputs return an error).

§user: Option<String>

A stable identifier for your end-users. Being replaced by safety_identifier and prompt_cache_key.

§extra_body_map: Option<Map<String, Value>>

Other request body fields that are not covered above. Useful for provider-specific parameters such as Qwen’s ocr_options.

Implementations§

Source§

impl RequestBody

Source

pub fn is_streaming(&self) -> bool

Whether this request asks for a streamed response. Defaults to false when RequestBody::stream is None.

Trait Implementations§

Source§

impl Clone for RequestBody

Source§

fn clone(&self) -> RequestBody

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RequestBody

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RequestBody

Source§

fn default() -> RequestBody

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RequestBody

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Post for RequestBody

Source§

fn build_url(&self, base_url: &str) -> Result<String, OapiError>

Builds the URL for the request.

base_url should be like https://api.openai.com/v1

Source§

fn is_streaming(&self) -> bool

Source§

impl PostNoStream for RequestBody

Source§

type Response = Response

Source§

fn get_response_string( &self, client: &Client, base_url: &str, options: &RequestOptions, ) -> impl Future<Output = Result<String, OapiError>> + Send + Sync

Sends a POST request and returns the raw response body. Read more
Source§

fn get_response( &self, client: &Client, url: &str, options: &RequestOptions, ) -> impl Future<Output = Result<Self::Response, OapiError>> + Send + Sync

Sends a POST request and deserializes the response.
Source§

impl PostStream for RequestBody

Source§

type Response = ResponseStreamEvent

Source§

fn get_stream_response_string( &self, client: &Client, base_url: &str, options: &RequestOptions, ) -> impl Future<Output = Result<impl Stream<Item = Result<String, OapiError>> + Send + Unpin + 'static, OapiError>> + Send + Sync

Sends a streaming POST request and returns the raw SSE data items as strings. Read more
Source§

fn get_stream_response( &self, client: &Client, base_url: &str, options: &RequestOptions, ) -> impl Future<Output = Result<impl Stream<Item = Result<Self::Response, OapiError>> + Send + Unpin + 'static, OapiError>> + Send + Sync

Sends a streaming POST request and deserializes every SSE data item into Self::Response. Read more
Source§

impl Serialize for RequestBody

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more