Skip to main content
The Vercel AI SDK provides powerful functions for text generation and streaming. Below are details and examples for implementing these functions.

Text Generation

Use generateText() for standard, non-streaming responses.

Streaming Responses

Use streamText() to stream tokens as they are generated.
Streaming improves perceived latency and is recommended for chat interfaces.

System Prompts & Parameters

You can customize model behavior using a system prompt and generation parameters.

Supported Parameters

LanguageModel
required
The model instance to use for generation.
string
The text prompt to generate a response for. Either prompt or messages is required.
string
System instructions to guide the model’s behavior.
number
Controls randomness. Lower values produce more deterministic responses.
number
Maximum number of tokens generated.
number
Nucleus sampling probability.
number
Limits sampling to the top K probable tokens.
number
Encourages introducing new topics.
number
Reduces repeated words or phrases.
number
Produces deterministic outputs when supported.
string[]
Stops generation when one of the specified sequences is encountered.

Error Handling

Wrap SDK calls in a try...catch block to handle API errors, validation failures, and authentication issues.
Common errors include:
  • Invalid API key
  • Incorrect endpoint URL
  • Unsupported model
  • Invalid request parameters
  • Rate limits