skillfed

xai-sdk

The official Python SDK for the xAI API

xai-sdk v1.18.0 4.8M downloads/30d#2,232 on PyPI542
Permissive license Apache-2.0 Active released

What it is and what it does

The xAI SDK is the official Python library for accessing xAI's generative AI APIs. It wraps gRPC and REST endpoints with both synchronous and asynchronous client interfaces, letting you build chat applications, generate images and videos, perform image understanding, and call functions on xAI models like Grok. The SDK handles authentication via environment variables, manages conversation history through a simple append-and-sample pattern, and supports streaming for real-time output.

The package is built on mature dependencies (aiohttp, grpcio, pydantic, protobuf, opentelemetry-sdk) and targets Python 3.10+. It's actively maintained, with comprehensive documentation and example code for common tasks. Whether you're building a chatbot, processing images, generating video, or integrating structured tool calling, the SDK abstracts away the underlying API details and provides a Pythonic interface.

Use it for:

  • Build interactive chatbots or multi-turn conversational applications using the chat API with synchronous or asynchronous clients.
  • Generate videos from text prompts, edit existing videos, or extend video sequences using the video generation models.
  • Analyze and understand images by combining text and image inputs in a single chat message.
  • Implement function calling workflows where the model intelligently invokes defined tools based on user input.
  • Stream real-time model responses for responsive UI applications that display output as it's generated.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Official Python SDK for xAI's APIs, providing synchronous and asynchronous clients to interact with text generation, image understanding, video generation, and structured output models.

Yes. The SDK is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively. It's the official client for xAI's APIs and provides both sync and async support, making it the natural choice if you're building applications against xAI's models. Requires Python 3.10+ and a valid API key.

Install

xai-sdk on PyPI

pip

pip install xai-sdk

uv

uv add xai-sdk

poetry

poetry add xai-sdk

Installing xai-sdk

Before you install

Low friction installation with a pure-wheel distribution. Active maintenance with a release within the last day and 542 repository stars. Requires Python 3.10 or higher and depends on 8 standard runtime libraries (aiohttp, grpcio, pydantic, protobuf, and others).

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for both open-source and proprietary projects.

Quickstart

pip install xai-sdk

from xai_sdk import Client
from xai_sdk.chat import system, user

client = Client()  # Uses XAI_API_KEY environment variable
chat = client.chat.create(model="grok-3", messages=[system("You are helpful.")])
chat.append(user("Hello"))
response = chat.sample()
print(response.content)

Requires Python 3.10 or higher and a valid XAI_API_KEY environment variable or explicit API key parameter.

Verify before relying

  • Rate limits, quota policies, or cost implications for API calls through the SDK.
  • Supported models beyond grok-3, grok-2-vision, and grok-imagine-video mentioned in examples.
  • Retry logic, timeout defaults, and error handling behavior for network failures.
  • Whether streaming responses work with all model types or only specific ones.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 8 — aiohttp, googleapis-common-protos, grpcio, opentelemetry-sdk, packaging, protobuf, pydantic, requests
Maintenance actively maintained — 1 days since the last release
Last repo commit
First released
Downloads 4,781,132/month — #2,232 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: xai_sdk-1.18.0-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Internet :: WWW/HTTPTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

xai api client pythongrok sdk pythontext generation api sdkasync api clientvideo generation sdkimage understanding apigrpc python client
grpc-clientasync-supportgenerative-ai

More Libraries packages