From bc0c5b5ba73401f1a00708449ac46bb0c3fe7830 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 3 Sep 2026 01:40:53 -0700 Subject: [PATCH] test(main): assert an explicit api_key still outranks the provider-scoped one in speech() --- tests/test_litellm/test_main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py index 7e2bc3dbe30..4e40903a3bb 100644 --- a/tests/test_litellm/test_main.py +++ b/tests/test_litellm/test_main.py @@ -3332,3 +3332,22 @@ def test_speech_azure_sends_the_provider_scoped_key(monkeypatch: pytest.MonkeyPa assert response.content == b"ID3\x04\x00\x00\x00fake-mp3-payload" assert len(received) == 1 assert received[0]["api-key"] == "azure-ai-scoped-key" + + +def test_speech_keeps_an_explicitly_passed_api_key_over_the_provider_scoped_one(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setattr(litellm, "api_key", None) + monkeypatch.setattr(litellm, "openai_key", None) + monkeypatch.setattr(litellm, "api_base", None) + monkeypatch.setenv("HOSTED_VLLM_API_KEY", "hosted-vllm-scoped-key") + + with _recording_tts_server() as (api_base, received): + litellm.speech( + model="hosted_vllm/tts-1", + input="which key goes out", + voice="alloy", + api_base=api_base, + api_key="caller-supplied-key", + ) + + assert len(received) == 1 + assert received[0]["authorization"] == "Bearer caller-supplied-key"