Tools & Products

SpaceXAI Unveils Official TypeScript SDK on npm: Native Typed Client for Grok and Real-Time Systems

An official experimental TypeScript SDK for the SpaceXAI and xAI API platform quietly landed on npm under @xai-official/sdk, providing end-to-end typed client libraries for Grok models, tool dispatching, and high-frequency telemetry streaming.

By FreakVinci · 2026-10-03 · 12 min read
SpaceXAI and xAI software telemetry interface showcasing code editor and neural model dispatch logs
SpaceXAI and xAI software telemetry interface showcasing code editor and neural model dispatch logs

An official experimental client library for the SpaceXAI / xAI developer platform appeared on the npm registry under the package name @xai-official/sdk.

The SDK delivers native TypeScript definitions for the xAI API, eliminating the need for developers to rely on third-party community wrappers or configure generic OpenAI client shims with custom base URLs.


Installation and Runtime Support

The SDK targets modern JavaScript runtimes without native binary compilation dependencies:

# Install via npm
npm install @xai-official/sdk

# Install via Bun or pnpm
bun add @xai-official/sdk
pnpm add @xai-official/sdk

The package runs natively in Node.js 18+, Bun, Deno, Next.js Edge Runtime, and Cloudflare Workers.


Basic Usage: Chat Completion with Streaming

Connecting to the Grok API with typed streaming takes only a few lines of code:

import { SpaceXAIClient } from '@xai-official/sdk';

const client = new SpaceXAIClient({
  apiKey: process.env.XAI_API_KEY,
});

async function main() {
  const stream = await client.chat.createStream({
    model: 'grok-3-latest',
    messages: [
      { role: 'system', content: 'You are an aerospace propulsion dynamics specialist.' },
      { role: 'user', content: 'Calculate specific impulse (Isp) variations between sea level and vacuum for methane-oxygen staged combustion.' }
    ],
    temperature: 0.2,
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
}

main().catch(console.error);

Structured Output and Tool Calling via Zod

The SDK includes first-class integration with Zod for deterministic schema generation:

import { SpaceXAIClient, defineTool } from '@xai-official/sdk';
import { z } from 'zod';

const client = new SpaceXAIClient({ apiKey: process.env.XAI_API_KEY });

const orbitalTelemetryTool = defineTool({
  name: 'getOrbitalTelemetry',
  description: 'Retrieve real-time velocity and apogee altitude for active orbital stages',
  schema: z.object({
    stageId: z.string().describe('The identifier of the rocket stage'),
    units: z.enum(['metric', 'imperial']).default('metric'),
  }),
  execute: async ({ stageId, units }) => {
    return { stageId, velocityKps: 7.82, apogeeKm: 420.5, status: 'nominal' };
  }
});

const response = await client.agents.run({
  model: 'grok-3-latest',
  tools: [orbitalTelemetryTool],
  prompt: 'Check status of Stage 2 on mission Starlink 12-4.'
});

console.log(response.output);

SDK Feature Overview

Capability Supported in @xai-official/sdk Implementation Detail
Grok-3 & Grok-2 Support Yes Full parameter typing (temperature, top_p, logprobs)
Multimodal Vision Yes Accepts URLs and raw Base64 image buffers
Function / Tool Calling Yes Parallel tool execution with automated Zod validation
Edge Compatibility Yes 100% Web standard APIs (Fetch, ReadableStream)
Automatic Retries Yes Exponential backoff with jitter on 429 and 503 errors
Real-Time Telemetry Hooks Yes Binary WebSocket streams for high-speed sensor feeds

Summary

The launch of @xai-official/sdk signals xAI's push to cement Grok's position within enterprise software and developer toolchains, offering modern typed ergonomics and zero-overhead performance.