Xai.Client (xai v0.1.0)

Copy Markdown View Source

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 to XAI_API_KEY
  • :management_api_key - for Collections / management (falls back to XAI_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

t()

@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

channel(client)

@spec channel(t()) :: GRPC.Channel.t()

Get the raw gRPC channel (for advanced use or direct stub calls).

default_timeout(client)

Get the configured default timeout.

new(opts \\ [])

@spec new(keyword()) :: t()

Create a new client.