Provider-specific options for enhanced functionality including search parameters and reasoning effort configuration.
Comprehensive configuration options specific to xAI models.
interface XaiProviderOptions {
/** Reasoning effort for reasoning models (grok-3-mini and grok-3-mini-fast only) */
reasoningEffort?: 'low' | 'high';
/** Search configuration parameters */
searchParameters?: SearchParameters;
}
interface SearchParameters {
/** Search mode preference */
mode: 'off' | 'auto' | 'on';
/** Whether to return citations in the response (defaults to true) */
returnCitations?: boolean;
/** Start date for search data (ISO8601 format: YYYY-MM-DD) */
fromDate?: string;
/** End date for search data (ISO8601 format: YYYY-MM-DD) */
toDate?: string;
/** Maximum number of search results to consider (1-50, defaults to 20) */
maxSearchResults?: number;
/** Data sources to search from (defaults to ["web", "x"]) */
sources?: Array<
| { type: 'web'; country?: string; excludedWebsites?: string[]; allowedWebsites?: string[]; safeSearch?: boolean; }
| { type: 'x'; xHandles?: string[]; }
| { type: 'news'; country?: string; excludedWebsites?: string[]; safeSearch?: boolean; }
| { type: 'rss'; links: string[]; }
>;
}Reasoning effort settings for compatible models.
interface ReasoningEffortConfig {
reasoningEffort: 'low' | 'high';
}Usage Examples:
import { generateText } from 'ai';
import { xai } from '@ai-sdk/xai';
// Low reasoning effort for faster responses
const quickResult = await generateText({
model: xai('grok-3-mini'),
prompt: 'Simple calculation: 2 + 2',
providerOptions: {
reasoningEffort: 'low',
},
});
// High reasoning effort for complex problems
const complexResult = await generateText({
model: xai('grok-3-mini-fast'),
prompt: 'Solve this complex logic puzzle...',
providerOptions: {
reasoningEffort: 'high',
},
});Comprehensive search functionality configuration.
interface SearchParameters {
mode: 'off' | 'auto' | 'on';
returnCitations?: boolean;
fromDate?: string;
toDate?: string;
maxSearchResults?: number;
sources?: SearchSource[];
}Usage Examples:
import { generateText } from 'ai';
import { xai } from '@ai-sdk/xai';
// Disable search completely
const noSearchResult = await generateText({
model: xai('grok-beta'),
prompt: 'What is the capital of France?',
providerOptions: {
searchParameters: {
mode: 'off',
},
},
});
// Enable search with date range
const currentEventsResult = await generateText({
model: xai('grok-beta'),
prompt: 'Latest developments in AI research',
providerOptions: {
searchParameters: {
mode: 'on',
fromDate: '2024-01-01',
toDate: '2024-12-31',
maxSearchResults: 10,
returnCitations: true,
},
},
});Different data sources available for search functionality.
// Note: These types are not exported from @ai-sdk/xai, they are defined inline
sources?: Array<
| { type: 'web'; country?: string; excludedWebsites?: string[]; allowedWebsites?: string[]; safeSearch?: boolean; }
| { type: 'x'; xHandles?: string[]; }
| { type: 'news'; country?: string; excludedWebsites?: string[]; safeSearch?: boolean; }
| { type: 'rss'; links: string[]; }
>;Usage Examples:
import { generateText } from 'ai';
import { xai } from '@ai-sdk/xai';
// Search with multiple source types
const comprehensiveSearch = await generateText({
model: xai('grok-beta'),
prompt: 'Current status of renewable energy adoption',
providerOptions: {
searchParameters: {
mode: 'on',
sources: [
{
type: 'web',
country: 'US',
safeSearch: true,
allowedWebsites: ['energy.gov', 'iea.org'],
},
{
type: 'news',
country: 'US',
safeSearch: true,
},
{
type: 'x',
xHandles: ['@IEA', '@CleanEnergyNews'],
},
],
maxSearchResults: 15,
returnCitations: true,
},
},
});
// RSS-based search
const rssSearch = await generateText({
model: xai('grok-beta'),
prompt: 'Latest tech industry news',
providerOptions: {
searchParameters: {
mode: 'on',
sources: [
{
type: 'rss',
links: ['https://techcrunch.com/feed/'],
},
],
},
},
});Comprehensive example using all available options.
Usage Examples:
import { generateText } from 'ai';
import { xai } from '@ai-sdk/xai';
const result = await generateText({
model: xai('grok-3-mini'),
prompt: 'Analyze recent AI developments and their impact',
providerOptions: {
reasoningEffort: 'high',
searchParameters: {
mode: 'on',
returnCitations: true,
fromDate: '2024-01-01',
toDate: '2024-12-31',
maxSearchResults: 20,
sources: [
{
type: 'web',
country: 'US',
safeSearch: true,
allowedWebsites: ['arxiv.org', 'openai.com'],
},
{
type: 'news',
country: 'US',
safeSearch: true,
excludedWebsites: ['unreliable-source.com'],
},
{
type: 'x',
xHandles: ['@OpenAI', '@AnthropicAI'],
},
],
},
},
});