pub struct Request {Show 16 fields
pub provider: Provider,
pub api_key: String,
pub base_url: String,
pub model: String,
pub system_message: Option<String>,
pub messages: Vec<Message>,
pub reminder: Option<String>,
pub tools: Vec<ToolDefinition>,
pub tool_choice: Option<ToolChoice>,
pub temperature: Option<f32>,
pub max_tokens: Option<u32>,
pub reasoning_effort: Option<ReasoningEffort>,
pub response_format: Option<ResponseFormat>,
pub extra_body: Map<String, Value>,
pub max_retries: u32,
pub retry_delay_ms: u64,
}Expand description
A self-contained, provider-agnostic chat-completion request.
Carries everything needed to hit an LLM API: provider, credentials, model, messages, tools, and tuning parameters.
Call stream() or complete() with
a shared reqwest::Client to send the request.
Fields§
§provider: ProviderWhich provider to use.
api_key: StringAPI key / token.
base_url: StringBase URL override. If empty, uses Provider::default_base_url.
model: StringModel identifier (e.g. "deepseek-chat", "gpt-4o").
system_message: Option<String>Optional system prompt.
messages: Vec<Message>Conversation history.
reminder: Option<String>Dynamic runtime context appended after the stable conversation prefix.
tools: Vec<ToolDefinition>Tools the model may call.
tool_choice: Option<ToolChoice>How the model should select tools.
temperature: Option<f32>Sampling temperature.
max_tokens: Option<u32>Maximum tokens to generate.
reasoning_effort: Option<ReasoningEffort>Reasoning effort hint. None means leave provider default in place;
Some(ReasoningEffort::None) explicitly disables thinking on providers
that support it.
response_format: Option<ResponseFormat>Constrain the output format.
extra_body: Map<String, Value>Arbitrary extra top-level JSON fields merged into the provider’s
raw request body (e.g. prefix, thinking).
max_retries: u32Maximum retries for transient errors. Default: 3.
retry_delay_ms: u64Initial retry delay in milliseconds. Default: 1000.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(provider: Provider, api_key: impl Into<String>) -> Self
pub fn new(provider: Provider, api_key: impl Into<String>) -> Self
Create a new request for the given provider and API key.
Sets sensible defaults: provider’s default base URL and model, 3 retries with 1 s initial delay, no system prompt.
Sourcepub fn deepseek(api_key: impl Into<String>) -> Self
pub fn deepseek(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::DeepSeek, api_key).
Sourcepub fn openai(api_key: impl Into<String>) -> Self
pub fn openai(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::OpenAI, api_key).
Sourcepub fn anthropic(api_key: impl Into<String>) -> Self
pub fn anthropic(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Anthropic, api_key).
Sourcepub fn gemini(api_key: impl Into<String>) -> Self
pub fn gemini(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Gemini, api_key).
Sourcepub fn kimi(api_key: impl Into<String>) -> Self
pub fn kimi(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Kimi, api_key).
Sourcepub fn glm(api_key: impl Into<String>) -> Self
pub fn glm(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Glm, api_key).
Sourcepub fn minimax(api_key: impl Into<String>) -> Self
pub fn minimax(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Minimax, api_key).
Sourcepub fn mimo(api_key: impl Into<String>) -> Self
pub fn mimo(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Mimo, api_key).
Sourcepub fn grok(api_key: impl Into<String>) -> Self
pub fn grok(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::Grok, api_key).
Sourcepub fn openrouter(api_key: impl Into<String>) -> Self
pub fn openrouter(api_key: impl Into<String>) -> Self
Shortcut for Request::new(Provider::OpenRouter, api_key).
Sourcepub fn system_prompt(self, p: impl Into<String>) -> Self
pub fn system_prompt(self, p: impl Into<String>) -> Self
Set the system prompt.
Sourcepub fn reminder(self, p: impl Into<String>) -> Self
pub fn reminder(self, p: impl Into<String>) -> Self
Set dynamic runtime context for this request only.
Sourcepub fn tools(self, tools: Vec<ToolDefinition>) -> Self
pub fn tools(self, tools: Vec<ToolDefinition>) -> Self
Set the tool definitions.
Sourcepub fn temperature(self, t: f32) -> Self
pub fn temperature(self, t: f32) -> Self
Set the temperature.
Sourcepub fn max_tokens(self, n: u32) -> Self
pub fn max_tokens(self, n: u32) -> Self
Set the max tokens.
Sourcepub fn reasoning_effort(self, e: ReasoningEffort) -> Self
pub fn reasoning_effort(self, e: ReasoningEffort) -> Self
Set the reasoning-effort hint. ReasoningEffort::None explicitly
disables thinking on providers that support the toggle.
Sourcepub fn json_schema(
self,
name: impl Into<String>,
schema: Value,
strict: bool,
) -> Self
pub fn json_schema( self, name: impl Into<String>, schema: Value, strict: bool, ) -> Self
Constrain output to a named JSON Schema (OpenAI json_schema mode).
Use schemars::schema_for!(T) to generate the schema:
let schema = serde_json::to_value(schemars::schema_for!(MyStruct)).unwrap();
let req = Request::openai(key).json_schema("my_struct", schema, true);Sourcepub fn json(self) -> Self
pub fn json(self) -> Self
Set the response format to JSON object mode.
The model will be constrained to emit a valid JSON object. You must also instruct the model to produce JSON in your system prompt or user message — the format flag alone is not sufficient for most providers.
Sourcepub fn extra_body(self, extra: Map<String, Value>) -> Self
pub fn extra_body(self, extra: Map<String, Value>) -> Self
Merge extra JSON fields into the request body.
Sourcepub fn effective_base_url(&self) -> &str
pub fn effective_base_url(&self) -> &str
Resolve the effective base URL (custom or provider default).