Skip to main content

llm-api-adapter-xai

Official xAI Responses API support for llm-api-adapter.

Installation

Install through the core package extra:

pip install "llm-api-adapter[xai]"

Direct installation is also supported when the core package is managed separately:

pip install llm-api-adapter-xai

Async methods need HTTPX:

pip install "llm-api-adapter[xai,async]"

Synchronous requests remains the default. To opt into the HTTPX synchronous transport, install "llm-api-adapter[xai,httpx]" and pass transport="httpx".

Quick start

import os

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter

adapter = UniversalLLMAPIAdapter(
    organization="xai",
    model="grok-4.6",
    api_key=os.environ["XAI_API_KEY"],
)

response = adapter.chat(
    messages=[UserMessage("Explain retrieval-augmented generation.")]
)
print(response.content)

Supported models and capabilities

The package deliberately exposes fixed model IDs, not moving aliases: grok-4.5 and grok-4.6.

Capability Supported models
Text chat, sync/async streaming, application function tools, JSON Schema/Pydantic output, image URLs or bytes, and PDF URLs or bytes Both models
reasoning_level grok-4.5: lowhigh; grok-4.6: lowxhigh

For grok-4.5 and grok-4.6, xAI cannot disable reasoning: a requested "none" is mapped to the documented minimum and produces a warning.

The JSON Schema subset is limited by xAI. The adapter rejects unsupported schemas before sending a request. See xAI's structured-output documentation for the supported schema vocabulary.

Conversations, files, and costs

previous_response is accepted for the shared API, but xAI continuation is intentionally not used: the adapter does not send previous_response_id. Keep and provide the complete messages history for each turn, including assistant tool calls and ToolMessage results.

The package does not expose or send xAI's store option. xAI documents that Responses are stored server-side by default, so configure data retention with xAI when that matters to your application. In particular, the library does not turn on Zero Data Retention (ZDR); enabling ZDR in the xAI Console blocks new Files API uploads and file_id attachments.

PDF URLs are passed to xAI unchanged. For PDF bytes, the adapter uploads a provider-owned file with a 24-hour expiry; it never deletes or changes a URL or file identifier supplied by your application. No OCR or local text extraction is performed.

Attaching a PDF activates xAI's attachment_search tool. That makes the request agentic and adds tool-invocation charges to normal token charges. Storage for an uploaded file is also billed by xAI until it expires. Treat ChatResponse.cost_total as the exact request cost only when xAI returns it; consult xAI billing for storage and any charges not included in that response.

See the official xAI documentation for Responses storage, files and expiry, and file-search pricing.

See the main llm-api-adapter README for the shared API contract and examples.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_api_adapter_xai-0.1.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_api_adapter_xai-0.1.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_api_adapter_xai-0.1.0.tar.gz.

File metadata

  • Download URL: llm_api_adapter_xai-0.1.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llm_api_adapter_xai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3a5c245aeb5337b3b6be5fae1d8c54b333aded3332987fdf13064fec861697f3
MD5 3538ad9d59feaf1d6b6af535d3bea442
BLAKE2b-256 6658727d55d1a7afe6160339e5fce8421cbb491656bf055211bbfc77bd397a57

See more details on using hashes here.

File details

Details for the file llm_api_adapter_xai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_api_adapter_xai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 169fe108c2eca708b4b119adfd46dd3af608188c091a24b839e66a82d8108105
MD5 1463adb8bf49c1c422109333c894ae8a
BLAKE2b-256 7ea50fa3f64eff9f42c46f3a543de497321c73a5c29ab17909a4b3ad5b2a49d9

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page