-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix azure dall e 3 call with custom model name + Handle Bearer $LITELLM_API_KEY
in x-litellm-api-key
custom header
#10776
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f8a6105
fix(main.py): use base model instead of user model if given
krrishdholakia 1e665f8
feat(azure/image_generation/__init__.py): make azure image gen check …
krrishdholakia 40f5a93
fix(user_api_key_auth.py): support bearer token auth for `x-litellm-a…
krrishdholakia 156b100
fix(user_api_key_auth.py): refactor get api key into separate function
krrishdholakia 1b0b284
fix: cleanup
krrishdholakia 70fb39c
fix: fix linting error
krrishdholakia 77e7e09
fix: cleanup
krrishdholakia 31147b4
test: update tests
krrishdholakia d5ba366
Merge branch 'main' into litellm_dev_05_12_2025_p1
krrishdholakia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/litellm/llms/azure/image_generation/test_azure_image_generation_init.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
import os | ||
import sys | ||
import traceback | ||
from typing import Callable, Optional | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
|
||
sys.path.insert( | ||
0, os.path.abspath("../../../../..") | ||
) # Adds the parent directory to the system path | ||
import litellm | ||
from litellm.llms.azure.image_generation import ( | ||
AzureDallE3ImageGenerationConfig, | ||
get_azure_image_generation_config, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"received_model, expected_config", | ||
[ | ||
("dall-e-3", AzureDallE3ImageGenerationConfig), | ||
("dalle-3", AzureDallE3ImageGenerationConfig), | ||
("openai_dall_e_3", AzureDallE3ImageGenerationConfig), | ||
], | ||
) | ||
def test_azure_image_generation_config(received_model, expected_config): | ||
assert isinstance( | ||
get_azure_image_generation_config(received_model), expected_config | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import asyncio | ||
import json | ||
import os | ||
import sys | ||
from typing import Tuple | ||
from unittest.mock import AsyncMock, MagicMock, patch | ||
|
||
sys.path.insert( | ||
0, os.path.abspath("../../..") | ||
) # Adds the parent directory to the system path | ||
|
||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from litellm.proxy.auth.user_api_key_auth import get_api_key | ||
|
||
|
||
def test_get_api_key(): | ||
bearer_token = "Bearer sk-12345678" | ||
api_key = "sk-12345678" | ||
passed_in_key = "Bearer sk-12345678" | ||
assert get_api_key( | ||
custom_litellm_key_header=None, | ||
api_key=bearer_token, | ||
azure_api_key_header=None, | ||
anthropic_api_key_header=None, | ||
google_ai_studio_api_key_header=None, | ||
azure_apim_header=None, | ||
pass_through_endpoints=None, | ||
route="", | ||
request=MagicMock(), | ||
) == (api_key, passed_in_key) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"custom_litellm_key_header, api_key, passed_in_key", | ||
[ | ||
("Bearer sk-12345678", "sk-12345678", "Bearer sk-12345678"), | ||
("Basic sk-12345678", "sk-12345678", "Basic sk-12345678"), | ||
("bearer sk-12345678", "sk-12345678", "bearer sk-12345678"), | ||
("sk-12345678", "sk-12345678", "sk-12345678"), | ||
], | ||
) | ||
def test_get_api_key_with_custom_litellm_key_header( | ||
custom_litellm_key_header, api_key, passed_in_key | ||
): | ||
assert get_api_key( | ||
custom_litellm_key_header=custom_litellm_key_header, | ||
api_key=None, | ||
azure_api_key_header=None, | ||
anthropic_api_key_header=None, | ||
google_ai_studio_api_key_header=None, | ||
azure_apim_header=None, | ||
pass_through_endpoints=None, | ||
route="", | ||
request=MagicMock(), | ||
) == (api_key, passed_in_key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Copilot Autofix
AI 1 day ago
To fix the issue, we should avoid logging sensitive data directly. Instead, we can log a sanitized or generic version of the
model
string that excludes any sensitive information. This can be achieved by masking or redacting sensitive parts of the string before logging. Alternatively, we can log a generic message without including themodel
value.In this case, we will redact the
model
string by replacing it with a sanitized version that removes any sensitive content. This ensures that no sensitive data is exposed in the logs while maintaining the usefulness of the log message.