Skip to main content

Overview

Generation functions accept configuration options as flat top-level parameters on the options object. The core options temperature, 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 on BaseGenerateOptions 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: number
Range: 0.0 to 2.0 (provider-dependent)
Default: Usually 1.0
Use low temperature (0.0-0.3) for factual tasks, code generation, and consistency. Use high temperature (1.0-2.0) for creative writing, brainstorming, and varied outputs.

maxTokens

Maximum number of tokens to generate in the response. Type: number
Range: 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.
Token Estimation:
  • 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: number
Range: 0.0 to 1.0
Default: Usually 1.0
Don’t use both high temperature and low topP together. They serve similar purposes and can conflict. Choose one approach.

Provider-specific options

Options like stopSequences, frequencyPenalty, and presencePenalty are not part of the core options. They are passed through providerOptions, namespaced by provider:
Each provider defines and validates its own set of options. See the provider pages for the full schema:
  • OpenAI — Responses API (openai.chatModel()): store, serviceTier, include, parallelToolCalls, user. Chat Completions API (openai.chat.chatModel()): store, serviceTier, parallelToolCalls, user, stopSequences, frequencyPenalty, presencePenalty, seed
  • AnthropictopK, stopSequences, betas, outputConfig, cacheControl
  • Google GenAIstopSequences, frequencyPenalty, presencePenalty, seed, topK
  • MistralstopSequences, frequencyPenalty, presencePenalty, randomSeed, parallelToolCalls, promptMode, safePrompt

stopSequences

Array of sequences that stop generation when encountered. Passed via providerOptions:
stopSequences support varies by provider. For OpenAI, it is available with openai.chat.chatModel() and @core-ai/openai-compat. Responses models do not support it.

frequencyPenalty

Reduces likelihood of repeating tokens based on how often they’ve appeared. Range: -2.0 to 2.0 (provider-dependent)
Use frequencyPenalty between 0.5-1.0 for creative writing or lists where you want diverse output without repetitive phrases.

presencePenalty

Reduces likelihood of tokens that have already appeared at least once. Range: -2.0 to 2.0 (provider-dependent)
Difference from Frequency Penalty:
  • presencePenalty: Binary — penalizes any token that appeared at least once
  • frequencyPenalty: Proportional — penalizes based on how many times token appeared

Complete configuration example

Reasoning configuration

For models that support extended thinking:
Usage:
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:
Creative Writing:
Question Answering:
Brainstorming/Ideas:

Testing configurations

Start with default settings and adjust one parameter at a time. Temperature is usually the most impactful setting to tune first.

Usage tracking

All generation results include token usage information:
Example:

Abort signal

Cancel long-running requests with AbortSignal:

Next Steps