Raz Ronen
Raz Ronen

Reputation: 2628

Why I'm getting 404 Resource Not Found to my newly Azure OpenAI deployment?

I've gone through this quickstart and I created my Azure OpenAI resource + created a model deployment which is in state succeedded. I also playaround it in https://oai.azure.com/ and it works there.

But, If I try to reach it from REST API is returns 404 Resource Not Found. I defined the api-key header, and took the url and json from Code View -> json from inside the playground.

I'm executing

POST https://raz-openai.openai.azure.com/openai/deployments/raz-model-2/completions?api-version=2022-12-01 { "prompt": "", "max_tokens": 100 } with api-key header

Am I missing another step?

Upvotes: 18

Views: 37691

Answers (6)

Arda Zaman
Arda Zaman

Reputation: 127

I fixed the issue after I tried many solutions. If you are using @azure-rest/ai-inference to make a request, you need to update the endpoint and specify the api version properly.

import ModelClient from "@azure-rest/ai-inference";
import { AzureKeyCredential } from "@azure/core-auth";

const endpoint = `https://${AZURE_RESOURCE}/openai/deployments/${MODEL}`

const client = new ModelClient(endpoint, new AzureKeyCredential(AZURE_MODEL_KEY), { apiVersion: "2024-08-01-preview" });

const response = await client.path("/chat/completions").post({
   body: query
})

The issue was my end I copied the whole endpoint from azure portal and use it as endpoint.

No, you should follow above endpoint structure instead whole endpoint from azure and specify apiVersion.

Upvotes: 0

Surendra Ediga
Surendra Ediga

Reputation: 41

This is all because you are not passing the correct API version, please check your api version.

Upvotes: 0

Péter Szilvási
Péter Szilvási

Reputation: 2019

It looks like you forgot to add the /chat before the /completions in the URL. You can only use correctly formatted URL which looks like the following:

https://<resource_name>.openai.azure.com/openai/deployments/<model_name>/chat/completions?api-version=<api_version>
  • The resource_name is the name of the Azure OpenAI resource.
  • The model_name is the model deployment name. Go to the Azure OpenAI Studio then select the Deployments tab under the Shared resources section. The Name column will be the correct value.
  • The api_version could be either in preview release (e.g. 2024-02-15-preview) or latest GA release which, as of today, is 2024-06-01.

The most straightforward way to test is to use the curl example at the Chat > View Code tab. Taking your URL example, the command will be this:

curl "https://raz-openai.openai.azure.com/openai/deployments/raz-model-2/chat/completions?api-version=2024-06-01" \
  -H "Content-Type: application/json" \
  -H "api-key: <API_KEY>" \
  -d "{\"messages\":[{\"role\":\"system\",\"content\":[{\"type\":\"text\",\"text\":\"You are an AI assistant that helps people find information.\"}]}]}"

Provide your API key for the raz-model-2 model before the request.

Further reading and references:

Upvotes: 2

Zhanwen Chen
Zhanwen Chen

Reputation: 1463

Use the Chrome web traffic (under Network) from the Azure OpenAI studio. It works better than the official docs and the Azure OpenAI Studio UI-generated code.

Upvotes: -1

Frank Wilson
Frank Wilson

Reputation: 181

I was also getting a 404 calling the Chat Completions API (https://{resource}.openai.azure.com/openai/deployments/{deployment}/chat/completions) and it turned out that I was using the wrong version. Each model has one or more versions that can be found at Azure OpenAI Service REST API reference.

For me, hitting the chat completions (ChatGPT), the correct URL with version was:

https://{resource}.openai.azure.com/openai/deployments/{deployment}/chat/completions?api-version=2023-03-15-preview

Any other version will give a 404 Resource Not Found.

Also, here are the definitions of those variables:

  • Resource: Take from the Azure endpoint URL, which can be found on the Overview page in your OpenAI Services resource. The format should be something like https://{resource}.openai.azure.com/
  • Deployment (aka deployment-id): You can find this in the Azure portal under the Model Deployments section. Each model has a "Model Deployment Name" and this is your Deployment ID. This isn't going to be the OpenAI name (like gpt-35-turbo) but rather the name you gave it when creating the model deployment.

Upvotes: 17

Ram
Ram

Reputation: 2754

Adding as an answer use a GET request instead of POST.

Upvotes: -1

Related Questions