By the end of this tutorial you’ll have a deployable Next.js 15 application that takes a text prompt, calls the Livepeer AI network through a server action, and displays the generated image alongside a history of past generations. The path uses Next.js 15’s App Router and server actions, the
@livepeer/ai TypeScript SDK, and the free Cloud Community Gateway from the .
This is the Persona 1 builder activation moment: the AI Jobs Quickstart proved the API call works; this tutorial proves it ships. Replace the community Gateway with a paid one when you deploy to users.
Required Tools
- Node.js 20 or later
npm,pnpm, oryarn- A code editor
Project Bootstrap
1
Create the Next.js project
--app), a src/ layout, TypeScript, Tailwind, and the @/* import alias. Accept the default for any remaining prompts.2
Install the Livepeer AI SDK
3
Configure environment variables
Save as The community Gateway is fine for development. For production, swap to a paid Gateway URL and add
.env.local:LIVEPEER_API_KEY for Bearer authentication.Server Action
The server action runs server-side, which means the Gateway call happens on your Next.js host instead of the browser. This keeps any future API key out of client-side bundles and centralises retry logic.1
Create the action file
Save as The
src/app/actions.ts:'use server' directive at the top marks every export as a server action. Client components can import and call generateImage as if it were a local function; Next.js handles the network round trip.UI Form Component
Save assrc/app/components/PromptForm.tsx:
useFormStatus reads the submission state of the parent form, which gives the button a pending flag without any extra wiring. The MODELS array maps to the warm models verified in the reference.
Image Gallery
The gallery holds generation history in client state. For production, swap the in-memory state for a database or local storage. Save assrc/app/components/Gallery.tsx:
unoptimized on the <Image> component skips Next.js’s image optimisation, which is necessary because the Gateway returns URLs Next.js can’t proxy through its own _next/image endpoint without remote-pattern configuration.
To allow Next.js optimisation instead, add the Gateway host to next.config.ts:
Page Composition
Save assrc/app/page.tsx:
http://localhost:3000. Type a prompt, click Generate, and the gallery populates with your first image.
Production Considerations
The community Gateway is shaped for experimentation. Production deployments need four changes. One. Switch to a paid Gateway. SetLIVEPEER_GATEWAY_URL to a paid Gateway endpoint and add LIVEPEER_API_KEY to the environment. Update the SDK initialisation to pass the key in the auth header.
Two. Rate-limit per user. Server actions run on your Next.js host; a malicious client can submit the form in a tight loop. Add a per-IP or per-session limit using a Redis backend or a serverless rate-limit library.
Three. Cache and persist. Generation costs money. Cache results by (prompt, modelId, seed) and persist gallery state in a database so users keep their history across sessions.
Four. Move large images out of the response path. The Gateway returns a hosted URL; download and rehost on your own CDN for control over availability and retention.
Full hardening guidance in .
Common Errors
`@livepeer/ai` import fails after install
`@livepeer/ai` import fails after install
The package needs Node 20 or later for the
fetch polyfill it relies on. Confirm node --version and upgrade if needed.`Gateway call failed: No orchestrator available`
`Gateway call failed: No orchestrator available`
No Orchestrator on the network has capacity for the requested model right now. Retry, or fall back to the other warm model from the
MODELS array.Image renders broken in the gallery
Image renders broken in the gallery
Either
unoptimized is missing from <Image>, or the Gateway host is missing from next.config.ts remotePatterns. Pick one path.Server action returns 405 in production
Server action returns 405 in production
Server actions need a runtime that supports them. Vercel, Cloudflare, and Node servers all work; static-only hosts (GitHub Pages, plain S3) don’t. Deploy to a runtime host.
Cold-start delay on first request
Cold-start delay on first request
The first request to a cold model triggers a 30-second to multi-minute load. Add a loading state in the UI and consider warming the model on app start by sending a dummy request.
AI agent prompt
Next Steps
AI Pipelines
The other ten pipelines: LLM, audio-to-text, image-to-video, segmentation, and more.
Model Support
Warm models, VRAM requirements, custom-model paths.
Chatbot Tutorial
Build a streaming chat app on the LLM pipeline.
Production Hardening
Rate limits, caching, auth, observability before ship.