Add the power of the Box AI API to your custom apps at Content Cloud Summit on May 15

Learn more and register!

Send AI Ask request

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

Sends an AI request to supported LLMs and returns an answer specifically focused on the user's question given the provided context.

Request

bearer [ACCESS_TOKEN]
application/json

Request Body

object arrayin bodyrequired

The items to be processed by the LLM, often files.

stringin bodyrequired
"123"

The id of the item

stringin bodyrequired
"file"

The type of the item

Value is always file

stringin bodyoptional
"This is file content."

The content of the item, often the text representation.

stringin bodyrequired
"multiple_item_qa"

The mode specifies if this request is for a single or multiple items.

Value is one of multiple_item_qa,single_item_qa

stringin bodyrequired
"What is the value provided by public APIs based on this document?"

The prompt provided by the client to be answered by the LLM.

Response

application/jsonAI 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
Send AI Ask request
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -X POST "https://api.box.com/2.0/ai/ask" \
     -H "content-type: application/json" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
         "mode": "single_item_qa",
         "prompt": "What is the value provided by public APIs based on this document?",
         "items": [
        {
            "type": "file",
            "id": "9842787262"
        }
       ],
     }'
Java
BoxAIResponse response = BoxAI.sendAIRequest(
    api,
    "What is the content of the file?",
    Collections.singletonList("123456", BoxAIItem.Type.FILE)),
    BoxAI.Mode.SINGLE_ITEM_QA
);
TypeScript (Beta)
await client.ai.createAiAsk({
  mode: 'multiple_item_qa' as AiAskModeField,
  prompt: 'Which direction sun rises?',
  items: [
    new AiAskItemsField({
      id: fileToAsk1.id,
      type: 'file' as AiAskItemsTypeField,
      content: 'Earth goes around the sun',
    }),
    new AiAskItemsField({
      id: fileToAsk2.id,
      type: 'file' as AiAskItemsTypeField,
      content: 'Sun rises in the East in the morning',
    }),
  ],
} satisfies AiAsk);
Python (Beta)
client.ai.create_ai_ask(CreateAiAskMode.MULTIPLE_ITEM_QA.value, 'Which direction sun rises?', [CreateAiAskItems(id=file_to_ask_1.id, type=CreateAiAskItemsTypeField.FILE.value, content='Earth goes around the sun'), CreateAiAskItems(id=file_to_ask_2.id, type=CreateAiAskItemsTypeField.FILE.value, content='Sun rises in the East in the morning')])
.NET (Beta)
await client.Ai.CreateAiAskAsync(requestBody: new AiAsk(mode: AiAskModeField.MultipleItemQa, prompt: "Which direction sun rises?", items: Array.AsReadOnly(new [] {new AiAskItemsField(id: fileToAsk1.Id, type: AiAskItemsTypeField.File, content: "Earth goes around the sun"),new AiAskItemsField(id: fileToAsk2.Id, type: AiAskItemsTypeField.File, content: "Sun rises in the East in the morning")})));

Response Example

{
  "answer": "Public APIs are important because of key and important reasons.",
  "completion_reason": "done",
  "created_at": "2012-12-12T10:53:43-08:00"
}