Skip to main content

Ai Functions

View as Markdown

Classify text into labels GA​

POST /api/2.0/ai-functions/ai-classify

Classifies content according to a set of provided labels. The AI Classify REST API has a default rate limit of 1,200 requests per minute per workspace. Contact your account team to request a higher limit.

API scopes: ai-functions

Request body​

contentobjectRequired

The content to classify. It accepts a plain string or the response object of ai_parse_document.

labelsobjectRequired

The label set to classify as. Either a JSON array of label strings (e.g. ["spam", "not_spam"]), or a JSON object mapping each label to a description (e.g. {"spam": "unsolicited bulk message", "not_spam": "a legitimate message"}). Accepts 2 to 5000 labels, each 1 to 100 characters. When multilabel is true, a single label is also accepted.

optionsobject

Function options. Omitted fields fall back to their documented defaults.

Show child attributesHide child attributes
instructionsstring

Natural-language guidance that steers how the text is classified (up to 20,000 characters).

versionstring

The function version to invoke. Defaults to the latest version. Supported versions: ["2.1"].

multilabelboolean

When true, allows more than one label to be returned per input.

enable_confidence_scoresboolean

When true, includes a per-label confidence score in the response.

enable_rationalesboolean

When true, includes a rationale explaining each classification in the response.

Response​

responseobject

The function result as a JSON value. An array of per-label objects: one element in single-label mode (the default), or multiple elements when multilabel is true. When enable_confidence_scores and enable_rationales are true, confidence_score and rationale are included in each response value, respectively.

metadataobject

Additional metadata returned by AI Classify.

Show child attributesHide child attributes
versionstring

The resolved function version.

Get fast structured decisions GA​

POST /api/2.0/ai-functions/ai-decide

Turn text and structured data into decisions your application can use. Define questions and criteria to choose an option, estimate a probability, or assign a score given a provided state. The AI Decide REST API has a default rate limit of 1,200 requests per minute per workspace. Contact your account team to request a higher limit.

Note: The v1 AI Decide syntax supporting strings and objects in state and objects and arrays in instructions will no longer be supported starting February 1, 2027. To use AI Decide, you must set options.version to "2.0", pass an array of typed content objects to state, and a nonblank string to instructions.

API scopes: ai-functions

Request body​

stateobjectRequired

A nonempty array of typed content objects shared by all questions. Set options.version to "2.0" to use this format. Each content object accepts only type and the content field listed below; other fields are rejected. Text and JSON content plus questions must fit within 32 KiB as compact UTF-8 JSON, excluding image parts.

typeContent fieldValue
texttextA nonblank string.
jsondataA JSON object or array.
imageimage_urlAn inline base64 PNG or JPEG data URL: data:image/png;base64,<base64-encoded image bytes> or data:image/jpeg;base64,<base64-encoded image bytes>. HTTP URLs and file paths are not supported. Each image must be at most 4 MiB after base64 decoding, with a resolution up to 1,568 × 1,568 pixels (or an equivalent pixel count). A request supports up to five images. Images are only supported in select regions.
questionsobjectRequired

A JSON object mapping up to 256 question IDs to their definitions. Each ID must be nonblank; its answer is returned with the same ID in response.answers.

Each definition is an object with the required fields type and instructions. The criteria field is optional for the type noul but is required for the types choice and score.

In AI Decide v2, instructions and each criteria description must be nonblank strings. Each question may contain at most 20,000 characters across its ID, instructions, and criteria.

