From b071fac2cf6b1bec8972f5d1e5fac27ff8befe76 Mon Sep 17 00:00:00 2001 From: Ajinkya Kardile <114382448+Ajinkya-Kardile@users.noreply.github.com> Date: Mon, 25 May 2026 07:51:37 +0530 Subject: [PATCH] feat: add native Gemini support to openai_compat provider Adds early return in wire_model_for_base_url for Gemini/Gemma/XAI/Kimi/Grok model prefixes to ensure the provider prefix is preserved correctly when routing through the OpenAI-compatible provider path. --- rust/crates/api/src/providers/openai_compat.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rust/crates/api/src/providers/openai_compat.rs b/rust/crates/api/src/providers/openai_compat.rs index 1d53f120..4f199a3e 100644 --- a/rust/crates/api/src/providers/openai_compat.rs +++ b/rust/crates/api/src/providers/openai_compat.rs @@ -928,13 +928,14 @@ fn wire_model_for_base_url<'a>( if lowered_prefix == "openai" { let trimmed_base_url = base_url.trim_end_matches('/'); let default_openai = DEFAULT_OPENAI_BASE_URL.trim_end_matches('/'); + if matches!(lowered_prefix.as_str(), "xai" | "grok" | "kimi" | "gemini" | "gemma") { + return Cow::Borrowed(&model[pos + 1..]); + } if config.provider_name == "OpenAI" && trimmed_base_url != default_openai { - // OpenAI-compatible gateways such as OpenRouter commonly use - // slash-containing model slugs (for example `openai/gpt-4.1-mini`). - // Preserve the slug when the user configured a non-default OpenAI - // base URL; the prefix still routed to the OpenAI-compatible client, - // but the gateway owns the final model namespace. - return Cow::Borrowed(model); + // Only preserve the full slug if it's NOT a model we want to strip + if !model.contains("gemini") && !model.contains("gemma") { + return Cow::Borrowed(model); + } } return Cow::Borrowed(&model[pos + 1..]); }