Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content/configuration/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ description: Configuration for AI Assistant and Model Context Protocol (MCP) fea
When `AI_ENABLED` is set to `false`:
- The API routes for the assistant are not mounted
- AI Assistant sidebar is hidden from all users
- [AI Text and AI Image](/guides/flows/operations#ai-text) flow steps fail without calling the AI provider
- AI settings form displays a disabled notice

This is useful for compliance requirements where AI features must be completely hidden.
Expand Down
153 changes: 153 additions & 0 deletions content/guides/06.flows/4.operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,156 @@ If you've configured a response body in the trigger of the other flow, this will
**Flows for-loops**
If you pass an array to the other flow, the other flow will run once for each item in the array.
::

## AI Text

![AI Text operation configuration](/img/eb604c8e-40f0-4da4-8f4d-fe12ff4d09a9.webp)

This operation sends a prompt to an AI model and appends the reply to the data chain. Use it to summarize, translate, categorize, or moderate content, write alt text for uploaded images, or pull named values out of text for later steps.

::callout{icon="i-lucide-info" to="/guides/ai/assistant/setup"}
This operation uses the providers and API keys set in **Settings → AI**. Add at least one provider before you add the step.
::

### Options

- **Model** - The model to use. The list shows the models allowed in **Settings → AI**. You can also type `provider:model-id`, such as `openai:gpt-5-mini`, but the model must still be allowed. OpenAI-compatible models aren't checked.
- **Prompt** - What the model should do. Insert data from the trigger or earlier steps with `{{ }}`, such as `{{ $trigger.payload.content }}`.
- **System Prompt** - Optional rules that apply to every run, such as tone, audience, or language.
- **Files** - Optional files for the model to read. Enter file IDs or a `{{ }}` value, or pick files from the library. Hidden for models that can't read files.
- **Permissions** - Whose access is used to read the files: **From Trigger**, **Public Role**, **Full Access**, or a specific role.
- **Output** - **Text** returns one string. **Object** returns named values that match the output schema.
- **Max Output Tokens** - Caps the length and cost of each run. Leave empty to use the model default.
- **Output Schema** - Available when **Output** is set to **Object**. Defines the values the model returns. See [Output Schema](#output-schema).

When the prompt is empty, you can pick a starting point: **Alt text & focal point**, **Summarize**, **Translate**, **Improve writing**, **SEO description**, **Categorize**, or **Moderate**. A starting point fills in the prompt and the output type, plus the output schema and files where it needs them. **Alt text & focal point** sets **Files** to `{{ $trigger.key }}`. Replace markers like `[your content]` with flow data before you save. The editor warns you while a marker is left in the prompt. To pick a different starting point, use **Start over**, which asks before it clears the prompt and the settings that go with it.

### Output Schema

![AI Text output schema with a category field limited to four choices](/img/1735261a-4601-4f59-8d8a-713c9c1b346e.webp)

The output schema is a JSON Schema for an object. Edit it in either view, and changes in one show up in the other:

- **Fields** - Add one row per value. Each row has a name, a type, a description, and for text, an optional list of choices the model must pick from. **Object** and **List of Objects** rows hold fields of their own.
- **JSON** - Edit the JSON Schema directly. Use this view for schema features the Fields view can't show, like `$ref`.

You can also build the schema from an example:

- **Paste an example** - Paste a sample of the object you want back. Text values become instructions for the model, and numbers and booleans set the type.
- **Generate with AI** - Describe the values you want, and the AI suggests fields. This needs a model allowed in **Settings → AI**.

Every field is returned. When **Always return a value** is off for a field, the model returns `null` if it can't find the value.

### Payload

With **Output** set to **Text**, the reply is appended under its `<operationKey>` as `text`:

```json
{
"text": "Directus 12 adds AI steps to flows.",
"model": "openai:gpt-5-mini",
"usage": {
"inputTokens": 412,
"outputTokens": 58,
"totalTokens": 470
},
"finishReason": "stop",
"warnings": []
}
```

With **Output** set to **Object**, the values are under `output` instead of `text`. Use them in later steps with `{{ <operationKey>.output.<field> }}`, such as `{{ categorize.output.category }}`.

### More Details

::callout{icon="i-lucide-info"}
**Files**
Files can be images (JPEG, PNG, GIF, WebP), PDFs, plain text, MP3 or WAV audio, and MP4 video, if the model supports the type. A step can send up to 20 files, up to 50MB combined. On a file upload trigger, `{{ $trigger.key }}` is the uploaded file.
::

::callout{icon="i-lucide-triangle-alert" color="warning"}
**Full Access**
With **Full Access**, any file ID in the flow data can be read and sent to the AI provider. Use **From Trigger** or a specific role when file IDs come from user input.
::

::callout{icon="i-lucide-info"}
**Checked Replies**
The reply is checked against the output schema. If it doesn't match, the step fails and the error names the fields that were wrong. If the model runs out of output tokens before it finishes, the step fails. When **Max Output Tokens** is set, raise it or leave it empty. Otherwise, ask for less or use a model with a larger output limit. Models that reason count their reasoning toward the limit.
::

::callout{icon="i-lucide-shield"}
**Secrets**
Before the options are filled in, `password`, `token`, `tfa_secret`, `credentials`, `auth_data`, `external_identifier`, and the AI API keys from **Settings → AI** are replaced with `--redacted--` anywhere under a `payload` or `body` in the flow data. So are `authorization` and `cookie` headers and the `access_token` query parameter. Other values returned by earlier steps aren't redacted. The Log to Console operation redacts the same fields.
::

::callout{icon="i-lucide-info"}
**Allowed Models**
AI Text can only use models from the **Allowed Models** setting in **Settings → AI**. AI Image doesn't use that setting, so it can use any image model from a configured provider.
::

::callout{icon="i-lucide-info" to="/configuration/ai"}
**Turning AI Off**
When `AI_ENABLED` is set to `false`, AI Text and AI Image steps fail without calling the AI provider.
::

## AI Image

![AI Image operation configuration](/img/6fbd0386-25c9-49bb-a457-57ab1bbe9aa2.webp)

This operation generates images with an AI model and saves them to the file library. Use it to make article hero images, product shots, social cards, or icons, or to restyle an existing image.

::callout{icon="i-lucide-info" to="/guides/ai/assistant/setup"}
This operation supports OpenAI, Google, and OpenRouter image models. Add an OpenAI, Google, or OpenRouter API key in **Settings → AI** before you add the step.
::

### Options

- **Model** - The image model to use. With an OpenRouter key, the list includes OpenRouter's current image models, with IDs like `openrouter:google/gemini-2.5-flash-image`. To use a model that isn't listed, type `provider:model-id`.
- **Prompt** - Describe the subject, style, and composition. Insert flow data with `{{ }}`.
- **Reference Images** - Optional PNG, JPEG, or WebP files, up to 20 images and 50MB combined. The model edits or combines them instead of starting from scratch. Some OpenRouter models ignore them. Enter file IDs or a `{{ }}` value, or pick images from the library.
- **Aspect Ratio** - Lists only the ratios the selected model supports. With reference images, **Match reference image** uses the shape of the first one.
- **Images** - How many images to make, from 1 to 4. Each image is saved as its own file.
- **Quality** - OpenAI models only. Higher quality costs more and takes longer.
- **Background** - Saves a PNG with a transparent background. Shown only for the OpenAI models that support it.
- **Folder** - The folder to save the new files in.
- **Permissions** - Whose access is used to read reference images and save the new files: **From Trigger**, **Public Role**, **Full Access**, or a specific role.
- **File Title** - The title of the new files. Defaults to "AI image". Multiple images are numbered.
- **Emit Events** - Whether saving the files runs other flows that start on file uploads. Off by default.

When the prompt is empty, you can pick a starting point: **Article hero**, **Product photo**, **Social card**, **Icon**, or **Restyle reference**. A starting point fills in the prompt and the aspect ratio, and **Icon** also turns on a transparent background. Replace markers like `[topic]` with flow data before you save. **Start over** asks before it clears them.

### Payload

The IDs of the saved files are appended under its `<operationKey>` as `files`:

```json
{
"files": ["a1b2c3d4-0000-4000-8000-000000000001"],
"model": "openai:gpt-image-2",
"warnings": []
}
```

Use `{{ <operationKey>.files[0] }}` to set the image on an item in a later step.

### More Details

::callout{icon="i-lucide-triangle-alert" color="warning"}
**Emit Events**
If this flow starts on file uploads, turning on **Emit Events** makes it run again for every image it saves. This repeats without end, and every run is billed by the provider.
::

::callout{icon="i-lucide-info"}
**Save Checks**
Before generating, the operation checks that the chosen permissions can create files and that the folder exists. If not, the step fails before the provider is called. Validation rules on files only run when saving, so they can still fail after the images are made.
::

::callout{icon="i-lucide-triangle-alert" color="warning"}
**Full Access**
With **Full Access**, any image ID in the flow data can be sent to the AI provider, and images can be saved to any folder. Use **From Trigger** or a specific role when file IDs come from user input.
::

::callout{icon="i-lucide-info"}
**Fewer Images**
Providers sometimes return fewer images than requested. When that happens, the step still succeeds and adds a message to `warnings`.
::
14 changes: 13 additions & 1 deletion content/guides/12.ai/0.index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
stableId: aff68140-bbee-4a00-8482-4ada9fa36e2e
title: AI + Directus
description: Use AI with Directus through the built-in AI Assistant, external AI tools over MCP, AI Translations, or coding agents with Agent Skills.
description: Use AI with Directus through the built-in AI Assistant, external AI tools over MCP, AI Translations, AI steps in Flows, or coding agents with Agent Skills.
---

Directus offers several ways to bring AI into your workflow, depending on where you prefer to work.
Expand Down Expand Up @@ -42,6 +42,18 @@ AI Translations let you translate content fields into multiple languages directl
Set up and use AI-powered content translations.
::

## Automations: AI in Flows

The AI Text and AI Image operations add AI steps to [Flows](/guides/flows).

- Summarize, translate, categorize, or moderate content when it's created or updated
- Return named values, like alt text or a category, that later steps save to items
- Generate images and save them to the file library

::card{icon="i-lucide-workflow" title="AI Operations" to="/guides/flows/operations#ai-text"}
Add AI Text and AI Image steps to a flow.
::

## Coding Agents: Agent Skills

Agent Skills teach AI coding agents how to build with Directus and avoid the mistakes they would otherwise make.
Expand Down
4 changes: 4 additions & 0 deletions content/guides/12.ai/1.assistant/1.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ This is useful for:
- Ensuring compliance by only allowing approved models
- Simplifying the user experience by reducing model choices

::callout{icon="i-lucide-info"}
Allowed Models apply to the AI Assistant, AI Translations, and the [AI Text](/guides/flows/operations#ai-text) flow operation. The [AI Image](/guides/flows/operations#ai-image) flow operation can use any image model from a configured provider.
::

### Save Settings

Click **Save** to apply your changes. AI Assistant is now available to all users with [App access](/guides/auth/access-control#studio-users).
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading