Exclude domains from web search
Exclude domains from web search
Pass excluded_domains (max 5) on the web_search tool so Grok skips those hosts when searching and browsing. Base setup: Add web search to a Grok API request. To lock search to a short allowlist instead, see Restrict web search to allowed domains.
xAI SDK
import os
from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import web_search
client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
model="grok-4.6",
tools=[
web_search(excluded_domains=["example-spam.com", "example-aggregator.com"]),
],
)
chat.append(user("Summarize recent coverage of Grok 4.6 releases."))
response = chat.sample()
print(response.content)
OpenAI Responses
{
"model": "grok-4.6",
"input": [
{
"role": "user",
"content": "Summarize recent coverage of Grok 4.6 releases."
}
],
"tools": [
{
"type": "web_search",
"filters": {
"excluded_domains": ["example-spam.com", "example-aggregator.com"]
}
}
]
}
curl https://api.x.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-d '{
"model": "grok-4.6",
"input": [
{
"role": "user",
"content": "Summarize recent coverage of Grok 4.6 releases."
}
],
"tools": [
{
"type": "web_search",
"filters": {
"excluded_domains": ["example-spam.com", "example-aggregator.com"]
}
}
]
}'
Pitfalls
excluded_domainsandallowed_domainscannot share the same request (max 5 each).- Domains are host names the tool should skip, not URL paths.
- Console API credits are separate from SuperGrok's weekly pool on grok.com.