Generate Text
Generate Text
Generate text from prompts using AI. Simple interface with character counting and response rendering.
Loading preview…
Problems solved
- Generate complete text responses with generateText
- Call an AI Gateway model from a minimal API route
- Show non-streaming prompt-to-text results in the UI
Use cases
- Simple AI prompt boxes
- One-shot text completion tools
- AI SDK generateText onboarding demos
- Basic assistant reply prototypes
Setup
Requirements, wiring steps, and what this pattern adds to your project.
Getting started
Pick how you want to pull this pattern in — then wire env vars and routes the same way.
- 1
Install from the preview toolbar

Copy the install command above and run it in your project — Pro patterns include a short-lived token.
- 2
Add environment variables to .env.local
OPENAI_API_KEY
- 3
Point client fetches at your API routes
Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.
- 4
Customize the agent and tool files
Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.
- 5
Run your dev server and open the pattern route
Install dependencies if needed, then start the app and verify responses.
Environment variables
OPENAI_API_KEYGet key
Capabilities
AI SDK APIs
generateTextconvertToModelMessagesProviders
Files added
4 filesapp/page.tsxapp/layout.tsxcomponents/basic-generate-text-form.tsxapp/api/generate-text/route.ts
Dependencies
8 totalnpm packages
4
Registry components
Critical files
generate-text/route.tsAPI route demonstrating the AI SDK generateText function with gateway pattern. Shows the basic non-streaming text generation pattern with system prompt and JSON response.
Requirements
- Complexity
- Beginner









