@@ -2560,6 +2560,53 @@ def test_completion_anyscale_with_functions():
2560
2560
# test_completion_anyscale_with_functions()
2561
2561
2562
2562
2563
+ def test_completion_azure_extra_headers ():
2564
+ # this tests if we can pass api_key to completion, when it's not in the env.
2565
+ # DO NOT REMOVE THIS TEST. No MATTER WHAT Happens!
2566
+ # If you want to remove it, speak to Ishaan!
2567
+ # Ishaan will be very disappointed if this test is removed -> this is a standard way to pass api_key + the router + proxy use this
2568
+ from httpx import Client
2569
+ from openai import AzureOpenAI
2570
+
2571
+ from litellm .llms .custom_httpx .httpx_handler import HTTPHandler
2572
+
2573
+ http_client = Client ()
2574
+
2575
+ with patch .object (http_client , "send" , new = MagicMock ()) as mock_client :
2576
+ client = AzureOpenAI (
2577
+ azure_endpoint = os .getenv ("AZURE_API_BASE" ),
2578
+ api_version = litellm .AZURE_DEFAULT_API_VERSION ,
2579
+ api_key = os .getenv ("AZURE_API_KEY" ),
2580
+ http_client = http_client ,
2581
+ )
2582
+ try :
2583
+ response = completion (
2584
+ model = "azure/chatgpt-v-2" ,
2585
+ messages = messages ,
2586
+ client = client ,
2587
+ extra_headers = {
2588
+ "Authorization" : "my-bad-key" ,
2589
+ "Ocp-Apim-Subscription-Key" : "hello-world-testing" ,
2590
+ "api-key" : "my-bad-key" ,
2591
+ },
2592
+ )
2593
+ print (response )
2594
+ pytest .fail ("Expected this to fail" )
2595
+ except Exception as e :
2596
+ pass
2597
+
2598
+ mock_client .assert_called ()
2599
+
2600
+ print (f"mock_client.call_args: { mock_client .call_args } " )
2601
+ request = mock_client .call_args [0 ][0 ]
2602
+ print (request .method ) # This will print 'POST'
2603
+ print (request .url ) # This will print the full URL
2604
+ print (request .headers ) # This will print the full URL
2605
+ auth_header = request .headers .get ("Authorization" )
2606
+ print (auth_header )
2607
+ assert auth_header == "my-bad-key"
2608
+
2609
+
2563
2610
def test_completion_azure_key_completion_arg ():
2564
2611
# this tests if we can pass api_key to completion, when it's not in the env.
2565
2612
# DO NOT REMOVE THIS TEST. No MATTER WHAT Happens!
0 commit comments