Skip to content

Variable: tools

@providerprotocol/ai


@providerprotocol/ai / xai / tools

const tools: object

Defined in: src/providers/xai/types.ts:608

Namespace object containing all xAI tool helper constructors.

Provides a convenient way to create built-in tool configurations. Note: These tools are only available via the Responses API (api: 'responses').

codeExecution: () => XAICodeExecutionTool = codeExecutionTool

Creates a code execution tool configuration

Creates a code execution tool configuration.

Enables Grok to write and execute Python code in a sandbox. Pricing: $5 per 1,000 successful tool invocations.

XAICodeExecutionTool

A code execution tool configuration object

const codeExec = codeExecutionTool();

fileSearch: (options) => XAIFileSearchTool = fileSearchTool

Creates a file/collections search tool configuration

Creates a file/collections search tool configuration.

Enables Grok to search through uploaded document collections. Pricing: $2.50 per 1,000 successful tool invocations.

File search configuration

number

"keyword" | "semantic" | "hybrid"

string[]

XAIFileSearchTool

A file search tool configuration object

const fileSearch = fileSearchTool({
vector_store_ids: ['vs_abc123'],
max_num_results: 10,
retrieval_mode: 'hybrid',
});

mcp: (options) => XAIMcpTool = mcpTool

Creates a remote MCP server tool configuration

Creates a remote MCP server tool configuration.

Enables Grok to connect to external Model Context Protocol servers. Pricing: Token-based only (no per-invocation charge).

MCP server configuration

string[]

string

Record<string, string>

string

string

string

XAIMcpTool

An MCP tool configuration object

const mcp = mcpTool({
server_url: 'https://my-mcp-server.com/sse',
server_label: 'my_tools',
allowed_tool_names: ['get_weather', 'search_db'],
});

webSearch: (options?) => XAIWebSearchTool = webSearchTool

Creates a web search tool configuration

Creates a web search tool configuration.

Enables Grok to search the web for up-to-date information. Pricing: $5 per 1,000 successful tool invocations.

Optional configuration for search behavior

string[]

boolean

string[]

XAIWebSearchTool

A web search tool configuration object

// Basic web search
const search = webSearchTool();
// With domain restrictions
const searchWithDomains = webSearchTool({
allowed_domains: ['wikipedia.org', 'github.com'],
});

xSearch: (options?) => XAIXSearchTool = xSearchTool

Creates an X (Twitter) search tool configuration

Creates an X (Twitter) search tool configuration.

Enables Grok to search X posts and profiles in real-time. Pricing: $5 per 1,000 successful tool invocations.

Optional configuration for search behavior

string[]

boolean

boolean

string[]

string

string

XAIXSearchTool

An X search tool configuration object

// Basic X search
const xSearch = xSearchTool();
// With handle and date filters
const filteredSearch = xSearchTool({
allowed_x_handles: ['elonmusk', 'xai'],
from_date: '2025-01-01',
to_date: '2025-12-31',
});
import { xai, tools } from 'provider-protocol/xai';
const model = llm({
model: xai('grok-4-1-fast', { api: 'responses' }),
params: {
tools: [
tools.webSearch(),
tools.xSearch({ from_date: '2025-01-01' }),
tools.codeExecution(),
],
include: ['inline_citations', 'code_execution_call_output'],
},
});