The type can be one of:

  • choice: Selects one option from a defined set. Requires criteria to be an object mapping 1 to 255 nonblank option names to nonblank string descriptions. For example:

    {
    "team": {
    "type": "choice",
    "instructions": "Which team should handle this ticket?",
    "criteria": {
    "billing": "Payments, charges, and refunds",
    "technical_support": "Product errors and troubleshooting"
    }
    }
    }
  • noul: Estimates the probability that the answer to a true-or-false question is true. criteria can take the fields true or false, or both, with nonblank string descriptions. Omit criteria to use the question alone. For example, both of the following are valid:

    {
    "escalate": {
    "type": "noul",
    "instructions": "Does this ticket need escalation?",
    "criteria": {
    "true": "Suspected fraud or an exception to standard policy",
    "false": "A routine issue frontline support can resolve"
    }
    }
    }

    or

    {
    "escalate": {
    "type": "noul",
    "instructions": "Does this ticket need escalation?"
    }
    }
  • score: Rates the state on an ordered scale. Requires criteria to be an array of 2 to 10 unique, nonblank string descriptions, ordered from low to high. Array positions define levels starting at 0. For example:

    {
    "urgency": {
    "type": "score",
    "instructions": "How urgent is this ticket?",
    "criteria": [
    "Routine: can wait a few days",
    "Time-sensitive: needs attention today",
    "Critical: needs immediate action"
    ]
    }
    }
optionsobject

Function options. Omitted fields fall back to their documented defaults.

Show child attributesHide child attributes
versionstring

Set to "2.0". If unset, the deprecated version 1.0 is used during the migration period.

Response​

responseobject

A JSON object containing an answers map with one answer for each question, keyed by the same IDs as questions.

Each answer has a type matching its question and the following fields:

  • choice: choice is the highest-probability option from criteria. probabilities maps every option name to its probability. confidence is a number from 0 to 1 indicating how well the state supports the assessment. The probabilities values sum to 1. For example:

    {
    "answers": {
    "team": {
    "type": "choice",
    "choice": "billing",
    "probabilities": {
    "billing": 0.85,
    "technical_support": 0.15
    },
    "confidence": 0.9
    }
    }
    }
  • noul: probability is a number from 0 to 1 estimating the probability that the answer is true. For example:

    {
    "answers": {
    "escalate": {
    "type": "noul",
    "probability": 0.8
    }
    }
    }
  • score: score is a numeric rating on the zero-based scale defined by criteria. It can fall between levels, from 0 to the number of levels minus 1. probabilities maps each level index to its probability, and legend maps each index to its original description. Both maps use string keys such as "0", "1", and "2". confidence is a number from 0 to 1 indicating how well the state supports the assessment. The probabilities values sum to 1. Depending on the model, score may be truncated and probabilities rounded to 2 decimal places while preserving a sum of 1, so the score can differ slightly from the probability-weighted mean computed from the returned probabilities. For example:

    {
    "answers": {
    "urgency": {
    "type": "score",
    "score": 1.6,
    "probabilities": {
    "0": 0.1,
    "1": 0.2,
    "2": 0.7
    },
    "legend": {
    "0": "Routine: can wait a few days",
    "1": "Time-sensitive: needs attention today",
    "2": "Critical: needs immediate action"
    },
    "confidence": 0.85
    }
    }
    }
metadataobject

Metadata identifying the function API version used for this request.

Show child attributesHide child attributes
versionstring

The function API version used to evaluate the request.

Extract structured data from text GA​

POST /api/2.0/ai-functions/ai-extract

Extracts structured data from text and documents according to a provided schema. The AI Extract REST API has a default rate limit of 120 requests per minute per workspace. Contact your account team to request a higher limit.

API scopes: ai-functions

Request body​

contentobjectRequired

The text to extract from. It accepts a plain string or the response object of ai_parse_document.

schemaobjectRequired

The extraction schema defining the fields to extract. Either a JSON array of field names, assumed to be strings (e.g. ["company", "valuation"]), or a JSON object mapping each field to its type/description (e.g. {"company": {"type": "string", "description": "the company name"}}). Enum fields list their values in "labels" (e.g. {"currency": {"type": "enum", "labels": ["USD", "EUR"]}}). Primitive and enum fields are nullable by default. Accepts up to 256 fields, 12 levels of nesting, and 500 enum values. Supported field types are string, integer, number, boolean, and enum.

optionsobject

Function options. Omitted fields fall back to their documented defaults.

Show child attributesHide child attributes
instructionsstring

Natural-language guidance that steers how data is extracted (up to 20,000 characters).

versionstring

The function version to invoke. Defaults to the latest version. Supported versions: ["2.1"].

modestring

