Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bedrock throttling error mapping to match OpenAI format #6973

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions litellm/litellm_core_utils/exception_mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,9 @@ def exception_type( # type: ignore # noqa: PLR0915
message=f"BedrockException: Rate Limit Error - {error_str}",
model=model,
llm_provider="bedrock",
type="throttling_error",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't we just move this type to happen in RateLimitError init (inside exceptions.py -

class RateLimitError(openai.RateLimitError): # type: ignore

param=None,
code=429,
response=getattr(original_exception, "response", None),
)
elif (
Expand Down
6 changes: 6 additions & 0 deletions tests/proxy_unit_tests/test_configs/test_bad_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ model_list:
model: azure/azure-embedding-model
api_base: os.environ/AZURE_API_BASE
api_key: bad-key
- model_name: anthropic.claude-v2
litellm_params:
model: bedrock/anthropic.claude-v2
aws_access_key_id: bad-key
aws_secret_access_key: bad-key
aws_region_name: us-east-1

62 changes: 62 additions & 0 deletions tests/proxy_unit_tests/test_proxy_exception_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,65 @@ def test_chat_completion_exception_azure_context_window(mock_acompletion, client

except Exception as e:
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")


bedrock_throttling_error_response_dict = {
"error": {
"message": "ThrottlingException - Rate exceeded",
"type": "throttling_error",
"param": None,
"code": 429,
},
}
bedrock_throttling_error_response = Response(
status_code=429,
content=json.dumps(bedrock_throttling_error_response_dict),
)

@mock.patch(
"litellm.proxy.proxy_server.llm_router.acompletion",
return_value=bedrock_throttling_error_response,
)
def test_chat_completion_exception_bedrock_throttling(mock_acompletion, client):
try:
# Your test data
test_data = {
"model": "anthropic.claude-v2",
"messages": [
{"role": "user", "content": "hi"},
],
"max_tokens": 10,
}
response = None

response = client.post("/chat/completions", json=test_data)
print("got response from server", response)

mock_acompletion.assert_called_once_with(
**test_data,
litellm_call_id=mock.ANY,
litellm_logging_obj=mock.ANY,
request_timeout=mock.ANY,
metadata=mock.ANY,
proxy_server_request=mock.ANY,
)

json_response = response.json()

print("keys in json response", json_response.keys())

assert json_response.keys() == {"error"}

assert json_response == bedrock_throttling_error_response_dict

# make an openai client to call _make_status_error_from_response
openai_client = openai.OpenAI(api_key="anything")
openai_exception = openai_client._make_status_error_from_response(
response=response
)
print("exception from proxy", openai_exception)
assert isinstance(openai_exception, openai.RateLimitError)
print("passed exception is of type RateLimitError")

except Exception as e:
pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")