Skip to main content
Version: 1.0.x

xAI (Grok) LLM

The xAI (Grok) LLM provider enables your agent to use xAI's language models (like Grok-4) for text-based conversations and processing. It also supports vision input capabilities, allowing your agent to analyze and respond to images alongside text with the supported models.

Installation

Install the xAI-enabled VideoSDK Agents package:

pip install "videosdk-plugins-xai"

Importing

from videosdk.plugins.xai import XAILLM

Authentication

The xAI plugin requires an xAI API key.

Set XAI_API_KEY in your .env file.

Example Usage

from videosdk.plugins.xai import XAILLM
from videosdk.agents import Pipeline

llm = XAILLM(
model="grok-4-1-fast-non-reasoning",
temperature=0.7,
tool_choice="auto",
max_completion_tokens=1000,
)

pipeline = Pipeline(llm=llm)
note

When using a .env file for credentials, don't pass them as arguments to model instances. The SDK automatically reads environment variables, so omit api_key and other credential parameters from your code.

Configuration Options

Core

  • model — The Grok model to use (e.g. "grok-4-1-fast-non-reasoning", "grok-4", "grok-4-1-fast"). Default: "grok-4-1-fast-non-reasoning".
  • api_key — Your xAI API key. Falls back to the XAI_API_KEY environment variable.
  • base_url — Custom base URL for the xAI API. Default: "https://api.x.ai/v1".
  • temperature — Sampling temperature (0.0 – 2.0). Default: 0.7.
  • tool_choice — Tool selection mode: "auto", "required", "none", or a dict {"type": "function", "function": {"name": "my_tool"}} to force a specific tool. Default: "auto".
  • max_completion_tokens — Maximum tokens in the completion response (optional).

Tool calling

  • tools — List of FunctionTool instances or tool dicts to make available to the LLM at initialization (optional).

Advanced Example

from videosdk.plugins.xai import XAILLM
from videosdk.agents import Pipeline

llm = XAILLM(
model="grok-4-1-fast-non-reasoning",
temperature=0.7,
tool_choice="auto",
max_completion_tokens=2048,
)

pipeline = Pipeline(llm=llm)

Additional Resources

Got a Question? Ask us on discord