Unable to use new API for Document Intelligence

Ritesh Panditi 15 Reputation points
2024-04-02T01:11:14.2+00:00

I am trying out the code in this link with a valid key and endpoint Layout model sample code, but I am getting an error message. I am unable to understand what is the reason for this error as I am using the sample document in the sample code to test it out. When I try the same with a previous version as shown in Another sample code but with GA API
it seems to work fine. But the features I want to use are available in the new preview API. Please let me know how I can resolve this error.

Inner error: {

"code": "ParameterMissing",

"message": "The parameter urlSource or base64Source is required."

}

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,100 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Сергій Ткаченко 0 Reputation points
    2024-09-02T11:51:56.8266667+00:00

    This code worked for me.

    from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.documentintelligence import DocumentIntelligenceClient
    
    def recognize_text(file_path):
        client = DocumentIntelligenceClient(
            endpoint=DOCS_ENDPOINT,
            credential=AzureKeyCredential(DOCS_API_KEY)
        )
    
        with open(file_path, "rb") as file:
            file_bytes = file.read()
            poller = client.begin_analyze_document(
                "prebuilt-read",
                AnalyzeDocumentRequest(bytes_source=file_bytes))
            result = poller.result()
    
        resulted_text = ""
        for page in result.pages:
            for line in page.lines:
                resulted_text += line.content + "\n"
    
        return resulted_text.strip()
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.