Skip to Content
FeaturesAI Generation

AI Generation

A generic, provider-agnostic generation pipeline runs one or more model steps behind the credit/subscription paywall. Today it ships a Replicate runner, and the pipeline executor itself is pure — it accepts any model step.

The generateAI server action

Exposed to any interface (form, MCP tool, REST endpoint). generateAI runs one or more model steps, optionally chaining one step’s output into the next, behind the credit/subscription paywall. It returns the generated output and the customer’s remaining credits.

import { generateAI } from '@/actions/generate' await generateAI({ steps: [ { model: 'black-forest-labs/flux-schnell', input: { prompt: 'a cat' } }, ], paywallConfig: { enableCredits: true, credits: 1 }, // or null for free })

Returns the generated results, the finalOutput, and creditsRemaining.

For multi-step runs, add a chainAs key to a later step to inject the previous step’s output into its input under that key (ignored on the first step). This lets you compose model steps without a custom adapter per pair.

Paywall integration

The paywallConfig argument flows through the same paywall system used by gated content (see Monetization & Payments):

  • { enableCredits: true, credits: N } — require and decrement N credits per generation.
  • { enableSubscription: true, minimum_tier_rank: N } — gate behind a subscription tier.
  • null — free.

The paywall is enforced before any model runs. If the customer doesn’t meet the requirement, generateAI raises a payment-required error and the model is never called — no credits are spent on a denied request.

The generation-section-block

A shipped Payload block (generation-section-block) puts the pipeline behind a page builder block. It stores:

  • userInputs — form field definitions shown to the user at runtime. Reference them as {variableName} placeholders in a step’s model defaults.
  • steps — the pipeline steps (model + defaults, with optional chainAs chaining).
  • enablePaywall + credits — when paywall is on, users spend the configured credits per run.

At render time the block resolves the {variableName} placeholders from the user’s form input and calls generateAI with the resolved steps. Template resolution is the block’s job — the pipeline always receives already-resolved inputs.

On-demand vs. pre-generated

The pipeline supports both modes:

  • On-demand — a user fills a form (or an agent calls generateAI), pays the credit cost, and the model runs. Output is returned and (optionally) persisted as a records row.
  • Pre-generated — a batch job runs the pipeline against a list of seed prompts/keywords overnight, writes outputs to records, and the /explore browse surface presents them at zero per-request cost.

The “AI Asset Library” shape uses both: a seed batch for SEO inventory, plus on-demand generation triggered by users via the credit system.

Provider-agnostic by design

The pipeline executor is pure and dependency-injected. The Replicate runner ships today; adding another provider doesn’t change the pipeline — it accepts any model step.