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 agno

Authentication

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.")

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?")
View more examples here.

Parameters

ParameterTypeDefaultDescription
idstr"grok-4-1-fast-non-reasoning-latest"The id of the xAI model to use
namestr"xAI"The name of the model
providerstr"xAI"The provider of the model
api_keyOptional[str]NoneThe API key for xAI (defaults to XAI_API_KEY env var)
base_urlstr"https://api.x.ai/v1"The base URL for the xAI API
search_parametersOptional[Dict[str, Any]]NoneLegacy Chat Completions passthrough; use xAIResponses tools for native search

xAI inherits the parameters of OpenAIChat. Provider and model support can differ; see model compatibility.