Expand description
The Responses API: create model responses and retrieve stored ones.
The Responses API is the successor of the Chat Completions API. Instead
of messages it takes an input that is either a plain string or a list
of input items (message, function_call, function_call_output,
reasoning, …), and instead of choices it returns a list of output
items.
Request types live in create::request, the shared response object and
the streaming event types in this module and create, and the retrieve
endpoint in retrieve.
Provider support is partial — see
the DeepSeek Responses API guide
and
the Qwen Responses API reference.
Notably DeepSeek’s implementation is stateless (store,
previous_response_id and retrieval are not supported there), while Qwen
supports multi-turn conversations via previous_response_id.
§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()),
..Default::default()
};
let response = request
.get_response(&default_client(), DEEPSEEK_URL, &RequestOptions::bearer("YOUR_API_KEY"))
.await?;
println!("{}", response.output_text());
Ok(())
}Modules§
- cancel
- Cancel a background response via
POST /responses/{response_id}/cancel. - create
- Create a response via
POST /responses. - delete
- Delete a stored response via
DELETE /responses/{response_id}. - input_
items - List the input items of a stored response via
GET /responses/{response_id}/input_items. - retrieve
- Retrieve a stored response via
GET /responses/{response_id}.
Structs§
- Code
Interpreter Call - Qwen: a code interpreter tool call.
- File
Search Call - Qwen: a knowledge-base (file search) tool call.
- Image
Search Call - Qwen: an image-to-image search tool call.
- Incomplete
Details - Details about why the response is incomplete.
- Input
Tokens Details - A breakdown of the input tokens.
- McpCall
- Qwen: a call to a tool on an MCP server.
- Output
Tokens Details - A breakdown of the output tokens.
- Reasoning
Summary - A summary part of a
ResponseReasoningItem. - Response
- The response object returned by the Responses API (non-streaming create, the final streaming events, and retrieve).
- Response
Error - An error object returned when the model fails to generate a response.
- Response
Function Call - A call to a user-defined function.
- Response
Output Message - A message output from the model.
- Response
Reasoning Item - A reasoning item (chain-of-thought and/or summaries) from the model.
- Response
Usage - Token usage statistics of a
Response. - Response
WebSearch Call - A web search performed by the server-side web search tool.
- WebExtractor
Call - Qwen: a web page extraction tool call.
- WebSearch
Action - The search action of a
ResponseWebSearchCall. - WebSearch
Image Call - Qwen: a text-to-image search tool call.
- WebSearch
Source - A source cited by a web search.
Enums§
- Annotation
- An annotation on an output text part.
- Incomplete
Reason - Why a response is incomplete.
- Item
Status - The status of an output item.
- Output
Content - A content part of an output
ResponseOutputMessage. - Reasoning
Content - A content part of a
ResponseReasoningItem. - Response
Object - The
objectfield of a response object, alwaysresponse. - Response
Output Item - An item in the
outputarray of aResponse. - Response
Status - The status of the response generation.