Join BoxWorks 2024 to discover what's possible with content and AI!

Register now!
Beta

Extract metadata (structured)

post
https://api.box.com/2.0
/ai/extract_structured

Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs. For this request, you need to use an already defined metadata template or a define a schema yourself. To learn more about creating templates, see Creating metadata templates in the Admin Console or use the metadata template API.

Request

bearer [ACCESS_TOKEN]
application/json

Request Body

The AI agent to be used for structured extraction.

object arrayin bodyoptional

The fields to be extracted from the provided items. For your request to work, you must provide either metadata_template or fields, but not both.

stringin bodyoptional
"enum"

The type of the field. It include but is not limited to string, float, date, enum, and multiSelect.

stringin bodyoptional
"The name of the person."

A description of the field.

stringin bodyoptional
"Name"

The display name of the field.

stringin bodyconditionally required
"name"

A unique identifier for the field.

object arrayin bodyoptional
[{"key":"First Name"},{"key":"Last Name"}]

A list of options for this field. This is most often used in combination with the enum and multiSelect field types.

stringin bodyconditionally required
"First Name"

A unique identifier for the field.

stringin bodyoptional
"Name is the first and last name from the email address"

The context about the key that may include how to find and format it.

object arrayin bodyrequired

The items to be processed by the LLM. Currently you can use files only.

stringin bodyrequired
"123"

The ID of the file.

stringin bodyrequired
"file"

The type of the item. Currently the value can be file only.

Value is always file

stringin bodyoptional
"This is file content."

The content of the item, often the text representation.

objectin body

The metadata template containing the fields to extract. For your request to work, you must provide either metadata_template or fields, but not both.

stringin bodyoptional
"metadata_template"

Value is always metadata_template.

Value is always metadata_template

stringin bodyoptional
"enterprise_12345"40

The scope of the metadata template that can either be global or enterprise.

  • The global scope is used for templates that are available to any Box enterprise.
  • The enterprise scope represents templates created within a specific enterprise, containing the ID of that enterprise.
stringin bodyoptional
"invoiceTemplate"

The name of the metadata template.

Response

application/jsonAI extract response

A successful response including the answer from the LLM.

application/jsonClient error

An unexpected client error.

application/jsonClient error

An unexpected server error.

post
Extract metadata (structured)
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -L 'https://api.box.com/2.0/ai/extract_structured' \
     -H 'content-type: application/json' \
     -H 'authorization: Bearer <ACCESS_TOKEN>' \
     -d '{
        "items": [
          {
            "id": "12345678",
            "type": "file",
            "content": "This is file content."
          }
        ],
        "metadata_template": {
            "template_key": "",
            "type": "metadata_template",
            "scope": ""
        },
        "fields": [
            {
              "key": "name",
              "description": "The name of the person.",
              "displayName": "Name",
              "prompt": "The name is the first and last name from the email address.",
              "type": "string",
              "options": [
                {
                  "key": "First Name"
                },
                {
                  "key": "Last Name"
                }
              ]
            }
        ],
        "ai_agent": {
          "type": "ai_agent_extract",
          "long_text": {
            "model": "azure__openai__gpt_3_5_turbo_16k",
            "system_message": "You are a helpful travel assistant specialized in budget travel",
            "prompt_template": "It is `{current_date}`, and I have $8000 and want to spend a week in the Azores. What should I see?",
            "num_tokens_for_completion": 8400,
            "llm_endpoint_params": {
              "type": "openai_params",
              "temperature": 0,
              "top_p": 1,
              "frequency_penalty": 1.5,
              "presence_penalty": 1.5,
              "stop": "<|im_end|>"
            },
            "embeddings": {
              "model": "openai__text_embedding_ada_002",
              "strategy": {
                "id": "basic",
                "num_tokens_per_chunk": 64
              }
            }
          },
          "basic_text": {
            "model": "azure__openai__gpt_3_5_turbo_16k",
            "system_message": "You are a helpful travel assistant specialized in budget travel",
            "prompt_template": "It is `{current_date}`, and I have $8000 and want to spend a week in the Azores. What should I see?",
            "num_tokens_for_completion": 8400,
            "llm_endpoint_params": {
              "type": "openai_params",
              "temperature": 0,
              "top_p": 1,
              "frequency_penalty": 1.5,
              "presence_penalty": 1.5,
              "stop": "<|im_end|>"
            }
          }
        }
      }'
Python Gen
client.ai.create_ai_extract_structured(
    [AiItemBase(id=file.id)],
    metadata_template=CreateAiExtractStructuredMetadataTemplate(
        template_key=template_key, scope="enterprise"
    ),
)