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

@ -500,6 +500,20 @@ impl Provider for AnthropicProvider {
fn supports_native_tools(&self) -> bool {
true
}
async fn warmup(&self) -> anyhow::Result<()> {
if let Some(credential) = self.credential.as_ref() {
let mut request = self
.client
.post(format!("{}/v1/messages", self.base_url))
.header("anthropic-version", "2023-06-01");
request = self.apply_auth(request, credential);
// Send a minimal request; the goal is TLS + HTTP/2 setup, not a valid response.
// Anthropic has no lightweight GET endpoint, so we accept any non-network error.
let _ = request.send().await?;
}
Ok(())
}
}
#[cfg(test)]
@ -1082,4 +1096,11 @@ mod tests {
assert!(!json.contains("cache_control"));
assert!(json.contains(r#""system":"System""#));
}
#[tokio::test]
async fn warmup_without_key_is_noop() {
let provider = AnthropicProvider::new(None);
let result = provider.warmup().await;
assert!(result.is_ok());
}
}