AI

AI endpoints provide access to language model capabilities including chat, structured object extraction, and file uploads for multimodal models. All endpoints require `AI_ENABLED=true` and app-level authentication.

AI Chat

Send messages to an AI language model and receive a streamed response. Requires `AI_ENABLED=true` and app-level authentication. Streamed as Server-Sent Events.

Request Body

provider
string

AI provider to use.

model
string

Model ID for the selected provider.

messages
array

Conversation history. Must contain at least one message.

tools
array

List of tools available to the model. Each entry is either a built-in tool name string or a custom tool definition object.

toolApprovals
object

Per-tool approval mode.

context
object

Contextual information for the session.

Responses

Successful request
// Not supported in Directus SDK

AI Object Extraction

Generate a structured object from a prompt using an AI language model. Requires `AI_ENABLED=true` and app-level authentication. Streams a JSON object matching the provided output schema.

Request Body

provider
string

AI provider to use.

model
string

Model ID for the selected provider.

prompt
string

Prompt describing the object to generate.

outputSchema
object

JSON Schema 7 definition for the output object.

maxOutputTokens
integer

Maximum number of tokens in the model output. Minimum 256.

Responses

Successful request
// Not supported in Directus SDK

Upload File for AI

Upload a file to an AI provider for use in subsequent AI requests. Requires `AI_ENABLED=true` and app-level authentication. Supported providers are `openai`, `anthropic`, and `google`. Maximum file size is 50 MB.

Responses

Successful request
data
object

Provider-specific file reference returned after upload.

// Not supported in Directus SDK
Response Example
{
  "data": {}
}