Extraction mode. Supported modes: "precision" — more powerful extraction for complex schemas, long documents, and reasoning-heavy extractions. Defaults to none (standard extraction).

enable_citationsboolean

When true, includes citation metadata locating each extracted value in the source. Depending on the type of input, citations can be one of two types:

For raw text (STRING) inputs, a citation is a span of text in the original input. Each object in metadata.citations has an id (integer matching a citation_ids entry on a field), a start (inclusive 0-based character offset into the input string), and a stop (exclusive 0-based character offset into the input string).

For PDF documents and images (when using ai_extract downstream of ai_parse_document), a citation is a bounding box in the original input. Each object in metadata.citations has an id (integer matching a citation_ids entry on a field) and a bbox (array of {coord, page_id} objects, identical in shape to element.bbox in ai_parse_document output; coord is pixel coordinates on the page image as [x0, y0, x1, y1], and page_id is a 0-based page index).

enable_confidence_scoresboolean

When true, includes a per-field confidence score in the response.

Response​

responseobject

The function result as a JSON value. When enable_confidence_scores and enable_citations are true, confidence and citation_ids are included in each response field, respectively.

metadataobject

Additional metadata returned by AI Extract.

Show child attributesHide child attributes
versionstring

The resolved function version.

modestring

The resolved extraction mode; present when a non-default mode was used.

chunk_typestring

How the source was chunked for citation offsets (span for text input, bbox for parsed-document input); present when citations are enabled.

citationsarray of object

Citation objects locating each result in the source; present when citations are enabled.

Show child attributesHide child attributes
idint64

Integer matching a citation_ids entry on an extracted field.

startint64

Inclusive 0-based character offset into the input string; set for span citations.

stopint64

Exclusive 0-based character offset into the input string; set for span citations.

bboxarray of object

Bounding boxes locating the citation on the source pages; set for bbox citations.

Show child attributesHide child attributes
coordarray of int64

Pixel coordinates on the page image as [x0, y0, x1, y1].

page_idint64

0-based page index the box is on.

Parse documents into structured content GA​

POST /api/2.0/ai-functions/ai-parse-document

Parse structured content from unstructured documents.

API scopes: ai-functions

Request body​

contentstringRequired

The document to parse. The REST API accepts a Unity Catalog volume path to the source file or a base64 data URL containing the file bytes (for example, data:application/pdf;base64,<encoded-file-bytes> or data:image/jpeg;base64,<encoded-file-bytes>). Supported formats: PDF, DOCX, DOC, PPTX, PPT, JPG, JPEG, PNG, TIFF. Accepts up to 100 pages and 100 MB per document.

optionsobject

Function options. Omitted fields fall back to their documented defaults.

Show child attributesHide child attributes
versionstring

The ai_parse_document output schema version. Supported value: "2.0".

description_element_typesstring

Element types for which an AI-generated description is produced. Use "" (default) to generate descriptions for all supported element types, "figure" to generate them for figures only, or "" (empty string) to generate none. Only figure descriptions are supported for version "2.0", so "" and "figure" produce the same behavior.

image_output_pathstring

Unity Catalog volume path where rendered page and element images are written.

page_rangestring

Pages to parse (1-indexed), as a comma-separated list of page numbers or ranges (e.g. "1,3,5-10").

Response​

documentobject

The parsed document as a JSON value, containing the extracted pages and elements.

error_statusarray of object

Per-page partial-failure details; present when the request succeeds (2xx) but individual pages fail.

Show child attributesHide child attributes
error_messagestring

Message describing why the page failed.

page_idint64

0-based index of the page that failed.

metadataobject

Additional metadata returned by AI Parse Document.

Show child attributesHide child attributes
idstring

Unique identifier for the parse request.

versionstring

The resolved function version.

file_metadataobject

Describes the source file; present only for file-path input.

Show child attributesHide child attributes
file_pathstring

Unity Catalog volume path of the source file.

file_namestring

Base name of the source file.

file_sizeint64

Size of the source file in bytes.

file_modification_timestring

Last-modified timestamp of the source file, as an HTTP date string.