Class XAIGrokClient

All Implemented Interfaces:
com.tnsai.llm.LLMClient

public class XAIGrokClient extends AbstractOpenAICompatibleClient
xAI Grok LLM client.

xAI's API is OpenAI-compatible — the same chat-completions wire format as GroqClient / OpenRouterClient / NvidiaNIMClient. This client targets the cloud endpoint at https://api.x.ai/v1 by default; a baseUrl parameter or the XAI_BASE_URL env var swaps it for a mirror or proxy.

Supported models (at time of writing):

  • grok-3 — flagship Grok 3 (general chat + tool use)
  • grok-3-mini — smaller / cheaper Grok 3
  • grok-2-vision — multimodal Grok 2 (image input)
  • grok-beta — pre-release tier; availability gated by xAI

The catalog evolves quickly; check the live list at docs.x.ai/api.

Configuration via environment variables:

  • XAI_API_KEY — Required for the cloud endpoint.
  • XAI_BASE_URL — Optional override, defaults to https://api.x.ai/v1.
See Also:
  • Constructor Details

    • XAIGrokClient

      public XAIGrokClient(String model)
    • XAIGrokClient

      public XAIGrokClient(String model, float temperature)
    • XAIGrokClient

      public XAIGrokClient(String model, float temperature, Integer maxTokens)
    • XAIGrokClient

      public XAIGrokClient(String model, float temperature, Float topP, Integer maxTokens)
    • XAIGrokClient

      public XAIGrokClient(String baseUrl, String model, float temperature, Integer maxTokens, String apiKey)
    • XAIGrokClient

      public XAIGrokClient(String baseUrl, String model, float temperature, Float topP, Integer maxTokens, String apiKey)