AiManager

June 30, 2026 ยท View on GitHub

Ask question

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

You can ask a question about a single file, several files, or the entire contents of a Box Hub. To search across and ask questions about everything in a Box Hub, send a single item with type set to hubs and the Hub's ID as the id. Box AI answers the question using the indexed content of all files in that Hub.

Asking questions about a Box Hub requires Box AI for Hubs to be enabled in the Admin Console before the Hub is created, so that its content is indexed.

This operation is performed by calling function createAiAsk.

See the endpoint docs at API Reference.

try await client.ai.createAiAsk(requestBody: AiAsk(mode: AiAskModeField.singleItemQa, prompt: "Which direction does the Sun rise?", items: [AiItemAsk(id: fileToAsk.id, type: AiItemAskTypeField.file, content: "The Sun rises in the east")]))

Arguments

  • requestBody AiAsk
    • Request body of createAiAsk method
  • headers CreateAiAskHeaders
    • Headers of createAiAsk method

Returns

This function returns a value of type AiResponseFull?.

A successful response including the answer from the LLM.No content is available to answer the question. This is returned when the request item is a hub, but content in the hubs is not indexed. To ensure content in the hub is indexed, make sure Box AI for Hubs in the Admin Console was enabled before hub creation.

Generate text

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

This operation is performed by calling function createAiTextGen.

See the endpoint docs at API Reference.

try await client.ai.createAiTextGen(requestBody: AiTextGen(prompt: "Paraphrase the documents", items: [AiTextGenItemsField(id: fileToAsk.id, type: AiTextGenItemsTypeField.file, content: "The Earth goes around the Sun. The Sun rises in the east in the morning.")], dialogueHistory: [AiDialogueHistory(prompt: "What does the earth go around?", answer: "The Sun", createdAt: try Utils.Dates.dateTimeFromString(dateTime: "2021-01-01T00:00:00Z")), AiDialogueHistory(prompt: "On Earth, where does the Sun rise?", answer: "east", createdAt: try Utils.Dates.dateTimeFromString(dateTime: "2021-01-01T00:00:00Z"))]))

Arguments

  • requestBody AiTextGen
    • Request body of createAiTextGen method
  • headers CreateAiTextGenHeaders
    • Headers of createAiTextGen method

Returns

This function returns a value of type AiResponse.

A successful response including the answer from the LLM.

Get AI agent default configuration

Get the AI agent default config.

This operation is performed by calling function getAiAgentDefaultConfig.

See the endpoint docs at API Reference.

try await client.ai.getAiAgentDefaultConfig(queryParams: GetAiAgentDefaultConfigQueryParams(mode: GetAiAgentDefaultConfigQueryParamsModeField.ask, language: "en-US"))

Arguments

  • queryParams GetAiAgentDefaultConfigQueryParams
    • Query parameters of getAiAgentDefaultConfig method
  • headers GetAiAgentDefaultConfigHeaders
    • Headers of getAiAgentDefaultConfig method

Returns

This function returns a value of type AiAgent.

A successful response including the default agent configuration. This response can be one of the following four objects:

  • AI agent for questions
  • AI agent for text generation
  • AI agent for freeform metadata extraction
  • AI agent for structured metadata extraction. The response depends on the agent configuration requested in this endpoint.

Extract metadata (freeform)

Sends an AI request to supported Large Language Models (LLMs) and extracts metadata in form of key-value pairs. In this request, both the prompt and the output can be freeform. Metadata template setup before sending the request is not required.

This operation is performed by calling function createAiExtract.

See the endpoint docs at API Reference.

try await client.ai.createAiExtract(requestBody: AiExtract(prompt: "firstName, lastName, location, yearOfBirth, company", items: [AiItemBase(id: file.id)]))

Arguments

  • requestBody AiExtract
    • Request body of createAiExtract method
  • headers CreateAiExtractHeaders
    • Headers of createAiExtract method

Returns

This function returns a value of type AiResponse.

A response including the answer from the LLM.

Extract metadata (structured)

Sends an AI request to supported Large Language Models (LLMs) and returns extracted metadata as a set of key-value pairs.

To define the extraction structure, provide either a metadata template or a list of fields. To learn more about creating templates, see Creating metadata templates in the Admin Console or use the metadata template API.

This endpoint also supports Enhanced Extract Agent.

For information about supported file formats and languages, see the Extract metadata from file (structured) API guide.

This operation is performed by calling function createAiExtractStructured.

See the endpoint docs at API Reference.

try await client.ai.createAiExtractStructured(requestBody: AiExtractStructured(fields: [AiExtractStructuredFieldsField(key: "firstName", displayName: "First name", description: "Person first name", prompt: "What is the your first name?", type: "string"), AiExtractStructuredFieldsField(key: "lastName", displayName: "Last name", description: "Person last name", prompt: "What is the your last name?", type: "string"), AiExtractStructuredFieldsField(key: "dateOfBirth", displayName: "Birth date", description: "Person date of birth", prompt: "What is the date of your birth?", type: "date"), AiExtractStructuredFieldsField(key: "age", displayName: "Age", description: "Person age", prompt: "How old are you?", type: "float"), AiExtractStructuredFieldsField(key: "hobby", displayName: "Hobby", description: "Person hobby", prompt: "What is your hobby?", type: "multiSelect", options: [AiExtractStructuredFieldsOptionsField(key: "guitar"), AiExtractStructuredFieldsOptionsField(key: "books")]), AiExtractStructuredFieldsField(key: "address", displayName: "Address", description: "Person address", type: "struct", prompt: "Extract the full mailing address.", fields: [AiExtractSubField(key: "street", displayName: "Street", type: "string"), AiExtractSubField(key: "city", displayName: "City", type: "string"), AiExtractSubField(key: "state", displayName: "State", type: "string"), AiExtractSubField(key: "zip", displayName: "Zip", type: "string"), AiExtractSubField(key: "country", displayName: "Country", type: "string")]), AiExtractStructuredFieldsField(key: "work_history", displayName: "Work history", description: "Person work history", type: "table", prompt: "Extract each job as a row.", fields: [AiExtractSubField(key: "job_title", displayName: "Job title", type: "string"), AiExtractSubField(key: "company", displayName: "Company", type: "string"), AiExtractSubField(key: "start_year", displayName: "Start year", type: "string"), AiExtractSubField(key: "end_year", displayName: "End year", type: "string")])], items: [AiItemBase(id: file.id)], includeConfidenceScore: true, includeReference: true))

Arguments

  • requestBody AiExtractStructured
    • Request body of createAiExtractStructured method
  • headers CreateAiExtractStructuredHeaders
    • Headers of createAiExtractStructured method

Returns

This function returns a value of type AiExtractStructuredResponse.

A successful response including the answer from the LLM.