Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(ai): omit store for Gemini compatible endpoint (#6538)

Louis Beaumont8cb9c763a216
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
index 1d5b709d2..2e36ef51a 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs
@@ -7319,6 +7319,18 @@ error: InstallFailed extracting tarball"#;
assert_eq!(providers["custom"]["headers"]["User-Agent"], "screenpipe");
}
+ #[tokio::test]
+ async fn test_build_models_json_gemini_disables_store() {
+ let mut pc = make_provider_config("custom", "gemini-3.6-flash");
+ pc.url = "https://generativelanguage.googleapis.com/v1beta/openai/".to_string();
+ let config = build_models_json(None, Some(&pc)).await;
+ let custom = &config["providers"]["custom"];
+ let model = &custom["models"][0];
+
+ assert_eq!(custom["baseUrl"], pc.url);
+ assert_eq!(model["compat"]["supportsStore"], false);
+ }
+
#[tokio::test]
async fn test_build_models_json_repairs_ai_genesis_custom_url() {
for base_url in ["https://ai.ai-genesis.app", "https://api.ai-genesis.app/"] {
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 7aad84fd3..931308ead 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -28,6 +28,7 @@ const PI_INSTALL_ARGS: [&str; 5] = [
"@anthropic-ai/sdk",
];
const CUSTOM_PROVIDER_USER_AGENT: &str = "screenpipe";
+const GEMINI_OPENAI_BASE_URL: &str = "https://generativelanguage.googleapis.com/v1beta/openai";
const DEFAULT_CLOUD_MAX_OUTPUT_TOKENS: u64 = 32_000;
/// Apply compatibility settings required by OpenAI-compatible custom endpoints.
@@ -42,9 +43,18 @@ const DEFAULT_CLOUD_MAX_OUTPUT_TOKENS: u64 = 32_000;
/// origin both serve non-API routes at `/`. Older presets commonly saved one of
/// those bare origins; repair only those proven aliases instead of guessing that
/// every custom provider uses `/v1`.
+///
+/// Google's Gemini OpenAI-compatible endpoint rejects the optional `store`
+/// request field. Pi otherwise sends `store: false` for standard-compatible
+/// providers, so disable that capability on each Gemini model while preserving
+/// any other explicit compatibility overrides.
pub fn apply_custom_provider_compat(provider: &mut serde_json::Value) {
- if let Some(base_url) = provider.get_mut("baseUrl").and_then(|value| value.as_str()) {
- let trimmed = base_url.trim().trim_end_matches('/');
+ let normalized_base_url = provider
+ .get("baseUrl")
+ .and_then(serde_json::Value::as_str)
+ .map(|base_url| base_url.trim().trim_end_matches('/').to_string());
+
+ if let Some(trimmed) = normalized_base_url.as_deref() {
if trimmed.eq_ignore_ascii_case("https://ai.ai-genesis.app")
|| trimmed.eq_ignore_ascii_case("https://api.ai-genesis.app")
{
@@ -70,6 +80,35 @@ pub fn apply_custom_provider_compat(provider: &mut serde_json::Value) {
{
headers.insert("User-Agent".to_string(), json!(CUSTOM_PROVIDER_USER_AGENT));
}
+
+ let is_gemini_openai = normalized_base_url
+ .as_deref()
+ .is_some_and(|base_url| base_url.eq_ignore_ascii_case(GEMINI_OPENAI_BASE_URL));
+ if !is_gemini_openai {
+ return;
+ }
+
+ let Some(models) = provider_object
+ .get_mut("models")
+ .and_then(serde_json::Value::as_array_mut)
+ else {
+ return;
+ };
+ for model in models {
+ let Some(model_object) = model.as_object_mut() else {
+ continue;
+ };
+ let compat = model_object
+ .entry("compat".to_string())
+ .or_insert_with(|| json!({}));
+ if !compat.is_object() {
+ *compat = json!({});
+ }
+ compat
+ .as_object_mut()
+ .expect("custom provider model compat was initialized as an object")
+ .insert("supportsStore".to_string(), json!(false));
+ }
}
/// Windows creation flags for background agent spawns: CREATE_NO_WINDOW
@@ -5214,11 +5253,35 @@ mod tests {
}
}
+ #[test]
+ fn custom_provider_compat_disables_store_for_gemini_openai_endpoint() {
+ let mut provider = json!({
+ "baseUrl": "https://generativelanguage.googleapis.com/v1beta/openai/",
+ "models": [
+ {
+ "id": "gemini-3.1-flash-lite",
+ "compat": {"maxTokensField": "max_tokens"}
+ },
+ {"id": "gemini-3.6-flash"}
+ ]
+ });
+ apply_custom_provider_compat(&mut provider);
+
+ assert_eq!(provider["models"][0]["compat"]["supportsStore"], false);
+ assert_eq!(
+ provider["models"][0]["compat"]["maxTokensField"],
+ "max_tokens"
+ );
+ assert_eq!(provider["models"][1]["compat"]["supportsStore"], false);
+ assert_eq!(provider["headers"]["User-Agent"], "screenpipe");
+ }
+
#[test]
fn custom_provider_compat_preserves_generic_urls_and_explicit_user_agents() {
let mut provider = json!({
"baseUrl": "https://proxy.example.com/openai/",
- "headers": {"user-agent": "my-client", "x-tenant": "tenant-1"}
+ "headers": {"user-agent": "my-client", "x-tenant": "tenant-1"},
+ "models": [{"id": "my-model"}]
});
apply_custom_provider_compat(&mut provider);
@@ -5226,6 +5289,7 @@ mod tests {
assert_eq!(provider["headers"]["user-agent"], "my-client");
assert_eq!(provider["headers"]["x-tenant"], "tenant-1");
assert_eq!(provider["headers"].as_object().unwrap().len(), 2);
+ assert!(provider["models"][0].get("compat").is_none());
}
#[tokio::test]