Accessing a Llama 3 model deployed on Azure OpenAI returns 403 "key_auth_bad_header_forbidden"

Antonio Goncalves 0 Reputation points Microsoft Employee
2024-10-24T10:01:02.2133333+00:00

I have deployed a Llama 3 model to Azure OpenAI:

Screenshot 2024-10-24 at 11.34.12

I then try to access it with the following Java code:

AzureOpenAiChatModel model = AzureOpenAiChatModel.builder()
  .apiKey(AZURE_OPENAI_KEY)
  .endpoint(AZURE_OPENAI_ENDPOINT)
  .deploymentName("llama-3-2-1b-instruct-1")
  .logRequestsAndResponses(true)
  .build();

System.out.println(model.generate("When was the first Rolling Stones album released?"));

And I get a Status code 403, "key_auth_bad_header_forbidden".

The same code works fine when I deploy an OpenAI mode (eg. GPT-4o) but doesn't with non-OpenAI models such as Llama.

I am trying to solve this issue: https://github.com/langchain4j/langchain4j/discussions/1580

Any pointers? Any idea of what could be wrong ? Do I need something else than just the API Key ? Any network config I need to setup ?

Thanks

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,081 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Fang 1,060 Reputation points MVP
    2024-10-24T11:41:25.07+00:00

    Hi, Antonio

    My feeling is that it is unlikely to work. The llama-3-2-1b-instruct-1 (any open source LLM) is deployed to *.inference.ml.azure.com that is different to the GPT models deployment as a part of Azure OpenAI service.

    Guess you used the target uri from the deployment endpoint in the format of: https://xxxxx.eastus2.inference.ml.azure.com. if you compare this with your working GPT-4o's endpoint url, you will notice the difference.

    On the other hand, the GPT-4o's request structure would be slightly different to llama 3.2's. the error you see is likely related to the authentication. If you go to Consume tab, and look at the example python code, the required auth header is a bearer header, but the AzureOpenAiChatModel would be using a api-key header.

    In short, dont believe the AzureOpenAiChatModel support llama-3-2-1b-instruct-1 model out of the box yet.

    User's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.