azureopenai-apiazure-openai

Azure OpenAI Ingesion Job API returns 404 Resource not found


Im following the documentation from Azure on the ingestion job API here: https://learn.microsoft.com/en-us/rest/api/azureopenai/ingestion-jobs/create?view=rest-azureopenai-2024-07-01-preview&tabs=HTTP

No matter the body of my request or the api-key in the request headers, I get { error: { code: '404', message: 'Resource not found' } } from the server. The endpoint im using is the one found in the Azure portal under Azure OpenAI resource -> Resource Management -> Keys and Endpoints -> Endpoint. The Azure OpenAI resource is deployed in Sweden Central.

Here is my request code:

const jobId = 'testing2793619'; // The ID of the job to be created

    const url = `${openaiEndpoint}/openai/ingestion/jobs/${jobId}?api-version=2024-07-01-preview`;

    const requestBody = {
        kind: "SystemCompute",
        searchServiceConnection: {
            kind: "EndpointWithKey",
            endpoint: searchEndpoint, // Replace with your Azure AI Search service endpoint,
            key: searchAdminApiKey // Replace with your Azure AI Search admin API key
        },
        datasource: {
            kind: "Storage", 
            connection: {
                kind: "ConnectionString",
                connectionString: blobStorageConnectionString
            },
            containerName: "testcontainer",
            chunking: {
                maxChunkSizeInTokens: 2048 // Customize as needed
            }
        },
        dataRefreshIntervalInHours: 24, // Customize as needed
        completionAction: "cleanUpTempAssets" // or "cleanUpTempAssets" depending on your needs
    };

    try {
        const response = await fetch(url, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json',
                'api-key': openaiApiKey
            },
            body: JSON.stringify(requestBody)
        });

        if (response.ok) {
            const data = await response.json();
            console.log('Request successful:', data);
            return data;
        } else {
            const errorData = await response.json();
            console.error('Request failed ingestion:', errorData);
        }
    } catch (error) {
        console.error('Error:', error);
    }

Solution

  • The 404 Resource not found error occurs when trying to create an ingestion job using the Azure OpenAI Ingestion Job API due to an invalid endpoint URL and API key.

    Below is how we configure the endpoint URL and API key:

    async function createIngestionJob() {
        const endpoint = "https://AzureOpenapiName.openai.azure.com"; 
        const jobId = "ingestion-job"; // Replace with your job ID
        const apiVersion = "2024-07-01-preview";
    
     try {
            const response = await axios.put(
                `${endpoint}/openai/ingestion/jobs/${jobId}?api-version=${apiVersion}`,
                requestBody,
                { headers }
            );
    
      const headers = {
            'api-key': 'YOUR_API_KEY', 
            'Content-Type': 'application/json'
        };
    

    The javascript code below is for creation of an ingestion job using the Azure OpenAI Service with an endpoint and API version.

    const axios = require('axios');
    
    async function createIngestionJob() {
        const endpoint ="https://AzureOpenapiName.openai.azure.com"; 
        const jobId = "ingestion-job"; // Replace with your job ID
        const apiVersion = "2024-07-01-preview";
    
      
        const headers = {
            'api-key': 'YOUR_API_KEY', 
            'Content-Type': 'application/json',
            'mgmt-user-token': 'YOUR_MGMT_USER_TOKEN', // If required
            'aml-user-token': 'YOUR_AML_USER_TOKEN'    // If required
        };
        const requestBody = {
            "kind": "SystemCompute",
            "searchServiceConnection": {
                "kind": "EndpointWithManagedIdentity",
                "endpoint": "https://aykame-dev-search.search.windows.net"
            },
            "datasource": {
                "kind": "Storage",
                "connection": {
                    "kind": "EndpointWithManagedIdentity",
                    "endpoint": "https://mystorage.blob.core.windows.net/",
                    "resourceId": "/subscriptions/1234567-abcd-1234-5678-1234abcd/resourceGroups/my-resource/providers/Microsoft.Storage/storageAccounts/mystorage"
                },
                "containerName": "container",
                "chunking": {
                    "maxChunkSizeInTokens": 2048
                },
                "embeddings": [
                    {
                        "connection": {
                            "kind": "RelativeConnection"
                        },
                        "deploymentName": "Ada"
                    }
                ]
            },
            "dataRefreshIntervalInHours": 24,
            "completionAction": "keepAllAssets"
        };
    
        try {
            const response = await axios.put(
                `${endpoint}/openai/ingestion/jobs/${jobId}?api-version=${apiVersion}`,
                requestBody,
                { headers }
            );
            
            console.log('Ingestion job created successfully:', response.data);
            console.log('Operation location:', response.headers['operation-location']);
        } catch (error) {
            console.error('Error creating ingestion job:', error.response.data);
        }
    }
    
    createIngestionJob();
    
    

    enter image description here