Functions
search-all
fn (model: Str, query: Str): Str
fn (model: Str, query: Str, instructions: Str): Str
Search both web and X simultaneously, returning an AI-summarized response.
Combines web-search-tool() and x-search-tool() for comprehensive coverage. Optionally pass system instructions as a third argument.
Example
answer search-all("grok-3", "What's happening with climate change today?")
// => "Based on web and X sources..."
search-web
fn (model: Str, query: Str): Str
fn (model: Str, query: Str, instructions: Str): Str
Search the web and get an AI-summarized response.
This is a convenience function that enables web search and returns the model's response text with real-time web information. Optionally pass system instructions as a third argument.
Example
answer search-web("grok-3", "What is the current weather in San Francisco?")
// => "Currently in San Francisco, it's 62°F..."
// With instructions
answer search-web("grok-3", "Latest AI news", "Summarize in bullet points.")
search-x
fn (model: Str, query: Str): Str
fn (model: Str, query: Str, instructions: Str): Str
Search X (Twitter) and get an AI-summarized response.
This is a convenience function that enables X search and returns the model's response text with real-time information from X posts. Optionally pass system instructions as a third argument.
Example
answer search-x("grok-3", "What are people saying about the latest tech news?")
// => "Here's what people are discussing on X..."
// With instructions
answer search-x("grok-3", "Reactions to the new iPhone", "Focus on sentiment analysis.")
web-search-tool
fn (): SearchTool
Create a web search tool configuration for the Responses API.
Use this in the tools array of a CreateResponseRequest to enable real-time web search. The model will automatically decide when to search based on the query.
Example
response ::xai::responses/create(::xai::responses/CreateResponseRequest({
model: "grok-3",
input: "What is the latest news about AI?",
tools: [web-search-tool()]
}))
x-search-tool
fn (): SearchTool
Create an X (Twitter) search tool configuration for the Responses API.
Use this in the tools array of a CreateResponseRequest to enable real-time X search. The model will automatically decide when to search based on the query.
Example
response ::xai::responses/create(::xai::responses/CreateResponseRequest({
model: "grok-3",
input: "What are people saying about the new iPhone?",
tools: [x-search-tool()]
}))
Types
SearchTool
SearchTool type {
type: Str
}
WebSearchResult
WebSearchResult type {
url: Str?,
title: Str?,
snippet: Str?
}
XSearchResult
XSearchResult type {
tweet_id: Str?,
author: Str?,
text: Str?,
created_at: Str?
}