
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 01:18 PM
We're attempting to integrate Azure OpenAI's GPT-4.0-turbo model with our ServiceNow instance. Our goal is to test AI functionalities within our environment. We have obtained an API token and endpoint from Azure, and our Azure contact has whitelisted our instance's IP address.
Despite this setup, we're encountering a persistent issue. Our ServiceNow script, intended to make a POST request to the OpenAI API, consistently returns a 404 error, indicating that the resource cannot be found.
Here's the relevant part of our script: (endpoint and token are removed for security)
var openaiApiUrl = 'https://**********.openai.azure.com/'; // Replace with your OpenAI endpoint URL var openaiApiKey = 'b060f***************7d7e570e'; // Replace with your OpenAI API key // Prepare the request body var requestBody = { "model": "gpt-4.0-turbo", // Specify the model "messages": [ // Add your messages here { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." } ] }; var requestBodyString = JSON.stringify(requestBody); // Create and configure the HTTP request var httpRequest = new GlideHTTPRequest(openaiApiUrl); httpRequest.addHeader('Content-Type', 'application/json'); httpRequest.addHeader('Authorization', 'Bearer ' + openaiApiKey); // Send the request and handle the response var response = httpRequest.post(requestBodyString); // Log the response for debugging gs.info("Status Code: " + response.getStatusCode()); gs.info("Response Body: " + response.getBody());
The response we receive is: Status Code: 404 Response Body: {"error":{"code":"404","message": "Resource not found"}}
We're seeking guidance on what might be causing this issue and how to resolve it. Any insights or suggestions would be greatly appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2024 11:22 AM
Here is the fix
var resourceName = '****-open-ai-it-sn'; // *** is for security reason
var deploymentName = '****-Open-AI-IT-SN-gpt4'; // *** is for security reason
var apiKey = '50ebb8*******bbbfc495b7ecd';
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod('post');
restMessage.setEndpoint('https://' + resourceName + '.openai.azure.com/openai/deployments/' + deploymentName + '/chat/completions?api-version=2023-07-01-preview');
restMessage.setRequestHeader('Content-Type', 'application/json');
restMessage.setRequestHeader('api-key', apiKey);
var requestBody = {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is Examination in norwegian?' },
]
};
restMessage.setRequestBody(JSON.stringify(requestBody));
var response = restMessage.execute();
var responseBody = response.getBody();
gs.info(responseBody);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2024 01:15 PM
Hi, the vendor doc's appear to show endpoints that include /openai/deployments/YOUR_DEPLOYMENT_NAME
Azure OpenAI Service REST API reference - Azure OpenAI | Microsoft Learn
Have you tried any of the endpoints shown in the doc's

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2024 12:06 AM
Hi, yes we tried all of them
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2024 11:10 AM
Are transactions successful if you use Postman or similar?
As resource is not found, it implies an issue with your endpoint.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2024 11:17 AM - edited ‎01-28-2024 11:20 AM
I will post the solution with my original private account