Skip to content
AI Primer
release

xAI releases an experimental TypeScript SDK for Grok

xAI's experimental TypeScript SDK supports Grok text, voice, image, and video models, plus server-side tools. Code execution runs in isolated, stateless Python sandboxes without network or filesystem access.

4 min read
xAI releases an experimental TypeScript SDK for Grok
xAI releases an experimental TypeScript SDK for Grok

TL;DR

  • xAI's experimental @xai-official/sdk covers Grok text, voice, images and video, plus server-side tools, as announced in the launch post.
  • Code execution runs in isolated, request-scoped Python sandboxes with no network, filesystem access or persistence between requests, according to the author's clarification.
  • X search uses Grok API credits; a billing clarification says it leaves X API balances untouched.

The changelog records a same-day breaking rename from xAI to SpaceXAI. The README blocks browser and Worker use by default and makes response storage opt-in.

TypeScript client

The client is typed, ESM-only and has no runtime dependencies. It requires Node.js 22.13 or later and automatically reads XAI_API_KEY, according to the README.

API coverage in the initial release includes:

  • Responses: streaming, structured output, image input and multi-turn conversations.
  • Images and video: generation and editing, plus video extension and local uploads.
  • Voice: text-to-speech, transcription and custom voices.
  • Supporting APIs: Files, Batch, tokenization, model catalogs and account lookup.

Server-side tools

Grok can use real-time X search, web search, code execution and remote MCP through the SDK, as described in the announcement. Built-in helpers live in @xai-official/sdk/tools, with the changelog listing seven capabilities:

  • Web search
  • X search
  • Code execution
  • Collections search
  • Remote MCP servers
  • Image generation
  • Tool search

Application-defined function tools execute in the application's own code, according to the README's examples.

Stateless Python sandboxes

NumPy, Pandas, Matplotlib and SciPy are available in the sandbox, according to the code execution docs. The page notes execution-time and memory constraints without publishing numerical limits.

Streaming and retries

Even non-streaming calls stream internally, the SDK's most consequential implementation wrinkle in the README.

  • on("text") delivers answer chunks; done() resolves to the completed response and rejects on failure or premature closure.
  • client_tool_call signals application-side functions or shell commands; server_tool_call signals tools run by xAI.
  • Function-call events fire once their arguments are complete. The application still has to execute the function.
  • A midstream failure ends the response without an automatic retry, including calls made without stream: true.
  • retryBeforeOutput, added in 0.2.1, enables retries before any model output, bounded by maxRetries.

Conversation storage

Responses are not stored by default. The client exposes three state-management paths in the conversation examples:

  • Manual history: toInput() carries model output, including encrypted reasoning content, into the next request.
  • Stored history: store: true enables continuation through previous_response_id.
  • Compaction: responses.compact() replaces conversation history with a single encrypted item. The input must still fit the model's context window when compaction runs.

Compaction usage includes dropped_message_count, the number of messages replaced.

API credits

The SDK runs on the Grok API with separate credits from the X API. The developer console provides API-key management and centralized usage, credit and invoice tracking.

Same-day breaking changes

Three public releases landed on October 2, according to the npm package history and changelog:

  • 0.1.0: initial public release.
  • 0.2.0: breaking rename of the client class from xAI to SpaceXAI, alongside renamed response, stream and binary-response types.
  • 0.2.1: toJson(schema) gained typed Standard Schema validation; a "json" stream event and parsePartialJson() added incremental structured-output parsing.
  • 0.2.1: 429 responses without Retry-After now back off starting at one second rather than 250 milliseconds, capped at 30 seconds.

The repository warns that interfaces may change before 1.0. The release author is soliciting early feedback, replying in the thread and thanking commenters.

Further reading

Discussion across the web

Where this story is being discussed, in original context.

On X· 1 thread
Same-day breaking changes3 posts
Share on X