The main client for interacting with xAI's gRPC APIs.
Closely modeled after xai_sdk.Client in the official Python SDK.
Example
client = Xai.Client.new(api_key: System.get_env("XAI_API_KEY"))
chat = Xai.Chat.create(client, model: "grok-4.5")
chat = Xai.Chat.append(chat, Xai.Chat.user("Hello"))
{:ok, response} = Xai.Chat.sample(chat)For long-running operations (video, deferred), the client manages the channel.
Options
:api_key- falls back toXAI_API_KEY:management_api_key- for Collections / management (falls back toXAI_MANAGEMENT_API_KEY):endpoint- default "api.x.ai:443":timeout- default 30 minutes
Summary
Functions
Get the raw gRPC channel (for advanced use or direct stub calls).
Get the configured default timeout.
Create a new client.
Types
@type t() :: %Xai.Client{ api_key: String.t() | nil, channel: GRPC.Channel.t(), endpoint: String.t(), management_api_key: String.t() | nil, timeout: pos_integer() }
Functions
@spec channel(t()) :: GRPC.Channel.t()
Get the raw gRPC channel (for advanced use or direct stub calls).
Get the configured default timeout.
Create a new client.