Reputation: 2628
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
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
Reputation: 41
This is all because you are not passing the correct API version, please check your api version.
Upvotes: 0
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>
resource_name
is the name of the Azure OpenAI resource.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.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
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
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:
Upvotes: 17