feat(providers): add warmup() for OpenAI, Anthropic, Gemini, Compatible, GLM

All five providers have HTTP clients but did not implement warmup(),
relying on the trait default no-op. This adds lightweight warmup calls
to establish TLS + HTTP/2 connection pools on startup, reducing
first-request latency. Each warmup is skipped when credentials are
absent, matching the OpenRouter pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Edvard 2026-02-17 18:55:05 -05:00 committed by Chummy
parent a85a4a8194
commit 1336c2f03e
5 changed files with 114 additions and 0 deletions

View file

@ -396,6 +396,27 @@ impl Provider for GeminiProvider {
.and_then(|p| p.text)
.ok_or_else(|| anyhow::anyhow!("No response from Gemini"))
}
async fn warmup(&self) -> anyhow::Result<()> {
if let Some(auth) = self.auth.as_ref() {
let url = if auth.is_api_key() {
format!(
"https://generativelanguage.googleapis.com/v1beta/models?key={}",
auth.credential()
)
} else {
"https://generativelanguage.googleapis.com/v1beta/models".to_string()
};
let mut request = self.client.get(&url);
if let GeminiAuth::OAuthToken(token) = auth {
request = request.bearer_auth(token);
}
request.send().await?.error_for_status()?;
}
Ok(())
}
}
#[cfg(test)]
@ -665,4 +686,11 @@ mod tests {
assert!(response.error.is_some());
assert_eq!(response.error.unwrap().message, "Invalid API key");
}
#[tokio::test]
async fn warmup_without_key_is_noop() {
let provider = GeminiProvider::new(None);
let result = provider.warmup().await;
assert!(result.is_ok());
}
}