fix(gemini): resolve 404 by defaulting Gemini 3+ to v1 endpoint
- Update get_base_url to prefer v1 for Gemini 3.0+ models even if they contain 'preview'. - Add tracing::debug logs for the final API URLs used in both streaming and non-streaming requests.
This commit is contained in:
@@ -439,9 +439,11 @@ impl GeminiProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Determine the appropriate base URL for the model.
|
/// Determine the appropriate base URL for the model.
|
||||||
/// "preview" models often require the v1beta endpoint.
|
/// "preview" models often require the v1beta endpoint, but newer promoted ones may be on v1.
|
||||||
fn get_base_url(&self, model: &str) -> String {
|
fn get_base_url(&self, model: &str) -> String {
|
||||||
if model.contains("preview") || model.contains("thinking") {
|
// Only use v1beta for older preview models or specific "thinking" experimental models.
|
||||||
|
// Gemini 3.0+ models are typically released on v1 even in preview.
|
||||||
|
if (model.contains("preview") && !model.contains("gemini-3")) || model.contains("thinking") {
|
||||||
self.config.base_url.replace("/v1", "/v1beta")
|
self.config.base_url.replace("/v1", "/v1beta")
|
||||||
} else {
|
} else {
|
||||||
self.config.base_url.clone()
|
self.config.base_url.clone()
|
||||||
@@ -512,6 +514,7 @@ impl super::Provider for GeminiProvider {
|
|||||||
|
|
||||||
let base_url = self.get_base_url(&model);
|
let base_url = self.get_base_url(&model);
|
||||||
let url = format!("{}/models/{}:generateContent", base_url, model);
|
let url = format!("{}/models/{}:generateContent", base_url, model);
|
||||||
|
tracing::debug!("Calling Gemini API: {}", url);
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
@@ -657,6 +660,7 @@ impl super::Provider for GeminiProvider {
|
|||||||
"{}/models/{}:streamGenerateContent?alt=sse",
|
"{}/models/{}:streamGenerateContent?alt=sse",
|
||||||
base_url, model,
|
base_url, model,
|
||||||
);
|
);
|
||||||
|
tracing::debug!("Calling Gemini Stream API: {}", url);
|
||||||
|
|
||||||
// (no fallback_request needed here)
|
// (no fallback_request needed here)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user