Vercel AI SDK integration for text and image generation.
Starter comes with a pre-configured Chat And Image generation AI features set using the Vercel AI SDK. It includes built-in support for Gemini and a robust mocking system for local development.
Generate a Gemini API key from Google AI Studio and add it to your .env file.
GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_keyTo switch providers (e.g., to OpenAI), simply update the provider factory and model strings in this file (its also type-safe).
const openAIModel = openai("model-of-your-choice");The AI feature is split into server-side logic and client-side state management:
chat.ts, image.ts)These files export generateTextFn and generateImageFn. They interact directly with the AI SDK.
"use server" to ensure AI logic and environment variables are executed exclusively on the server, preventing sensitive configurations from being exposed to the client.config.mock.ts. To use real AI, change the import to ./config.use-image-gen.ts)We use TanStack Form and TanStack Query to manage the AI lifecycle:
zod handles prompt length, image constraints and form reset.useMutation triggers the server action and handles the loading state.history state keeps track of generations within the current session.The ImageGeneration component is a complete "Studio" UI:
| Task | Action |
|---|---|
| Go Live | Change imports in chat.ts/image.ts from ./config.mock to ./config. |
| Change Constraints | Update the Zod schema in user-image-gen.ts. |
| Switch Provider | Install the SDK (e.g., @ai-sdk/openai) and update config.ts. |
config.mock.ts during UI development to avoid unnecessary costs.generateImageFn with your database and S3 bucket.