One prompt, one string back
This is the smallest useful call: one function on the server, one string back. Learn it before streaming or tools.
This is the smallest useful call in the AI SDK. Run it on the server — a script, a Route Handler, a server action. getModel() reads DEFAULT_MODEL. You wait. text is a string you can log, save, or return as JSON.
prompt is the short form: a single user turn, no history. Use it for one-shot jobs (summarize this, name this). Chat products almost always use messages instead, because they need a system prompt and a thread. Same function, two input shapes.
Files
- 01
Import from ai, not from OpenAI
generateText is the AI SDK. Importing a vendor SDK here locks you to one HTTP dialect and throws away streaming and tools later.
- 02
getModel() picks the provider
DEFAULT_MODEL becomes a Gateway id. You do not hardcode openai('gpt-4o') in lesson code.
- 03
prompt is the short form
One string, treated as a user message. No system instructions unless you stuff them into the same string — which you should not, once you have messages.
- 04
await means wait
Nothing is returned until the model finishes. Slower to feel than ChatGPT, but you can reason about one value. Streaming is the same call with a different return.
The same call, as a chat
Replace prompt with messages when you need roles or history. This is the shape every later lesson uses — streaming, tools, structured output. Learn it here while the result is still a quiet string.
After the call, if you want a thread, you append { role: 'assistant', content: text } yourself and save the array. Forget that step and the next request has no past.
Files
- 01
system is the rulebook
Put durable instructions here, not in every user line. Short system prompts cost fewer tokens and are easier to audit.
- 02
user is this turn
In a real app this string comes from the request body. It is data. Never eval it. Never concatenate it into SQL.
- 03
You would append the assistant reply
Push { role: 'assistant', content: text } onto the array and persist it if the next turn should remember. The API will not.
When to wait, when not to
Wait (generateText) is the right default for scripts, cron, classification, and anything you assert on in a test. You get one object. You can JSON.stringify it.
Do not wait in a chat UI. Users stare at a spinner for a paragraph they could have started reading. That is Day 3. The messages you learned here do not change.
Docs
Official API reference for this chapter.
Common questions
- What is “generateText — wait for the answer”?
- The smallest useful AI SDK call: pick a model, send a prompt, read text.
- How long does this lesson take?
- About 16 minutes of reading. It is a free chapter in the AI SDK Patterns TypeScript course.
- When should I not use this?
- Wait (generateText) is the right default for scripts, cron, classification, and anything you assert on in a test. You get one object. You can JSON.stringify it.
Written by Akash Panchal·Updated August 29, 2026