xai-sdk
The official Python SDK for the xAI API
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or higher and a valid XAI_API_KEY environment variable or explicit API key parameter.
- Low friction installation with a pure-wheel distribution.
- Active maintenance with a release within the last day and 542 repository stars.
License · maintenance · safety
Apache-2.0 (permissive) — Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for both open-source and proprietary projects.
last release 2026-08-13 (1 days) · last repo commit 2026-08-14 · 542 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 4,781,132 downloads/mo, #2,232 on PyPI
Alternatives
Verify before relying
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)- 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.
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 on it.
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
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).
Requires Python 3.10 or higher and a valid XAI_API_KEY environment variable or explicit API key parameter.
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)
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 packagesaiohttpgoogleapis-common-protosgrpcioopentelemetry-sdkpackagingprotobufpydanticrequests |
| 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 |
| Classifiers | 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 |
Evidence: xai_sdk-1.18.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “xai api client python”
- xai-sdkOfficial Python SDK for xAI's APIs, providing synchronous and…
- langchain-xaiConnects xAI's language models to LangChain applications through…
- livekit-plugins-xaiIntegrates xAI's Grok LLM with LiveKit's Agent Framework to enable…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also reka-api · livekit-plugins-xai · mistralai · aleph-alpha-client · gigachat · imagekitio · langchain-xai · zai-sdk · atproto · meilisearch-python-sdk