pub struct LlmConfig {Show 13 fields
pub model: String,
pub api_key: Option<String>,
pub base_url: Option<String>,
pub temp: f64,
pub max_tokens: Option<u32>,
pub prompt_cache_key: Option<String>,
pub project_id: Option<String>,
pub location: Option<String>,
pub use_chat_api: bool,
pub extra_headers: Vec<(String, String)>,
pub reasoning_effort: Option<String>,
pub use_genai: bool,
pub use_cli: bool,
}Expand description
LLM provider configuration — single config for any provider.
Two optional fields control routing:
api_key: None → auto from env vars (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)base_url: None → auto-detect provider from model name; Some → custom endpoint
use sgr_agent::LlmConfig;
let c = LlmConfig::auto("gpt-4o"); // env vars
let c = LlmConfig::with_key("sk-...", "claude-3-haiku"); // explicit key
let c = LlmConfig::endpoint("sk-or-...", "https://openrouter.ai/api/v1", "gpt-4o"); // custom
let c = LlmConfig::auto("gpt-4o").temperature(0.9).max_tokens(2048); // builderFields§
§model: String§api_key: Option<String>§base_url: Option<String>§temp: f64§max_tokens: Option<u32>§prompt_cache_key: Option<String>OpenAI prompt cache key — caches system prompt prefix server-side.
project_id: Option<String>Vertex AI project ID (enables Vertex routing when set).
location: Option<String>Vertex AI location (default: “global”).
use_chat_api: boolForce Chat Completions API instead of Responses API. Needed for OpenAI-compatible endpoints that don’t support /responses (e.g. Cloudflare AI Gateway compat, OpenRouter, local models).
extra_headers: Vec<(String, String)>Extra HTTP headers to include in LLM API requests.
E.g. cf-aig-request-timeout: 300000 for Cloudflare AI Gateway.
reasoning_effort: Option<String>Reasoning effort for reasoning models. “none” disables reasoning for FC. E.g. DeepInfra Nemotron Super needs “none” for function calling.
use_genai: boolForce genai backend (for providers with native API: Anthropic, Gemini). When false, oxide (OpenAI Responses API) is used by default.
use_cli: boolUse CLI subprocess backend (claude/gemini/codex -p). Tool calls emulated via text prompt + flexible parsing. Uses CLI’s own auth (subscription credits, no API key).
Implementations§
Source§impl LlmConfig
impl LlmConfig
Sourcepub fn auto(model: impl Into<String>) -> Self
pub fn auto(model: impl Into<String>) -> Self
Auto-detect provider from model name, use env vars for auth.
Sourcepub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
Explicit API key, auto-detect provider from model name.
Sourcepub fn endpoint(
api_key: impl Into<String>,
base_url: impl Into<String>,
model: impl Into<String>,
) -> Self
pub fn endpoint( api_key: impl Into<String>, base_url: impl Into<String>, model: impl Into<String>, ) -> Self
Custom OpenAI-compatible endpoint (OpenRouter, Ollama, LiteLLM, etc.).
Sourcepub fn vertex(project_id: impl Into<String>, model: impl Into<String>) -> Self
pub fn vertex(project_id: impl Into<String>, model: impl Into<String>) -> Self
Vertex AI — uses gcloud ADC for auth (no API key needed).
Sourcepub fn temperature(self, t: f64) -> Self
pub fn temperature(self, t: f64) -> Self
Set temperature.
Sourcepub fn max_tokens(self, m: u32) -> Self
pub fn max_tokens(self, m: u32) -> Self
Set max output tokens.
Sourcepub fn prompt_cache_key(self, key: impl Into<String>) -> Self
pub fn prompt_cache_key(self, key: impl Into<String>) -> Self
Set OpenAI prompt cache key for server-side system prompt caching.
Sourcepub fn apply_headers(&self, config: &mut ClientConfig)
pub fn apply_headers(&self, config: &mut ClientConfig)
Apply extra_headers to an openai-oxide ClientConfig. Used by both OxideClient and OxideChatClient.
Sourcepub fn cli(cli_model: impl Into<String>) -> Self
pub fn cli(cli_model: impl Into<String>) -> Self
CLI subprocess backend — uses claude -p / gemini -p / codex exec.
No API key needed, uses CLI’s own auth (subscription credits).
Optional model overrides the CLI’s default model via --model flag.
Sourcepub fn compaction_model(&self) -> String
pub fn compaction_model(&self) -> String
Infer a cheap/fast model for compaction based on the primary model.
Sourcepub fn for_compaction(&self) -> Self
pub fn for_compaction(&self) -> Self
Create a compaction config — cheap model, low max_tokens.