NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #1849 most downloaded on PyPI
The official Python SDK for the xAI API
Last release 10 days ago
24 Sep 2026
Ships fairly regularly
a new release about every 3 weeks
Nearly every release is documented
notes for 29 of 29 stable releases
Nothing withdrawn
no release was ever pulled
1 years old
32 releases · first in 2025
One column per month.
Update changelog by @Omar-V2 in #199
Full Changelog: v1.19.0...v1.20.0
Update README examples to use grok-4.6 by @gyang-xai in #191
tool_call_id when replaying tool outputs via chat.append(response) by @Omar-V2 in #192reference_audios, generate_audio, and 1080p to video generation by @Omar-V2 in #194Full Changelog: v1.18.0...v1.19.0
XaiSdk/{version} via grpc.primary_user_agent (same string already used for image URL fetches; exposed as xai_sdk.client.USER_AGENT)reference_audios and generate_audio parameters to video generation. reference_audios (on client.video.generate / start / prepare) is a list of audio sources for reference-to-video — each entry is a TypedDict such as {"voice_id": "ara"}; only supported for grok-imagine-video-1.5. generate_audio (on generate / start / prepare) controls whether the generated video includes audio (true) or is silent (false); when omitted the server defaults to true."1080p" as an accepted video resolution value (maps to VIDEO_RESOLUTION_1080P). Only supported on models that advertise 1080p (e.g. grok-imagine-video-1.5 for image-to-video).quality parameter ("low", "medium") to image generation (client.image.sample, sample_batch, and batch prepare), mapping to the GenerateImageRequest.quality field. When omitted, the default is "medium". Only supported for grok-imagine-image-2.0.grok-imagine-image-2.0 to the ImageGenerationModel known-model type literalxai_sdk.tools.image_generation helper for the server-side image_generation tool, enabling image generation and editing in agentic requests. Accepts an optional action parameter ("auto", "generate", or "edit") to control which image capabilities are exposed to the modelResponse.image_outputs for retrieving images generated by the server-side image_generation tool as decoded bytes (output.image), along with mime_type, data_url, image_uuid, and the originating tool_callgrok-imagine-video-1.5 and removed grok-imagine-video-1.5-preview (now an alias of grok-imagine-video-1.5) from VideoGenerationModel, and removed grok-imagine-image-pro (an alias of grok-imagine-image-quality) from ImageGenerationModel. These literals are type hints for editor autocomplete only — alias strings continue to work when passed to the API.chat.append(response) now sets tool_call_id on replayed tool-role messages (recovered from the tool call echoed on the output), so servers can pair replayed tool turns with their originating calls. This fixes stateless multi-turn follow-ups to server-side tools whose results are re-hydrated by ID — e.g. editing a previously generated image in-memory without previous_response_id.Accept xhigh reasoning_effort and add grok-4.6 to ChatModel by @gyang-xai in #189
Full Changelog: v1.17.1...v1.18.0
xhigh Reasoning Effort: Added "xhigh" as an accepted reasoning_effort value (maps to EFFORT_XHIGH; supported by models such as grok-4.6)grok-4.6 to the ChatModel known-model type literalfeat: add service_tier support for priority processing by @double-di in #163
Full Changelog: v1.16.0...v1.17.0
service_tier parameter to chat.create() for requesting priority processing ("default" or "priority") at a higher token price. Responses expose a service_tier property indicating which tier was actually usedAdd Imagine file storage & file-ID inputs to image/video generation by @Omar-V2 in #160
Full Changelog: v1.15.0...v1.16.0
storage_options parameter to persist generated assets to the Files API. It takes a dict with a required filename and optional expires_after (an int in seconds or a datetime.timedelta) and public_url (True to create a public URL with default expiry, or {"expires_after": <seconds>} for an independent URL expiry). Image and video responses expose new file_output, storage_error, public_url, and public_url_error properties.file_id references as inputs alongside URLs/base64 — image_file_id / image_file_ids for image.sample() / image.sample_batch(), and image_file_id / video_file_id / reference_image_file_ids for video.generate() / video.extend() (and the batch prepare helpers). URL and file-ID lists may be mixed in the same multi-image request (file IDs are sent first).client.files.create_public_url() and client.files.revoke_public_url() (sync and async) to create and revoke publicly shareable, unauthenticated URLs for stored files. create_public_url() accepts an optional expires_after (an int in seconds or a datetime.timedelta).client.files.list() (sync and async) now accepts an optional filter parameter to narrow results server-side by fields such as content_type, size_bytes, created_at, upload_status, and public_url (e.g. filter='public_url != null').grok-imagine-image-quality to the ImageGenerationModel known-model type literal and grok-imagine-video-1.5-preview to the VideoGenerationModel known-model type literalAdd grok-build-0.1 to ChatModel by @shawnthapa in #155
Full Changelog: v1.14.0...v1.15.0
chat.compact_context() (sync and async) to compact a conversation into an opaque encrypted_content representation that can be reused in follow-up requests without sending the full message history. Chat objects also expose compact(), which runs compaction on the current conversation and appends the result. The returned CompactContextResponse includes encrypted_content, dropped_message_count, and usage.grok-build-0.1 to the ChatModel known-model type literalAdd enable_image_search to web_search and SERVER_SIDE_TOOL_IMAGE_SEARCH enum by @ushiromiya-lion in #152
Full Changelog: v1.13.0...v1.14.0
enable_image_search parameter to web_search() to return image results that can be embedded in responsesAdd none and medium reasoning effort levels by @shawnthapa in #139
Full Changelog: v1.12.1...v1.12.2
"none" and "medium" as accepted reasoning_effort values (maps to EFFORT_NONE and EFFORT_MEDIUM)Update the CHANGELOG with missing entries by @Omar-V2 in #135
Full Changelog: v1.12.0...v1.12.1
grok-4.3 and grok-4.3-latest to the ChatModel known-model type literaldocs: add video generation and extension documentation to README by @double-di in https://github.com/xai-org/xai-sdk-python/pull/127
expires_after to file uploads, drop team_id from File by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/131cost_usd tracking, model migration, example fixes by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/132cost_usd property to image and video responses by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/133Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.11.0...v1.12.0
chat.sample() / chat.stream(), image.sample() / image.sample_batch(), and video.generate() / video.extend() now expose a cost_usd property that returns the per-request cost in USD (or None when the server does not report cost)client.files.upload() (sync and async) now accepts an optional expires_after parameter to set a TTL on uploaded files. Accepts either an int (seconds) or a datetime.timedelta. After the duration elapses, the file is automatically deleted.description parameter to collections.create() and collections.update() for human-friendly collection descriptionscollections.generate_description() method that asks the API to summarize a collection based on its document contentsfield_definitions parameter to collections.update() for adding or deleting field definitions on existing collections. Each entry is either an add ({"field_definition": {...}, "operation": "add"}) or a delete ({"key": "...", "operation": "delete"}); typed via FieldDefinitionAdd / FieldDefinitionDelete (re-exported as the union FieldDefinitionUpdate)BytesConfiguration as a third chunking strategy (alongside chars_configuration and tokens_configuration) on ChunkConfigurationfilter parameter to collections.list_documents() for filtering on file metadata and document fields (e.g., 'status:DOCUMENT_STATUS_PROCESSED', 'fields.isbn:"978-1-234567-89-0"')wait_for_indexing polling now treats the new DOCUMENT_STATUS_CHUNKED, DOCUMENT_STATUS_EMBEDDING, and DOCUMENT_STATUS_WRITING statuses as in-progress instead of unknowncollections.reindex_documentcollection.id and file.id span attributes to delete_collection, add_existing_document, remove_document, reindex_document, and generate_descriptioncost_in_usd_ticks to telemetry span attributes for chat, image, and video responseschunk_configuration validation is now stricter. When chunk_configuration is provided, it must specify exactly one of chars_configuration, tokens_configuration, or bytes_configuration. Previously, calls that omitted all three (e.g., to update only strip_whitespace) silently succeeded; they now raise ValueError. Callers updating only top-level chunk flags must now also include their existing chunking strategy.team_id field from File responses returned by the Files API (upload, list, get). The same value is available via client.auth.get_api_key_info().team_id, which is the canonical source.Support inline file attachments by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/122
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.10.0...v1.11.0
chat.file() now supports inline file data via a new data parameter (with optional filename and mime_type), in addition to the existing file_id modechat.file() now supports public URL file references via a new url parameter (with optional filename and mime_type)Add video extension API and reference_image_urls support by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/120
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.9.1...v1.10.0
extend() and extend_start() methods to sync and async video clients for extending existing videos with a text promptreference_image_urls parameter to video.generate(), video.start(), and video.prepare() for reference-image-based video generation (R2V)Update grok-4.20 and multi-agent model variants in ChatModel by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/117
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.9.0...v1.9.1
grok-4.20 model variants from beta to GA naming convention (e.g., grok-4.20, grok-4.20-0309, grok-4.20-multi-agent)feat: add image/video batch support and input_file_id by @double-di in https://github.com/xai-org/xai-sdk-python/pull/112
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.8.2...v1.9.0
image.prepare() and video.prepare() methods to create batch requests for image and video generationinput_file_id parameter to batch.create() for creating batches from uploaded JSONL filesimage_response and video_response properties on BatchResult for typed access to image and video batch resultsUnion[ImageGenerationModel, str] / Union[VideoGenerationModel, str] for model parameters, enabling IDE autocompleteValueErrorPollTimer now accepts an optional context parameter for more descriptive TimeoutError messagesHandle video generation failure case by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/110
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.8.1...v1.8.2
VideoGenerationError (with code and message attributes) when the API reports a generation failure, instead of returning an incomplete responseUpdate grok-4.20 beta and multi-agent model variants in ChatModel by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/107
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.8.0...v1.8.1
grok-4.20 model variants from experimental-beta to beta naming convention (e.g., grok-4.20-beta, grok-4.20-beta-0309, grok-4.20-multi-agent-beta-0309)Add grok-imagine-image-pro to ImageGenerationModel by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/103
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.7.0...v1.8.0
agent_count parameter to chat.create() for configuring the number of agents (4 or 16) when using multi-agent modelsgrok-4.20-experimental-beta and grok-4.20-multi-agent-experimental-beta model variants to ChatModelgrok-imagine-image-pro to ImageGenerationModelgrok-2-image model variants from ImageGenerationModelDeprecate BaseImageResponse.prompt after up_sampled_prompt proto removal by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/96
BaseImageResponse.prompt after up_sampled_prompt proto removal by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/96image_urls parameter by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/99Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.6.1...v1.7.0
image_urls parameter to image.sample() and image.sample_batch() for multi-reference image editing with mutual exclusivity enforcement against image_url"2k" option to ImageResolution for higher resolution image generationPollTimer poll interval from 100ms to 1s and introduced DEFAULT_VIDEO_POLL_INTERVAL and DEFAULT_VIDEO_TIMEOUT constants for video clientsBaseImageResponse.prompt now returns an empty string and emits a DeprecationWarning after the up_sampled_prompt field was removed from the GeneratedImage protoUpdate changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/90
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.6.0...v1.6.1
client.video sub-client (sync and async) for video generation, supporting text-to-video and image-to-video with configurable aspect_ratio, resolution, and durationimage_url parameter to image.sample() and image.sample_batch() for using a reference image as a starting point for generationaspect_ratio parameter for controlling image aspect ratios (e.g., "1:1", "16:9", "9:16")resolution parameter for controlling image resolution ("1k")ImageAspectRatio, ImageFormat, ImageResolution, VideoAspectRatio, VideoResolution, and VideoGenerationModel type aliasesgrok-imagine-image to ImageGenerationModel and grok-imagine-video as VideoGenerationModelAdd user-location support for web-search tool by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/80
tool_call_id field by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/81developer role by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/86gen_ai spec's changes by @aaditjuneja in https://github.com/xai-org/xai-sdk-python/pull/83Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.5.0...v1.6.0
client.batch sub-client for interacting with the Batch API:
batch_request_id field in chat.create methoddeveloper role support for chat messages with developer() utility functiontool_call_id field and argument to tool_result utility function for explicit tool call identificationweb_search() server-side tool with new location-related argumentsgen_ai semantic conventionsxai under gen_ai.provider.name field instead of gen_ai.systemserver.address attribute set to api.x.aiupload, delete)create, update, delete, upload_document, add_existing_document, remove_document, update_document)Add end_index, rename document search tools, and add verbose_streaming include option by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull
end_index, rename document search tools, and add verbose_streaming include option by @shawnthapa in https://github.com/xai-org/xai-sdk-python/pull/71Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.4.1...v1.5.0
field_definitions parameter to collections.create() enabling custom document metadata schemas with validation constraints (required, unique, inject_into_chunk)metric_space parameter to collections.create() supporting HNSW distance metrics (cosine, euclidean, inner_product)filter parameter to collections.list() with support for filtering by collection_name, created_at, and documents_countwait_for_indexing parameter to document upload with customizable poll_interval and timeoutinstructions and retrieval_mode parameters to collections.search()TypedDict interfaces as ergonomic alternatives to protobuf objectsend_index field for InlineCitationverbose_streaming to include options for streaming responsesupload_document now streams bytes via the Files UploadFile endpoint, then attaches the resulting file to the collectioncontent_type parameter was removed from the public collections.upload_document functionUpdate changelog following the v.1.4.0 release by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/63
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.4.0...v1.4.1
batch_upload method to both sync and async file clients for concurrent uploads of multiple files with progress trackingmax_turns parameter to chat.create for configuring the maximum number of agentic turns when using server-side toolsinclude field to chat requests allowing users to specify optional outputs to be returned (e.g., tool output, inline citations)InlineCitation support for agentic search outputsModel literals for type-safe model specification and editor autocomplete supporttypes folder for better organizationAdd xai-sdk-version to the request metadata by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/41
ToolCallType in ToolCall by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/50parse method by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/55response_format directly in chat.create by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/57Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.3.1...v1.4.0
client.files sub-client for uploading and managing filesBaseModel directly to response_format parameter in chat.create for type-safe structured outputsclose() methods to Client and AsyncClient for proper gRPC channel cleanupSERVER_SIDE_TOOL_MCP and SERVER_SIDE_TOOL_COLLECTIONS_SEARCH to ServerSideTool usage enumToolCallType support in ToolCall for distinguishing between client-side and server-side toolsget_tool_call_type() for retrieving tool call typesinsecure parameter (useful for local development)xai-sdk-version metadata header to all gRPC requests for better debugging and analyticsXAI_SDK_DISABLE_SENSITIVE_TELEMETRY_ATTRIBUTES environment variableChoiceChunk class to CompletionOutputChunkparse method for chat responsesUnaryStreamAioInterceptorSupport multiple outputs in chunk and response of chat service by @mark-xai in https://github.com/xai-org/xai-sdk-python/pull/39
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.3.0...v1.3.1
response.tool_calls now correctly returns ALL tool calls from all assistant outputs in the response, not just those from a single output indexresponse.content properly aggregates and returns the final assistant response contentUpdate changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/31
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.2.0...v1.3.0
web_search(): Enables web search with configurable domain filtering (exclude/allow lists) and image understanding capabilitiesx_search(): Enables X (Twitter) search with date range filtering, handle-based filtering (include/exclude), and both image and video understandingcode_execution(): Enables server-side code execution for computational tasksxai_sdk.tools module for easily creating server-side tool configurationsServerSideTool enum in usage proto for tracking server-side tool usage (WEB_SEARCH, X_SEARCH, CODE_EXECUTION, VIEW_IMAGE, VIEW_X_VIDEO)server_side_tools_used field to SamplingUsage for detailed usage tracking of which server-side tools were invokedGetChatCompletionResponse.choices → GetChatCompletionResponse.outputsGetChatCompletionChunk.choices → GetChatCompletionChunk.outputsChoice message type → CompletionOutputChoiceChunk message type → CompletionOutputChunkUpdate changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/31
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.2.0...v1.3.0a0
Update changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/26
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.1.0...v1.2.0
collections sub-client to Client and AsyncClient which can be used to interact with the collections API.Client and AsyncClient objects now accept an optional management_api_key parameter which can be used to authenticate requests to the management API (e.g. CRUD operations on collections). Alternatively, the XAI_MANAGEMENT_API_KEY environment variable can be used to set this value without having to pass it as a parameter.chat.create method:
store_messages whether to persist messages on xAI servers such that they can be referenced and retrieved later.previous_response_id allows you to specify the ID of a previously stored response to use as the starting point for the new chat.chat object:
get_stored_completion allows you to retrieve a previously stored response by its ID.delete_stored_completion allows you to delete a previously stored response by its ID.documents sub-client from Client and AsyncClient. In order to search for documents within collections, use the client.collections.search method instead.Update changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/19
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.0.1...v1.1.0
telemetry module (xai_sdk.telemetry) which can be used to setup trace creation and exporting of traces to an otel backend or to the consoledocuments sub-client to Client and AsyncClient which can be used to interact with the documents API.search method on the documents sub-client which can be used to perform semantic search for documents that are stored in collections.Update changelog by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/15
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.0.0...v1.0.1
from_date and to_date parameters to have no effect when using them via SearchParameters for the live search featureAdd support for new X source params for live search by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/10
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.0.0rc2...v1.0.0
x_source (from xai_sdk.search import x_source) for use with the live search API feature:
included_x_handles allows you to limit posts used to those only authored by particular handlesexcluded_x_handles allows you to exclude posts authored by particular handlespost_favorite_count allows you to set a threshold for the minimum number of favorites a post must have to be consideredpost_view_count allows you to set a threshold for the minimum number of views a post must have to be consideredUpdate protos with new reasoning_content field added to Message proto by @Omar-V2 in https://github.com/xai-org/xai-sdk-python/pull/6
Full Changelog: https://github.com/xai-org/xai-sdk-python/compare/v1.0.0rc1...v1.0.0rc2
Update SECURITY.md by @avixai in https://github.com/xai-org/xai-sdk-python/pull/1
Full Changelog: https://github.com/xai-org/xai-sdk-python/commits/v1.0.0rc1
Your coding agent can read these notes before it upgrades. Set up the MCP server →