Box Developer Documentation
 
    Latest version

    Generate text

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

    This endpoint is in the version 2024.0. No changes are required to continue using it. For more details, see Box API versioning.

    Sends an AI request to supported Large Language Models (LLMs) and returns generated text based on the provided prompt.

    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 parameter provides the additional context to the LLM when 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 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 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 server error.

    application/jsonClient error

    An unexpected error.

    post
    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 <ACCESS_TOKEN>" \
         -d '{
              "prompt": "Write a social media post about protein powder.",
              "items": [
             {
                "id": "12345678",
                "type": "file",
                "content": "More information about protein powders"
            },
            ],
              "dialogue_history": [
                {
                    "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"
                }
            ],
              "ai_agent": {
                "type": "ai_agent_text_gen",
                "basic_gen": {
                  "model": "azure__openai__gpt_4o_mini"
                }
             }
         }'

    Response Example

    {
      "ai_agent_info": {
        "models": [
          {
            "name": "azure__openai__text_embedding_ada_002",
            "provider": "azure",
            "supported_purpose": "embedding"
          }
        ]
      },
      "answer": "Public APIs are important because of key and important reasons.",
      "completion_reason": "done",
      "created_at": "2012-12-12T10:53:43-08:00"
    }