AI Gateway Google and Vertex Reasoning
Gemini 2.5 and later models use an internal "thinking process" that improves their reasoning and multi-step planning abilities, making them effective for complex tasks like coding, advanced mathematics, and data analysis.
These models are available through both Google AI and Google Vertex AI providers. The thinking configuration is the same. The only difference is using providerOptions.vertex instead of providerOptions.google. To route through Vertex, configure Vertex AI credentials and set the provider order to prefer vertex.
- Gemini 3 and later: Use
thinkingLevelto control the depth of reasoning - Gemini 2.5: Use
thinkingBudgetto set a token limit for thinking
See the AI SDK Google provider reference for supported reasoning options and response metadata.
To see the current list of Google reasoning models, use the Reasoning filter on the AI Gateway models page.
The thinkingLevel parameter controls reasoning behavior:
| Thinking level | Description |
|---|---|
minimal | Matches "no thinking" for most queries. The model may still think minimally for complex coding tasks. Best for latency-sensitive workloads. |
low | Minimizes latency and cost. Use for instruction following and chat with low reasoning requirements. |
medium | Balanced thinking for most tasks. |
high | Maximizes reasoning depth. The model may take significantly longer to reach a first output token. |
Select the exact model in GET /v1/models and read the effort values in reasoning_options. Don't infer a new Flash or Pro model's supported levels or default from an older generation. The catalog doesn't expose a structured default; consult the Google thinking documentation for model-specific behavior.
The shared effort mapping and native thinkingLevel can differ. AI Gateway's cross-provider translation maps low to low and other effort levels to high on Gemini 3-family models. To request a native minimal or medium level listed in the catalog, use the serving provider's thinkingConfig.thinkingLevel option and verify support.
The thinkingBudget parameter sets a specific number of thinking tokens. Set thinkingBudget to 0 to disable thinking, or -1 to enable dynamic thinking (the model adjusts based on request complexity).
For an exact budget, check the model's budget_tokens entry in catalog discovery. Apply min and max when present; missing bounds don't mean an unlimited budget. The Google thinking documentation describes disabling thinking and dynamic budgets for each model.
The AI SDK 7 top-level reasoning option works across Gemini models without provider-specific configuration. On Gemini 3 and later it maps to thinkingLevel; on Gemini 2.5, AI Gateway maps effort to a thinking-token budget:
import { generateText } from 'ai';
const result = await generateText({
model: 'google/gemini-3.6-flash',
prompt: 'What is the sum of the first 10 prime numbers?',
reasoning: 'high',
});
console.log(result.text);Use providerOptions when you need an exact thinkingBudget, includeThoughts, or Gemma's chat_template_kwargs. If you set thinkingConfig in providerOptions, it takes precedence over the top-level reasoning value.
Check the catalog and the serving provider before configuring Gemma reasoning. The model's reasoning tag alone doesn't establish support for chat_template_kwargs or guarantee reasoning deltas. AI Gateway's shared reasoning translation currently treats Gemma as unsupported. For native provider options, verify both successful stream completion and reasoning output before relying on them.
Use the thinkingLevel parameter to control the depth of reasoning:
import { generateText } from 'ai';
const result = await generateText({
model: 'google/gemini-3.6-flash',
prompt: 'What is the sum of the first 10 prime numbers?',
providerOptions: {
vertex: { // use vertex or google
thinkingConfig: {
thinkingLevel: 'high',
includeThoughts: true,
},
},
},
});
console.log(result.text);
console.log(result.reasoningText);Use the thinkingBudget parameter to control the number of thinking tokens:
import { generateText } from 'ai';
const result = await generateText({
model: 'google/gemini-2.5-flash',
prompt: 'What is the sum of the first 10 prime numbers?',
providerOptions: {
vertex: { // use vertex or google
thinkingConfig: {
thinkingBudget: 8192,
includeThoughts: true,
},
},
},
});
console.log(result.text);
console.log(result.reasoningText);When streaming, thinking tokens are emitted as reasoning-delta stream parts:
import { streamText } from 'ai';
const result = streamText({
model: 'google/gemini-2.5-flash',
prompt: 'Explain quantum computing in simple terms.',
providerOptions: {
vertex: { // use vertex or google
thinkingConfig: {
thinkingBudget: 2048,
includeThoughts: true,
},
},
},
});
for await (const part of result.stream) {
if (part.type === 'reasoning-delta') {
process.stdout.write(part.text);
} else if (part.type === 'text-delta') {
process.stdout.write(part.text);
}
}import { streamText } from 'ai';
const result = streamText({
model: 'google/gemini-2.5-flash',
prompt: 'Explain quantum computing in simple terms.',
providerOptions: {
vertex: { // use vertex or google
thinkingConfig: {
thinkingBudget: 2048,
includeThoughts: true,
},
},
},
});
for await (const part of result.fullStream) {
if (part.type === 'reasoning-delta') {
process.stdout.write(part.text);
} else if (part.type === 'text-delta') {
process.stdout.write(part.text);
}
}You can configure thinking without the AI SDK through the gateway's OpenAI-compatible endpoints. AI Gateway maps the reasoning effort level to the model's native thinking configuration:
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: process.env.AI_GATEWAY_API_KEY,
baseURL: 'https://ai-gateway.vercel.sh/v1',
});
const completion = await openai.chat.completions.create({
model: 'google/gemini-3.6-flash',
messages: [
{
role: 'user',
content: 'What is the sum of the first 10 prime numbers?',
},
],
// AI Gateway extension fields are not included in the upstream SDK types.
...{
reasoning: {
effort: 'high',
},
},
});
const message = completion.choices[0].message;
console.log(
'Reasoning:',
'reasoning' in message ? message.reasoning : undefined,
);
console.log('Answer:', completion.choices[0].message.content);import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv('AI_GATEWAY_API_KEY'),
base_url='https://ai-gateway.vercel.sh/v1'
)
completion = client.chat.completions.create(
model='google/gemini-3.6-flash',
messages=[
{
'role': 'user',
'content': 'What is the sum of the first 10 prime numbers?'
}
],
extra_body={
'reasoning': {
'effort': 'high'
}
}
)
print('Reasoning:', completion.choices[0].message.reasoning)
print('Answer:', completion.choices[0].message.content)curl https://ai-gateway.vercel.sh/v1/chat/completions \
-H "Authorization: Bearer $AI_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.6-flash",
"messages": [
{
"role": "user",
"content": "What is the sum of the first 10 prime numbers?"
}
],
"reasoning": {
"effort": "high"
}
}'Native chat_template_kwargs support depends on the serving provider. See Gemma 4 models before using this configuration; it isn't a shared AI Gateway reasoning control.
| Parameter | Type | Description |
|---|---|---|
thinkingLevel | string | Depth of reasoning: 'minimal', 'low', 'medium', 'high' |
includeThoughts | boolean | Include thinking content in the response |
| Parameter | Type | Description |
|---|---|---|
thinkingBudget | number | Maximum number of tokens to allocate for thinking |
includeThoughts | boolean | Include thinking content in the response |
For more details, see the Google AI thinking docs and Vertex AI thinking docs.
Was this helpful?