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":ssl- whether to use TLS for the gRPC connection, defaulttrue:timeout- default 30 minutes:adapter- theGRPC.Stubtransport adapter, defaultGRPC.Client.Adapters.Gun. Both:gunand:mintare optional dependencies of this package — add whichever one you actually use to your ownmix.exs. Passadapter: GRPC.Client.Adapters.Mintto use Mint instead of Gun (no:cowlibin its dependency tree). Callers who only useXai.Realtime(WebSocket, viawebsockex) never callXai.Client.new/1at all and need neither:gunnor:mint.
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.