Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(llm): allow overriding Gemini provider base URL

Adham Lucas da Silva Oliveira6082fb69413f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 96ae8332..f4f23382 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+- The `gemini` LLM provider now respects the `LLM_BASE_URL` configuration value.
+ Previously, the base URL was hardcoded to `generativelanguage.googleapis.com`.
+ This allows using self-hosted, local Gemini-compatible models (like Gemma 3 hosted via Litert) that expect the native `/v1beta/models/...:generateContent` payload shape.
+
## [1.30.0] - 2026-08-21
### Fixed
diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rs
index c14d5ba8..239a5658 100644
--- a/crates/ai-memory-cli/src/config.rs
+++ b/crates/ai-memory-cli/src/config.rs
@@ -2038,3 +2038,35 @@ mod tests {
assert_eq!(provider.provider, ProviderChoice::AnthropicOAuth);
}
}
+
+#[test]
+fn llm_provider_config_passes_base_url_to_gemini() {
+ let cfg = Config {
+ llm_provider: Some("gemini".into()),
+ llm_base_url: Some("http://localhost:9379".into()),
+ runtime_env: RuntimeEnv {
+ gemini_api_key: Some(SecretString::from("dummy")),
+ ..RuntimeEnv::default()
+ },
+ ..Config::default()
+ };
+ let provider = cfg.llm_provider_config().unwrap().unwrap();
+ assert_eq!(provider.provider, ProviderChoice::Gemini);
+ assert_eq!(provider.base_url.as_deref(), Some("http://localhost:9379"));
+}
+
+#[test]
+fn llm_provider_config_gemini_uses_default_base_url_when_none_provided() {
+ let cfg = Config {
+ llm_provider: Some("gemini".into()),
+ llm_base_url: None, // Explicitly None
+ runtime_env: RuntimeEnv {
+ gemini_api_key: Some(SecretString::from("dummy")),
+ ..RuntimeEnv::default()
+ },
+ ..Config::default()
+ };
+ let provider = cfg.llm_provider_config().unwrap().unwrap();
+ assert_eq!(provider.provider, ProviderChoice::Gemini);
+ assert_eq!(provider.base_url, None);
+}
diff --git a/crates/ai-memory-llm/src/factory.rs b/crates/ai-memory-llm/src/factory.rs
index 90130840..89c1511d 100644
--- a/crates/ai-memory-llm/src/factory.rs
+++ b/crates/ai-memory-llm/src/factory.rs
@@ -247,9 +247,11 @@ pub fn build_provider(config: ProviderConfig) -> LlmResult<Arc<dyn LlmProvider>>
}
ProviderChoice::Gemini => {
let key = config.auth.require_api_key()?;
- Ok(Arc::new(
- GeminiProvider::new(key, config.model)?.with_timeout_secs(timeout),
- ))
+ let mut provider = GeminiProvider::new(key, config.model)?;
+ if let Some(url) = config.base_url {
+ provider = provider.with_base_url(url);
+ }
+ Ok(Arc::new(provider.with_timeout_secs(timeout)))
}
ProviderChoice::OpenAiCompat => {
let base = config