pub struct LlmConfig {
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,
}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).
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 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.