Skip to main content

Using artificial intelligence

Mage uses AI to help you build data pipelines faster— with our OpenAI integration, you can automate the tedious parts of pipeline development and focus on the fun stuff.
You will need to add an OpenAI API key to your project before you can use AI for various actions.
We currently support the following AI features:
  • Generate pipelines
  • Generate blocks
  • Chat with Codex in Mage Pro
  • Document code
    • Block documentation
    • Block comments
    • Pipeline documentation
    • Simultaneously document all blocks in a pipeline

To see examples of how to use AI in Mage, check out our AI guides.

Setup

You need to add an OpenAI API key to your project before you can use AI for various actions.
Read OpenAI’s documentation to get your API key.
Once you have your OpenAI API key, go to project settings (click the “wizard” in the top right > Workspace > Preferences) and enter the OpenAI API key under the section labeled OpenAI.

AI Chat in Mage Pro

Mage Pro includes AI Chat for Codex-backed workspace assistance. Open AI Chat from Mage Pro, or visit /ai/chat in an authenticated workspace as a user with the Editor role or higher. For each chat turn, Mage captures the visible non-chat text from the current browser page, along with the page title and URL, so Codex can answer page-relative prompts such as “explain this page” or “what am I looking at?” The captured context is scoped to the authenticated user and chat session, excludes the Codex chat UI, and is capped at 20,000 characters. The AI Chat sidebar lists active and archived chats, lets you search chat history by title, and loads older chats with Show more when more results are available. Mage Pro remembers the selected chat and whether you were viewing active or archived chats for the current workspace, then restores that state when you refresh or reopen AI Chat. AI Chat supports session-scoped file attachments. Attachment uploads require a chat session and are limited by the MAGE_CODEX_CHAT_ATTACHMENT_MAX_BYTES, MAGE_CODEX_CHAT_ATTACHMENT_MAX_COUNT, and MAGE_CODEX_CHAT_ATTACHMENT_MAX_SESSION_BYTES environment variables. When Codex returns a project-local PNG, JPEG, GIF, or WebP path, AI Chat renders the image inline. The path can be on its own line, embedded in prose, such as Here it is: /home/src/demo/cyborg_mage.png, or used as a Markdown link target, such as [output/anime_styled_mage.png](output/anime_styled_mage.png). The preview is served through a short-lived authenticated URL, so the image file does not need a public URL. For direct model authentication, configure MAGE_CODEX_CHAT_OPENAI_API_KEY or store the key in a Mage secret named by MAGE_CODEX_CHAT_OPENAI_API_KEY_SECRET. OPENAI_API_KEY is also accepted as a fallback. For Mage Pro proxy authentication, set MAGE_CODEX_MODEL_AUTH_MODE=proxy and configure either MAGE_CODEX_MODEL_PROXY_BASE_URL or MAGE_PRO_API_ENDPOINT with MAGE_PRO_API_API_KEY. The chat model, reasoning effort, service tier, and concurrency defaults can be configured with the MAGE_CODEX_CHAT_* environment variables listed in Environment variables.

Generate pipeline using AI

When creating a new pipeline, select the option labeled Using AI. Then, type the description of what the pipeline should do. For example: Load data from an API, then clean the column names, and finally export the dataframe to PostgreSQL. Generate pipeline using AI

Generate block using AI

You must turn on the feature named add_new_block_v2 in your project settings. (click the “wizard” in the top right > Workspace > Preferences)
When adding a new block, type in the description of what you want the block to do. In the autocomplete dropdown list, select the 1st option with a label starting with Generate block using AI: … Generate block using AI

Document code using AI

Add documentation using AI

Add documentation for a block

On the edit pipeline page in the top right corner of a block, click the AI actions icon. Select the option labeled Document block.

Add documentation for a pipeline and all its blocks

On the edit pipeline page in the top right corner of a block, click the AI actions icon. Select the option labeled Document pipeline and all blocks.

Add comments in a block

On the edit pipeline page in the top right corner of a block, click the AI actions icon. Select the option labeled Add comments in code.