LLMDB.Sources.XAI (LLM DB v2026.3.0)

Copy Markdown View Source

Remote source for xAI (Grok) models (https://api.x.ai/v1/models).

  • pull/1 fetches data from xAI API and caches locally
  • load/1 reads from cached file (no network call)

Options

  • :url - API endpoint (default: "https://api.x.ai/v1/models")
  • :api_key - xAI API key (required, or set XAI_API_KEY env var)
  • :region - Optional regional endpoint (:us_east_1 or :eu_west_1)
  • :req_opts - Additional Req options for testing

Configuration

Cache directory can be configured in application config:

config :llm_db,
  xai_cache_dir: "priv/llm_db/remote"

Default: "priv/llm_db/remote"

Regional Endpoints

You can use regional endpoints for data residency:

  • :us_east_1 - https://us-east-1.api.x.ai/v1/models
  • :eu_west_1 - https://eu-west-1.api.x.ai/v1/models

Usage

# Pull remote data and cache (requires API key)
mix llm_db.pull --source xai

# Pull with regional endpoint
mix llm_db.pull --source xai --region eu_west_1

# Load from cache
{:ok, data} = XAI.load(%{})

Summary

Functions

Transforms xAI API response to canonical Zoi format.

Functions

transform(content)

Transforms xAI API response to canonical Zoi format.

xAI uses OpenAI-compatible format.

Input Format (xAI)

{
  "object": "list",
  "data": [
    {
      "id": "grok-4-fast-reasoning",
      "object": "model",
      "created": 1234567890,
      "owned_by": "xai"
    }
  ]
}

Output Format (Canonical Zoi)

%{
  "xai" => %{
    id: :xai,
    name: "xAI",
    models: [
      %{
        id: "grok-4-fast-reasoning",
        provider: :xai,
        extra: %{
          created: 1234567890,
          owned_by: "xai"
        }
      }
    ]
  }
}