Search code examples
azureazure-openai

Azure Document Intelligence Custom Classification Python API


I am making 2 API calls using Python.

url_1 = "https://XXX.cognitiveservices.azure.com/documentintelligence/documentModels/prebuilt-read:analyze?api-version=2024-07-31-preview"
url_2 = "https://XXX.cognitiveservices.azure.com/documentintelligence/documentModels/myModelID:analyze?api-version=2024-07-31-preview"
url = url_1

payload = {}
files=[
  ('',('DOC130924-162130.pdf',open('DOC130924-162130.pdf','rb'),'application/pdf'))
]
headers = { 'Ocp-Apim-Subscription-Key': 'XXX' }

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.headers)
print(response)
print(response.text)

url_1 works fine and I get 202 response. But for url_2 i get 'The requested model was not found'.

I have only 1 custom classification model and the status is successful from model training. I tested from Azure Document Intelligence Studio and it seems to work fine but not from Python code. Please help.

enter image description here


Solution

  • Finally fixed it. The URL should include "documentClassifiers" and NOT "documentModels". For custom document classification, use "documentClassifiers". For custom document extraction, use "documentModels". Since Azure Portal does not provide the Python SDK code (at the moment), you will need to dig into the below documentation to find the correct URL.

    https://learn.microsoft.com/en-us/rest/api/aiservices/document-classifiers/classify-document?view=rest-aiservices-v4.0%20(2024-07-31-preview)&viewFallbackFrom=rest-aiservices-2023-07-31&tabs=HTTP