The Extract metadata (freeform) endpoint doesn’t support OCR. To extract metadata from image files (TIFF, PNG, JPEG) or documents in languages other than English, use the Extract metadata (structured) endpoint.
Before you start
Make sure you followed the steps listed in getting started with Box AI to create a platform app and authenticate.Send a request
To send a request, use thePOST /2.0/ai/extract endpoint.
Parameters
To make a call, you must pass the following parameters. Mandatory parameters are in bold.The
items array can have exactly one element.| Parameter | Description | Example |
|---|---|---|
prompt | The request for Box AI to generate or refine the text. The prompt’s length cannot exceed 10000 characters. | Create a meeting agenda for a weekly sales meeting. |
items.id | Box file ID of the document. The ID must reference an actual file with an extension. | 1233039227512 |
items.type | The type of the supplied input. | file |
items.content | The content of the item, often the text representation. | This article is about Box AI. |
ai_agent | The AI agent used to override the default agent configuration. This parameter allows you to, for example, replace the default LLM with a custom one using the model parameter, tweak the base prompt to allow for a more customized user experience, or change an LLM parameter, such as temperature, to make the results more or less creative. Before you use the ai_agent parameter, you can get the default configuration using the GET 2.0/ai_agent_default request. For specific use cases, see the AI model overrides tutorial. |
Use cases
This example shows you how to extract metadata from a sample invoice.Create the request
To get the response from Box AI, callPOST /2.0/ai/extract endpoint with the following parameters:
promptthat can be a query, or a structured or unstructured list of fields to extract.typeandidof the file to extract the data from.
Create the prompt
Depending on the use case and the level of detail, you can construct various prompts.Use plain text
Because this endpoint allows freeform prompts, you can use plain text to get the information.Use specific terms
If you don’t want to write the entire sentence, the prompt can consist of terms that you expect to find in an invoice:Use key-value pairs
The prompt can also be a list of key-value pairs that helps Box AI to come up with the metadata structure. This approach requires listing the key-value pairs within afields array.
fields present in the file, along with their values:
