xAI
Use xAI Grok models with Agno agents.
xAI provides the Grok family of large language models. See the xAI model catalog.
The examples select Grok 4.5 explicitly. Choose a model available to your account; the adapter default in the table below is the literal default in Agno.
Installation
uv pip install openai agnoAuthentication
Set your XAI_API_KEY environment variable. You can get one from xAI here.
export XAI_API_KEY="YOUR_API_KEY"Example
Use xAI with your Agent:
from agno.agent import Agent
from agno.models.xai import xAI
agent = Agent(
model=xAI(id="grok-4.5"),
markdown=True
)
agent.print_response("Share a 2 sentence horror story.")Live Search
Use xAIResponses for native web and X search:
Native web search and X search use the Responses API. Pass web_search and x_search tool dictionaries to the agent with xAIResponses; the legacy xAI.search_parameters option targets Chat Completions and does not enable these Responses tools.
from agno.agent import Agent
from agno.models.xai import xAIResponses
agent = Agent(
model=xAIResponses(id="grok-4.5"),
tools=[{"type": "web_search"}, {"type": "x_search"}],
markdown=True,
)
agent.print_response("What's the latest news about AI developments?")Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
id | str | "grok-4-1-fast-non-reasoning-latest" | The id of the xAI model to use |
name | str | "xAI" | The name of the model |
provider | str | "xAI" | The provider of the model |
api_key | Optional[str] | None | The API key for xAI (defaults to XAI_API_KEY env var) |
base_url | str | "https://api.x.ai/v1" | The base URL for the xAI API |
search_parameters | Optional[Dict[str, Any]] | None | Legacy Chat Completions passthrough; use xAIResponses tools for native search |
xAI inherits the parameters of OpenAIChat. Provider and model support can differ; see model compatibility.