diff --git a/crates/anthropic/src/anthropic.rs b/crates/anthropic/src/anthropic.rs index 28e306d314..1dd447a1c9 100644 --- a/crates/anthropic/src/anthropic.rs +++ b/crates/anthropic/src/anthropic.rs @@ -148,8 +148,13 @@ impl Model { } } + pub const DEFAULT_BETA_HEADERS: &[&str] = &["prompt-caching-2024-07-31"]; + pub fn beta_headers(&self) -> String { - let mut headers = vec!["prompt-caching-2024-07-31".to_string()]; + let mut headers = Self::DEFAULT_BETA_HEADERS + .into_iter() + .map(|header| header.to_string()) + .collect::>(); if let Self::Custom { extra_beta_headers, .. @@ -186,12 +191,14 @@ pub async fn complete( request: Request, ) -> Result { let uri = format!("{api_url}/v1/messages"); - let model = Model::from_id(&request.model)?; + let beta_headers = Model::from_id(&request.model) + .map(|model| model.beta_headers()) + .unwrap_or_else(|_err| Model::DEFAULT_BETA_HEADERS.join(",")); let request_builder = HttpRequest::builder() .method(Method::POST) .uri(uri) .header("Anthropic-Version", "2023-06-01") - .header("Anthropic-Beta", model.beta_headers()) + .header("Anthropic-Beta", beta_headers) .header("X-Api-Key", api_key) .header("Content-Type", "application/json"); @@ -302,12 +309,14 @@ pub async fn stream_completion_with_rate_limit_info( stream: true, }; let uri = format!("{api_url}/v1/messages"); - let model = Model::from_id(&request.base.model)?; + let beta_headers = Model::from_id(&request.base.model) + .map(|model| model.beta_headers()) + .unwrap_or_else(|_err| Model::DEFAULT_BETA_HEADERS.join(",")); let request_builder = HttpRequest::builder() .method(Method::POST) .uri(uri) .header("Anthropic-Version", "2023-06-01") - .header("Anthropic-Beta", model.beta_headers()) + .header("Anthropic-Beta", beta_headers) .header("X-Api-Key", api_key) .header("Content-Type", "application/json"); let serialized_request =