Surface upstream rate limits from Anthropic (#16118)
This PR makes it so hitting upstream rate limits from Anthropic result in an HTTP 429 response instead of an HTTP 500. To do this we need to surface structured errors out of the `anthropic` crate. Release Notes: - N/A
This commit is contained in:
@@ -197,7 +197,20 @@ async fn perform_completion(
|
||||
request,
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
.await
|
||||
.map_err(|err| match err {
|
||||
anthropic::AnthropicError::ApiError(ref api_error) => {
|
||||
if api_error.code() == Some(anthropic::ApiErrorCode::RateLimitError) {
|
||||
return Error::http(
|
||||
StatusCode::TOO_MANY_REQUESTS,
|
||||
"Upstream Anthropic rate limit exceeded.".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
Error::Internal(anyhow!(err))
|
||||
}
|
||||
anthropic::AnthropicError::Other(err) => Error::Internal(err),
|
||||
})?;
|
||||
|
||||
chunks
|
||||
.map(move |event| {
|
||||
|
||||
Reference in New Issue
Block a user