Overview
Generation functions accept configuration options as flat top-level parameters on the options object. The core optionstemperature, maxTokens, and topP are available on every generation call. Additional parameters like stopSequences, frequencyPenalty, and presencePenalty are provider-specific and passed via providerOptions.
Core options
These options are available onBaseGenerateOptions and apply to generate(), stream(), generateObject(), and streamObject():
temperature
Controls randomness in the output. Higher values make output more creative and random, lower values make it more focused and deterministic. Type:numberRange:
0.0 to 2.0 (provider-dependent)Default: Usually
1.0
maxTokens
Maximum number of tokens to generate in the response. Type:numberRange: Varies by model and provider
Some providers (like Anthropic) require
maxTokens to be set. The provider wrapper may set a default value if not specified.- 1 token ≈ 0.75 words (English)
- 100 tokens ≈ 75 words
- 1000 tokens ≈ 750 words
topP
Nucleus sampling: considers only tokens whose cumulative probability is above this threshold. Type:numberRange:
0.0 to 1.0Default: Usually
1.0
Provider-specific options
Options likestopSequences, frequencyPenalty, and presencePenalty are not part of the core options. They are passed through providerOptions, namespaced by provider:
- OpenAI — Responses API (
openai.chatModel()):store,serviceTier,include,parallelToolCalls,user. Chat Completions API (openai.chat.chatModel()):store,serviceTier,parallelToolCalls,user,stopSequences,frequencyPenalty,presencePenalty,seed - Anthropic —
topK,stopSequences,betas,outputConfig,cacheControl - Google GenAI —
stopSequences,frequencyPenalty,presencePenalty,seed,topK - Mistral —
stopSequences,frequencyPenalty,presencePenalty,randomSeed,parallelToolCalls,promptMode,safePrompt
stopSequences
Array of sequences that stop generation when encountered. Passed viaproviderOptions:
frequencyPenalty
Reduces likelihood of repeating tokens based on how often they’ve appeared. Range:-2.0 to 2.0 (provider-dependent)
presencePenalty
Reduces likelihood of tokens that have already appeared at least once. Range:-2.0 to 2.0 (provider-dependent)
presencePenalty: Binary — penalizes any token that appeared at least oncefrequencyPenalty: Proportional — penalizes based on how many times token appeared
Complete configuration example
Reasoning configuration
For models that support extended thinking:Reasoning configuration is provider-dependent. Check if your model supports extended thinking before using this option.
Providers interpret reasoning differently. Anthropic and OpenAI enforce model-specific restrictions, Google maps effort to thinking level or budget, and Mistral accepts the option but does not send effort to the API.
Configuration best practices
For different tasks
Code Generation:Testing configurations
Usage tracking
All generation results include token usage information:Abort signal
Cancel long-running requests withAbortSignal:
Next Steps
- Learn about Error Handling for robust applications
- Explore Providers for provider-specific features
- Understand Messages for building conversations