mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-28 06:23:07 +00:00
Merge b9d9be367b into f2118fc767
This commit is contained in:
commit
e06ecb6a03
2 changed files with 26 additions and 1 deletions
|
|
@ -441,12 +441,12 @@ def _map_openai_exception(
|
|||
elif (
|
||||
"The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable"
|
||||
in error_str
|
||||
or ("Missing credentials" in error_str and "api_key" in error_str)
|
||||
):
|
||||
raise AuthenticationError(
|
||||
message=f"AuthenticationError: {exception_provider} - {message}",
|
||||
llm_provider=custom_llm_provider,
|
||||
model=model,
|
||||
response=response,
|
||||
litellm_debug_info=extra_information,
|
||||
)
|
||||
elif "Mistral API raised a streaming error" in error_str:
|
||||
|
|
|
|||
|
|
@ -508,6 +508,31 @@ def test_openai_compatible_429_still_maps_to_rate_limit():
|
|||
assert excinfo.value.status_code == 429
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error_message",
|
||||
(
|
||||
"The api_key client option must be set either by passing api_key to the client "
|
||||
"or by setting the OPENAI_API_KEY environment variable",
|
||||
"Missing credentials. Please pass an `api_key`, `workload_identity`, "
|
||||
"`admin_api_key`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` "
|
||||
"environment variable.",
|
||||
),
|
||||
)
|
||||
def test_openai_missing_credentials_maps_to_authentication_error(error_message: str) -> None:
|
||||
original_exception: Final = OpenAIError(status_code=500, message=error_message)
|
||||
|
||||
with pytest.raises(litellm.AuthenticationError) as excinfo:
|
||||
exception_type(
|
||||
model="test-model",
|
||||
original_exception=original_exception,
|
||||
custom_llm_provider="openai",
|
||||
)
|
||||
|
||||
assert excinfo.value.status_code == 401
|
||||
assert excinfo.value.response.status_code == 401
|
||||
assert excinfo.value.llm_provider == "openai"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error_message",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue