Send AI request to generate text

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

Sends an AI request to supported LLMs and returns an answer specifically focused on the creation of new text.

Request

bearer [ACCESS_TOKEN]
application/json

Request Body

The AI agent used for generating text.

object arrayin bodyoptional

The history of prompts and answers previously passed to the LLM. This provides additional context to the LLM in generating the response.

stringin bodyoptional
"Here is the first draft of your professional email about public APIs."

The answer previously provided by the LLM.

string (date-time)in bodyoptional
"2012-12-12T10:53:43-08:00"

The ISO date formatted timestamp of when the previous answer to the prompt was created.

stringin bodyoptional
"Make my email about public APIs sound more professional."

The prompt previously provided by the client and answered by the LLM.

object arrayin bodyrequired

The items to be processed by the LLM, often files. The array can include exactly one element.

Note: Box AI handles documents with text representations up to 1MB in size. If the file size exceeds 1MB, the first 1MB of text representation will be processed.

stringin bodyoptional
"123"

The id of the item.

stringin bodyoptional
"file"

The type of the item.

Value is always file

stringin bodyoptional
"This is file content that is relevant to the text gen request."

The content to use as context for generating new text or editing existing text.

stringin bodyrequired
"Write an email to a client about the importance of public APIs."

The prompt provided by the client to be answered by the LLM. The prompt's length is limited to 10000 characters.

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 request to generate text
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -L POST "https://api.box.com/2.0/ai/text_gen" \
     -H "content-type: application/json" \
     -H "authorization: Bearer <TOKEN>" \
     -d '{
          "prompt": "Write a social media post about protein powder",
          "items": [
         {
            "id": "12345678",
            "type": "file"
        }
      ]
     }'
TypeScript Gen
await client.ai.createAiTextGen({
  prompt: 'Parapharse the document.s',
  items: [
    {
      id: fileToAsk.id,
      type: 'file' as AiTextGenItemsTypeField,
      content:
        'The Earth goes around the sun. Sun rises in the East in the morning.',
    } satisfies AiTextGenItemsField,
  ],
  dialogueHistory: [
    {
      prompt: 'What does the earth go around?',
      answer: 'The sun',
      createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
    } satisfies AiTextGenDialogueHistoryField,
    {
      prompt: 'On Earth, where does the sun rise?',
      answer: 'East',
      createdAt: dateTimeFromString('2021-01-01T00:00:00Z'),
    } satisfies AiTextGenDialogueHistoryField,
  ],
} satisfies AiTextGen);
Python Gen
client.ai.create_ai_text_gen(
    "Parapharse the document.s",
    [
        CreateAiTextGenItems(
            id=file_to_ask.id,
            type=CreateAiTextGenItemsTypeField.FILE.value,
            content="The Earth goes around the sun. Sun rises in the East in the morning.",
        )
    ],
    dialogue_history=[
        CreateAiTextGenDialogueHistory(
            prompt="What does the earth go around?",
            answer="The sun",
            created_at=date_time_from_string("2021-01-01T00:00:00Z"),
        ),
        CreateAiTextGenDialogueHistory(
            prompt="On Earth, where does the sun rise?",
            answer="East",
            created_at=date_time_from_string("2021-01-01T00:00:00Z"),
        ),
    ],
    ai_agent=ai_text_gen_agent_config,
)
.NET Gen
await client.Ai.CreateAiTextGenAsync(requestBody: new AiTextGen(prompt: "Parapharse the document.s", items: Array.AsReadOnly(new [] {new AiTextGenItemsField() { Id = fileToAsk.Id, Type = AiTextGenItemsTypeField.File, Content = "The Earth goes around the sun. Sun rises in the East in the morning." }})) { DialogueHistory = Array.AsReadOnly(new [] {new AiTextGenDialogueHistoryField() { Prompt = "What does the earth go around?", Answer = "The sun", CreatedAt = Utils.DateTimeFromString(dateTime: "2021-01-01T00:00:00Z") },new AiTextGenDialogueHistoryField() { Prompt = "On Earth, where does the sun rise?", Answer = "East", CreatedAt = Utils.DateTimeFromString(dateTime: "2021-01-01T00:00:00Z") }}) });
Java
List<BoxAIDialogueEntry> dialogueHistory = new ArrayList<>();
dialogueHistory.add(
        new BoxAIDialogueEntry(
            "Make my email about public APIs sound more professional",
            "Here is the first draft of your professional email about public APIs.",
            BoxDateFormat.parse("2013-05-16T15:26:57-07:00")
        )
    );
BoxAIResponse response = BoxAI.sendAITextGenRequest(
    api,
    "Write an email to a client about the importance of public APIs.",
    Collections.singletonList(new BoxAIItem("123456", BoxAIItem.Type.FILE)),
    dialogueHistory
);
Python
items = [{
    "id": "1582915952443",
    "type": "file",
    "content": "More information about public APIs"
}]
dialogue_history = [{
        "prompt": "Make my email about public APIs sound more professional",
        "answer": "Here is the first draft of your professional email about public APIs",
        "created_at": "2013-12-12T10:53:43-08:00"
    },
    {
        "prompt": "Can you add some more information?",
        "answer": "Public API schemas provide necessary information to integrate with APIs...",
        "created_at": "2013-12-12T11:20:43-08:00"
}]
answer = client.send_ai_text_gen(
    dialogue_history=dialogue_history,
    items=items,
    prompt="Write an email to a client about the importance of public APIs."
)
print(answer)
.NET
BoxAIResponse response = await client.BoxAIManager.SendAITextGenRequestAsync(
    new BoxAITextGenRequest
    {
        Prompt = "What is the name of the file?",
        Items = new List<BoxAITextGenItem>() { new BoxAITextGenItem() { Id = "12345" } },
        DialogueHistory = new List<BoxAIDialogueHistory>()
        {
            new BoxAIDialogueHistory() { Prompt = "What is the name of the file?", Answer = "MyFile", CreatedAt = DateTimeOffset.Parse("2024-05-16T15:26:57-07:00") }
            new BoxAIDialogueHistory() { Prompt = "What is the size of the file?", Answer = "10kb", CreatedAt =  DateTimeOffset.Parse("2024-05-16T15:26:57-07:00") }
        }
    };
);
Node
client.ai.textGen(
    {
        prompt: 'What is the capital of France?',
        items: [
            {
                type: 'file',
                id: '12345'
            }
        ],
        dialogue_history: [
            {
                prompt: 'What is the capital of France?',
                answer: 'Paris',
                created_at: '2021-10-01T00:00:00Z'
            },
            {
                prompt: 'What is the capital of Germany?',
                answer: 'Berlin',
                created_at: '2021-10-01T00:00:00Z'
            }
        ]
    })
    .then(response => {
        /* response -> {
            "answer": "The capital of France is Paris.",
            "created_at": "2021-10-01T00:00:00Z",
            "completion_reason": "done"
        } */
    });

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"
}