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:
parent
fbb533b3e0
commit
ebdb755fef
6 changed files with 144 additions and 47 deletions
|
@ -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| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue