Skip to main content

Settings

AI SDK Core functions support a variety of settings to control model behavior, generation quality, and execution flow. These settings work across all providers with a standardized interface.

Common Settings

All AI SDK functions (generateText, streamText) support these common settings:

maxOutputTokens

Maximum number of tokens to generate:
number
Maximum number of tokens to generate. Use this to control response length and costs.

temperature

Controls randomness in generation:
number
Controls randomness. Lower values (closer to 0) make output more deterministic. Higher values increase creativity and variation. Range depends on provider.
Recommended to set either temperature or topP, but not both.

topP

Nucleus sampling parameter:
number
Nucleus sampling. Consider only tokens with the top P probability mass. For example, 0.1 means only tokens in the top 10% are considered.

topK

Sample from top K options:
number
Sample from the top K options for each token. Removes “long tail” low probability responses. Advanced use cases only.

presencePenalty

Penalty for repeating information already in the prompt:
number
Affects likelihood of repeating information from the prompt. For most providers, 0 means no penalty.

frequencyPenalty

Penalty for using the same words repeatedly:
number
Affects likelihood of repeatedly using the same words or phrases. For most providers, 0 means no penalty.

stopSequences

Stop generation when specific sequences are encountered:
string[]
Array of sequences that stop generation when encountered. Providers may limit the number of stop sequences.

seed

Seed for deterministic results:
number
Integer seed for random sampling. When set and supported by the model, generates deterministic results.

Retry and Timeout Settings

maxRetries

Configure automatic retries for failed requests:
number
default:"2"
Maximum number of retries for failed requests. Set to 0 to disable retries.

abortSignal

Cancel requests programmatically:
AbortSignal
Abort signal for canceling the request. Can be forwarded from UI or created with AbortSignal.timeout().

Using AbortSignal.timeout

timeout

Simplified timeout configuration:
number | object
Timeout in milliseconds (number) or object with granular settings:
  • totalMs: Total timeout for entire operation
  • stepMs: Timeout per step (for multi-step operations)
  • chunkMs: Timeout between stream chunks (streaming only)

Chunk Timeout (Streaming)

Request Settings

headers

Add custom HTTP headers:
Record<string, string>
Custom HTTP headers to include in the request. Only applicable for HTTP-based providers.
The headers setting is for request-specific headers. You can also set headers in provider configuration for all requests.

Provider-Specific Settings

Use providerOptions for provider-specific features:
object
Provider-specific options. See individual provider documentation for available options.

Settings for Specific Use Cases

Deterministic Output

For consistent, reproducible results:

Creative Writing

For varied, creative responses:

Tool Calling

For reliable tool execution:

Long-Running Requests

For operations that may take time:

Checking for Unsupported Settings

Not all providers support all settings. Check warnings:

Settings Reference

Generation Parameters

Execution Control

Best Practices

1. Use Temperature 0 for Structured Output

2. Set Timeouts for Production

3. Don’t Set Both Temperature and TopP

4. Check Warnings

Always check for provider warnings:

Next Steps

Generating Text

Learn about text generation

Prompt Engineering

Optimize your prompts

Tool Calling

Use tools with models