How to use Box AI with Box CLI

|
Share
1

he Box CLI is a user-friendly command line tool that allows both technical and non-technical users to leverage the Box API to perform routine or bulk actions. There is no need to write any code, as these actions are executed through a set of commands. Since the version v3.15.0 it’s possible to use Box AI built-in commands. In this blog post, I’ll walk you through setup and some basic examples of usage.

The key features of Box AI in Box CLI

  1. Document Q&A and summarization: you can ask Box AI about document content, or generate summaries of larger documents to grasp key points efficiently.
  2. Content Generation: you can create document drafts using natural language prompts.

⚠️ Box AI API is available to all Enterprise Plus and Enterprise Advanced customers.

Setup

Install Box CLI

To use Box CLI, ensure you have installed the latest version of the CLI. You can find installation instructions in our quick start guide. This tutorial will walk you through the package installation, the creation of a Box Platform app, and authentication.

ℹ️ Check the below-mentioned settings to ensure you can perform Box AI API calls. Insufficient scopes may result in the following error:

Unexpected API Response [403 Forbidden | 0e652aca531c5ab0627abfa0f89fbf59f.0e652aca531c5ab0627abfa0f89fbf59f] insufficient_scope - The request requires higher privileges than provided by the access token.

Enable Box AI in Admin

In order to use Box AI, you need to make sure appropriate settings are applied. First, go to Admin Console and navigate to Enterprise Settings. Within the Box AI tab, scroll to Box AI for API enabled for all users and enable it.

12

Next, go to Developer Console and choose the Platform app that you’d like to work with. In the app Configuration tab, enable Manage AI scope.

13

Finally, make sure your Platform app is authorized and enabled in the Admin Console. Go to Integrations and click Platform Apps Manager.

14

When the application’s scopes or access level change the application needs to be re-authorized. Check more details in developer documentation.

Start using Box AI with Box CLI

Currently, there are two commands related to Box AI in Box CLI: box ai:ask and box ai:text-gen. The AI model used in Box CLI is Azure OpenAI GPT-4o Mini.

box ai:ask

This command sends an AI request to the LLM and returns an answer with some additional parameters.

A sample document I chose contains the first few pages of the book “The Adventures of Huckleberry Finn.” Let’s ask Box AI who the author of this book is.

15

There are two required parameters in this command: the file ID and a prompt.

box ai:ask --items=id=12345678901234,type=file --prompt "Who is the author of this book?"

Box CLI returns an answer with some additional parameters, such as the AI Agent information.

box ai:ask --items=id=12345678901234,type=file --prompt "What is the author of this book?"
Answer: The author of the book is Mark Twain.
Created At: '2025-01-30T03:26:12.043-08:00'
Completion Reason: done
Ai Agent Info:
    Models:
        -
            Name: azure__openai__gpt_4o_mini
            Provider: azure
    Processor: basic_text

Let’s slightly raise the bar and ask about the number of chapters in this book:

➜  ~ box ai:ask --items=id=12345678901234,type=file --prompt "How many chapters does this is book have?" 
Answer: 'The book contains a total of 43 chapters, including "THE CHAPTER LAST."'
Created At: '2025-01-30T03:47:45.54-08:00'
Completion Reason: done
Ai Agent Info:
    Models:
        -
            Name: azure__openai__gpt_4o_mini
            Provider: azure
    Processor: basic_text

Cool, what about asking Box AI to write a document summary?

box ai:ask --items=id=12345678901234,type=file --prompt "Write a document summary"          
Answer: >-
    "The Adventures of Huckleberry Finn" by Mark Twain follows the story of a
    young boy named Huck Finn, who is introduced as a friend of Tom Sawyer. The
    narrative begins with Huck reflecting on his life and experiences,
    particularly after finding treasure with Tom that makes them both wealthy.
    Huck struggles with the constraints of civilized life imposed by the Widow
    Douglas and her sister Miss Watson, who attempt to "sivilize" him. He feels
    trapped and longs for freedom, leading him to escape back into his old ways.
    The story captures Huck's internal conflicts regarding morality, society,
    and his desire for adventure, setting the stage for his journey along the
    Mississippi River.
Created At: '2025-01-30T05:19:03.505-08:00'
Completion Reason: done
Ai Agent Info:
    Models:
        -
            Name: azure__openai__gpt_4o_mini
            Provider: azure
    Processor: basic_text

As you can see, Box AI returns a pretty extensive summary of the document content. These were some basic examples; however, I recommend that you explore the possibilities of this tool to help streamline your day-to-day tasks.

Now, let’s talk about the second command.

box ai:text-gen

It sends an AI request to the LLM and returns an answer specifically focused on creating new text. For example, we can ask Box AI to write a poem about Box CLI!

box ai:text-gen --items=id=12345678901234,type=file --prompt "Write a poem about Box CLI"       

Ai Agent Info:
    Processor: basic_gen
    Models:
        -
            Name: azure__openai__gpt_4o_mini
            Provider: azure
Answer: |-
    In the realm of code where commands align,  
    Box CLI stands, a tool so fine.  
    With lines of text and options galore,  
    It opens the door to cloud's endless store.  

    A whisper of power in each typed command,  
    Managing files with a steady hand.  
    Upload and download with effortless grace,  
    Navigating folders in digital space.  

    Scripts come alive as you harness its might,  
    Automating tasks from morning till night.  
    Collaboration blooms with every deploy,  
    Sharing ideas brings everyone joy.  

    So here’s to Box CLI, sleek and bright,  
    Empowering users to reach new heights.  
    In the world of tech where we strive to be free,  
    It’s more than a tool; it’s our key to unity.  
Created At: '2025-01-30T05:20:51.635-08:00'
Completion Reason: done

Apart from writing poetry, box ai:text-gen can help you generate drafts, contracts, agreements, and more directly form your terminal. Give it a try, and as always stay tuned for upcoming enhancements! 🤓

🦄 Want to engage with other Box Platform champions?

Join our Box Developer Community for support and knowledge sharing!