404 Resource Not Found using OpenAI Azure gpt-4

Randy Song 0 Reputation points
2024-04-20T20:01:21.0766667+00:00

Trying to use the OpenAI Azure client for the first time (switching from openai direct), but having trouble. Here's how i instantiate my client:


            return AsyncAzureOpenAI(
                api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
                api_version="2024-01-25-preview",
                azure_deployment="NAME",
                azure_endpoint=azure_endpoint,
            )

(placeholder for deployment name)
User's image

Here's my actual deployment. I do pass in the correct azure_endpoint as well. I keep getting 404 resource not found when i try to call this. here's my code for how i use the client:


            async with get_client(model.azure) as client:
                if stream:
                    async for chunk in await client.chat.completions.create(**params):

Anyone know what's going on? Thanks

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,945 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Randy Song 0 Reputation points
    2024-04-21T02:48:19.03+00:00

    Found the answer. The problem was actually in the request params. Normally, openai expects a model name to be passed in for model like

    gpt-4-1106-preview
    

    But in the case of azure, it expects the given model name in your deployment, so whatever name you wrote down for the deployment should be passed in here.

    
        params = {
            "model": model.name, // NAME IN AZURE
            "messages": chat_messages,
            "max_tokens": model_max_tokens,
            "temperature": temperature,
            "stream": stream,
        }
    
    0 comments No comments

  3. YutongTie-MSFT 50,866 Reputation points
    2024-04-21T04:13:57.91+00:00

    @Randy Song

    Thanks for reaching out to us and sharing the workaround for this issue. Please let us know if you have any other issues. Please feel free to open a new thread if needed.

    I will remove the duplicate posts.

    Thanks again.

    Regards,

    Yutong

    0 comments No comments

  4. John Moto 41 Reputation points
    2024-09-18T21:10:12.4233333+00:00

    To anyone else finding this issue later, I had an issue with always getting a "HTTP 404 Resource not found" error specifically after upgrading to the "Azure.AI.OpenAI" Nuget package version "2.0.0-beta.5". In the new version of the Nuget package, I was trying to outright create a new AssistantClient and passing in my endpoint and API key. But apparently, you have to first create an AzureOpenAIClient , then create an AssistantClient (or whatever other client you need), like this:

    var azureOpenAIClient = new AzureOpenAIClient(myEndpointUri, myApiKey);
    var assistantClient = azureOpenAIClient.GetAssistantClient();
    var chatClient = azureOpenAIClient.GetChatClient("gpt-4o");
    
    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.