---
title: "Generate functions with AI - Workflow Functions"
description: "Connect your Anthropic (Claude) or OpenAI API key and describe a function in plain English - the editor writes the code for you."
canonical: "https://docs.workflow-functions.app/generate-with-ai"
---

# Generate functions with AI

Describe what you want in plain English and let AI write the function. It uses your own AI provider key and is grounded in the Shopify Admin API and this app's runtime, so the code it produces fits straight into a function.

## Connect a provider

On **Developer -> Connections**, add your API key for **Anthropic (Claude)** and/or **OpenAI**:

- Your key is **encrypted at rest** and used only for generation. It is **never** injected into your functions (unlike Secrets) and never shown again after you save it.
- Each card links to where to create a key on the provider's site.

You can connect either provider, or both and pick per generation.

## Generate a function

1. Open a function's **Code** tab. With a provider connected, a **Generate with AI** box appears.
2. Describe the function - be specific about the input and the outcome, for example:
   > When an order is tagged `wholesale`, add the tag `B2B` to that order's customer.
3. Choose the provider (if you connected more than one) and select **Generate**.
4. The generated code loads into the editor. **Review it, test it, then Save.** AI can make mistakes - always run a test before you rely on it.

## What it knows

The generator is told this app's runtime contract, so it uses the right shapes:

- `export default async function (input, ctx)` with `ctx.log`, `ctx.fetch`, and `ctx.shopify.graphql(query, variables)` for the Admin API (current version), and `secrets.NAME` for stored secrets.
- To read or modify store data, the function needs **Needs Shopify data** turned on and the matching permission granted - see [Permissions and store data access](https://docs.workflow-functions.app/permissions-and-store-data-access.md).

> [!NOTE]
> **Your key, your usage**
> Generation runs against your own Anthropic/OpenAI account and counts toward that account's usage and billing - not your Workflow Functions plan. Manual generation and testing never use your Flow run quota.
