Provider for xAI's Grok models.
Thin wrapper around Alloy.Provider.OpenAI that sets xAI defaults.
xAI implements the OpenAI Responses API at https://api.x.ai.
Config
Required:
:api_key- xAI API key:model- Model name (e.g.,"grok-4.3","grok-4.1-fast-reasoning","grok-code-fast-1")
Optional:
:web_search-trueor config map to enable Grok's web search tool:x_search-trueor config map to enable search across X posts- All options from
Alloy.Provider.OpenAI(:max_tokens,:tool_choice, etc.)
Example
Alloy.run("What's happening on X today?",
provider: {Alloy.Provider.XAI,
api_key: System.get_env("XAI_API_KEY"),
model: "grok-4.3",
web_search: true
}
)With X search
Alloy.run("What are people saying about Elixir agents?",
provider: {Alloy.Provider.XAI,
api_key: System.get_env("XAI_API_KEY"),
model: "grok-4",
x_search: true
}
)
Summary
Types
Configuration for the xAI provider. Inherits the full Alloy.Provider.OpenAI
config surface plus :web_search and :x_search for Grok's native search
tools. :api_url defaults to "https://api.x.ai".
Types
@type config() :: Alloy.Provider.OpenAI.config()
Configuration for the xAI provider. Inherits the full Alloy.Provider.OpenAI
config surface plus :web_search and :x_search for Grok's native search
tools. :api_url defaults to "https://api.x.ai".