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

Learn more and register!

Generate text with Box AI

Guides Box AI Generate text with Box AI
Edit this page

Generate text with Box AI

Box AI API is a beta feature which means the available capabilities may change. Box AI API is available to all Enterprise Plus customers.

You can use Box AI to generate text based on provided content. For example, you can ask Box AI to generate a template based on the content you read or create in Box Notes. Then you can embed the generated text directly into your document.

Send a request

To send a request, use the POST /2.0/ai/text_gen endpoint.

cURL
curl -i -X POST "https://api.box.com/2.0/ai/text_gen" \
     -H "content-type: application/json" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
         "prompt": "Write an email to a client about the importance of public APIs.",
         "items": [
        {
            "id": "12345678",
            "type": "file",
            "content": "More information about public APIs"
        },
        {
            "id": "87654321",
            "type": "file",
        },
    ],
    "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"
        }
    ],
  }'
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
);
TypeScript (Beta)
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 (Beta)
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'))])
.NET (Beta)
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"))})));

Make sure you have generated the developer token to authorize your app. See Prerequisites for Box AI for details.

Parameters

To make a call, you must pass the following parameters. Mandatory parameters are in bold.

ParameterDescriptionExample
promptThe request for Box AI to generate or refine the text.Create a meeting agenda for a weekly sales meeting.
items.idBox file ID of the document.1233039227512
items.typeThe type of the supplied input.file
items.contentThe content of the item, often the text representation.This article is about Box AI.
dialogue_history.promptThe prompt previously provided by the client and answered by the Large Language Model (LLM)."Make my email about public APIs sound more professional"
dialogue_history.answerThe answer previously provided by the LLM."Here is a draft of your professional email about public APIs."
dialogue_history.created_atThe ISO date formatted timestamp of when the previous answer to the prompt was created.2012-12-12T10:53:43-08:00