litellm icon indicating copy to clipboard operation
litellm copied to clipboard

[Bug]: Azure OpenAI - Sora 2 Model Authentication Error

Open zolgear opened this issue 1 month ago • 1 comments

What happened?

ref: #15992

API calls to the sora-2 model return the error:
401 Client Error: Unauthorized for url: http://litellm:4000/v1/videos

Debug log from Azure's error response:
{"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}

It depends on the environment variable AZURE_API_KEY and does not support credential_list or similar.
Same issue as #10868.


Example of a model definition that returned an error in the debug log (different environment variables):

model_list:
  - model_name: sora-2
    litellm_params:
      model: azure/sora-2
      api_version: "preview"
      rpm: 1
      api_key: os.environ/AZURE_API_KEY_XXX
      api_base: os.environ/AZURE_API_BASE_XXX
    model_info:
      mode: video_generation
      base_model: azure/sora-2

Model definition confirmed to work correctly:

model_list:
  - model_name: sora-2
    litellm_params:
      model: azure/sora-2
      api_version: "preview"
      rpm: 1
      api_key: os.environ/AZURE_API_KEY
      api_base: os.environ/AZURE_API_BASE
    model_info:
      mode: video_generation
      base_model: azure/sora-2

Relevant log output

06:37:50 - LiteLLM Router:INFO: simple_shuffle.py:55 - get_available_deployment for model: sora-2, Selected deployment: {'model_name': 'sora-2', 'litellm_params': {'api_version': '2025-04-01-preview', 'rpm': 1, 'litellm_credential_name': 'azure_xxxxxxxxx_credential', 'use_in_pass_through': False, 'use_litellm_proxy': False, 'merge_reasoning_content_in_choices': False, 'model': 'azure/sora-2'}, 'model_info': {'id': 'xxxxxxxxxxxxxxxxxxxxx', 'db_model': False, 'base_model': 'azure/sora-2', 'mode': 'video_generation'}} for model: sora-2
06:37:51 - LiteLLM Router:INFO: router.py:2913 - ageneric_api_call_with_fallbacks(model=sora-2) Exception litellm.AuthenticationError: AzureException AuthenticationError - {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}
06:37:51 - LiteLLM Router:INFO: router.py:3876 - Trying to fallback b/w models
06:37:51 - LiteLLM Proxy:ERROR: common_request_processing.py:699 - litellm.proxy.proxy_server._handle_llm_api_exception(): Exception occured - litellm.AuthenticationError: AzureException AuthenticationError - {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}. Received Model Group=sora-2
Available Model Group Fallbacks=None
Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/llm_http_handler.py", line 4179, in async_video_generation_handler
    response = await async_httpx_client.post(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/logging_utils.py", line 190, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/http_handler.py", line 403, in post
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/http_handler.py", line 359, in post
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://xxxxxxxxxx.openai.azure.com/openai/v1/videos?api-version=2025-04-01-preview'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/videos/main.py", line 96, in avideo_generation
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/llm_http_handler.py", line 4195, in async_video_generation_handler
    raise self._handle_error(
          ~~~~~~~~~~~~~~~~~~^
        e=e,
        ^^^^
        provider_config=video_generation_provider_config,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/llm_http_handler.py", line 3517, in _handle_error
    raise provider_config.get_error_class(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        error_message=error_text,
        ^^^^^^^^^^^^^^^^^^^^^^^^^
        status_code=status_code,
        ^^^^^^^^^^^^^^^^^^^^^^^^
        headers=error_headers,
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/openai/videos/transformation.py", line 376, in get_error_class
    raise BaseLLMException(
    ...<3 lines>...
    )
litellm.llms.base_llm.chat.transformation.BaseLLMException: {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/litellm/proxy/video_endpoints/endpoints.py", line 76, in video_generation
    return await processor.base_process_llm_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<16 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/proxy/common_request_processing.py", line 494, in base_process_llm_request
    responses = await llm_responses
                ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 3745, in async_wrapper
    return await self._ageneric_api_call_with_fallbacks(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 2808, in _ageneric_api_call_with_fallbacks
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 2795, in _ageneric_api_call_with_fallbacks
    response = await self.async_function_with_fallbacks(**kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4072, in async_function_with_fallbacks
    return await self.async_function_with_fallbacks_common_utils(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<8 lines>...
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4030, in async_function_with_fallbacks_common_utils
    raise original_exception
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4064, in async_function_with_fallbacks
    response = await self.async_function_with_retries(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4186, in async_function_with_retries
    self.should_retry_this_error(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        error=e,
        ^^^^^^^^
    ...<4 lines>...
        content_policy_fallbacks=content_policy_fallbacks,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4380, in should_retry_this_error
    raise error  # then raise error
    ^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4160, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 4280, in make_call
    response = await response
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 2918, in _ageneric_api_call_with_fallbacks_helper
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/router.py", line 2899, in _ageneric_api_call_with_fallbacks_helper
    response = await response  # type: ignore
               ^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1637, in wrapper_async
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1483, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/videos/main.py", line 102, in avideo_generation
    raise litellm.exception_type(
          ~~~~~~~~~~~~~~~~~~~~~~^
        model=model,
        ^^^^^^^^^^^^
    ...<3 lines>...
        extra_kwargs=kwargs,
        ^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2274, in exception_type
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2059, in exception_type
    raise AuthenticationError(
    ...<5 lines>...
    )
litellm.exceptions.AuthenticationError: litellm.AuthenticationError: AzureException AuthenticationError - {"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}. Received Model Group=sora-2
Available Model Group Fallbacks=None
INFO:     xxx.xx.x.x:51720 - "POST /v1/videos HTTP/1.1" 401 Unauthorized

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.79.1-stable

Twitter / LinkedIn details

No response

zolgear avatar Nov 13 '25 08:11 zolgear

I just found a workaround like this

from litellm import video_generation

API_BASE = ""
API_KEY = ""

resp = video_generation(
    model="azure/sora-2",
    prompt="A video of a cat",
    seconds="4",
    size="720x1280",
    api_base=API_BASE,
    extra_headers={
        "Content-Type": "application/json",
        "Api-key": API_KEY,
    },
)

print(resp)

tqtensor avatar Nov 22 '25 22:11 tqtensor

@zolgear @tqtensor Can you test code the endpoint with the code in the above PR? Will help to resolve the issue quickly

Sameerlite avatar Nov 24 '25 02:11 Sameerlite

It works @Sameerlite

tqtensor avatar Nov 24 '25 07:11 tqtensor

Sorry for the late response.

I tested using the image ghcr.io/berriai/litellm:litellm_bedrock_openai_imported_model-v1.80.5.dev1.

The authentication error issue that was occurring when not using environment variables and when using credential_list has been resolved.

zolgear avatar Nov 26 '25 02:11 zolgear