Variable: tools
@providerprotocol/ai / xai / tools
Variable: tools
Section titled “Variable: tools”
consttools: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').
Type Declaration
Section titled “Type Declaration”codeExecution()
Section titled “codeExecution()”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.
Returns
Section titled “Returns”A code execution tool configuration object
Example
Section titled “Example”const codeExec = codeExecutionTool();fileSearch()
Section titled “fileSearch()”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.
Parameters
Section titled “Parameters”options
Section titled “options”File search configuration
max_num_results?
Section titled “max_num_results?”number
retrieval_mode?
Section titled “retrieval_mode?”"keyword" | "semantic" | "hybrid"
vector_store_ids
Section titled “vector_store_ids”string[]
Returns
Section titled “Returns”A file search tool configuration object
Example
Section titled “Example”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).
Parameters
Section titled “Parameters”options
Section titled “options”MCP server configuration
allowed_tool_names?
Section titled “allowed_tool_names?”string[]
authorization?
Section titled “authorization?”string
extra_headers?
Section titled “extra_headers?”Record<string, string>
server_description?
Section titled “server_description?”string
server_label?
Section titled “server_label?”string
server_url
Section titled “server_url”string
Returns
Section titled “Returns”An MCP tool configuration object
Example
Section titled “Example”const mcp = mcpTool({ server_url: 'https://my-mcp-server.com/sse', server_label: 'my_tools', allowed_tool_names: ['get_weather', 'search_db'],});webSearch()
Section titled “webSearch()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional configuration for search behavior
allowed_domains?
Section titled “allowed_domains?”string[]
enable_image_understanding?
Section titled “enable_image_understanding?”boolean
excluded_domains?
Section titled “excluded_domains?”string[]
Returns
Section titled “Returns”A web search tool configuration object
Example
Section titled “Example”// Basic web searchconst search = webSearchTool();
// With domain restrictionsconst searchWithDomains = webSearchTool({ allowed_domains: ['wikipedia.org', 'github.com'],});xSearch()
Section titled “xSearch()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional configuration for search behavior
allowed_x_handles?
Section titled “allowed_x_handles?”string[]
enable_image_understanding?
Section titled “enable_image_understanding?”boolean
enable_video_understanding?
Section titled “enable_video_understanding?”boolean
excluded_x_handles?
Section titled “excluded_x_handles?”string[]
from_date?
Section titled “from_date?”string
to_date?
Section titled “to_date?”string
Returns
Section titled “Returns”An X search tool configuration object
Example
Section titled “Example”// Basic X searchconst xSearch = xSearchTool();
// With handle and date filtersconst filteredSearch = xSearchTool({ allowed_x_handles: ['elonmusk', 'xai'], from_date: '2025-01-01', to_date: '2025-12-31',});Example
Section titled “Example”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'], },});