Use the POST /ai/extract endpoint to extract metadata from documents using natural language prompts.
Box AI API allows you to query a document and extract metadata based on a provided prompt.
Freeform means that the prompt can include a stringified version of formats such as JSON or XML, or even plain text.
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 endpoint.
To send a request, use the
POST /2.0/ai/extract endpoint.
curl -i -L 'https://api.box.com/2.0/ai/extract' \ -H 'content-type: application/json' \ -H 'authorization: Bearer <ACCESS_TOKEN>' \ -d '{ "prompt": "Extract data related to contract conditions", "items": [ { "type": "file", "id": "1497741268097" } ], "ai_agent": { "type": "ai_agent_extract", "long_text": { "model": "azure__openai__gpt_4o_mini", "prompt_template": "It is `{current_date}`, and I have $8000 and want to spend a week in the Azores. What should I see?", }, "basic_text": { "model": "azure__openai__gpt_4o_mini", } } }'
To make a call, you must pass the following parameters. Mandatory parameters are in bold.The items array must contain exactly one element. For prompt and file limits, see .
Parameter
Description
Example
prompt
The request for Box AI to extract metadata. Maximum 10,000 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
Override the default model configuration. Lets you change the model, prompt template, system message, or LLM parameters. See for how it works and for examples.
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 a fields array.