#### SDKs

# TypeScript SDK

Use Grok from TypeScript with `@grok/sdk`, the official typed ESM client built on the SpaceXSI REST API. The SDK has no runtime dependencies and covers the [Responses API and streaming](/developers/sdk/typescript/responses), [structured output](/developers/sdk/typescript/structured-outputs), [tools](/developers/sdk/typescript/tools), [image and video generation](/developers/sdk/typescript/images-and-video), [files and batch processing](/developers/sdk/typescript/files-and-batch), [text to speech and transcription](/developers/sdk/typescript/voice), and [tokenization, model, and account lookup](/developers/sdk/typescript/models-and-account).

> [!WARNING]
>
> **Experimental.** The TypeScript SDK is in early development (pre-1.0), and its interfaces may change between releases. Pin an exact version in `package.json` and check the [changelog](https://github.com/xai-org/xai-sdk-ts/blob/main/CHANGELOG.md) when upgrading. Report bugs or share feedback in [GitHub issues](https://github.com/xai-org/xai-sdk-ts/issues).

## Requirements

Before installing the SDK, verify your environment meets these requirements:

* Node.js 22.13 or later
* A [SpaceXSI API key](https://console.x.ai/team/default/api-keys?utm_source=docs\&utm_medium=referral\&utm_campaign=developers-sdk-typescript\&utm_content=api-keys)
* An ESM project (`"type": "module"` in `package.json` or `.mts`/`.mjs` entrypoints)

## Installation

Install `@grok/sdk` with your package manager:

```bash
npm install @grok/sdk
```

```bash
pnpm add @grok/sdk
```

```bash
yarn add @grok/sdk
```

```bash
bun add @grok/sdk
```

Every release is also published identically as `@xai-official/sdk` with the same build and version. If you install `@xai-official/sdk`, import from `@xai-official/sdk` and `@xai-official/sdk/tools` instead.

## Quickstart

Set your API key in the environment. `Grok` reads `XAI_API_KEY` or `GROK_API_KEY` automatically (`XAI_API_KEY` takes precedence when both are set).

```bash
export XAI_API_KEY="your-api-key"
```

Create a client and send a request to the Responses API:

```typescript
import { Grok } from '@grok/sdk';

const client = new Grok();

const response = await client.responses.create({
  model: 'grok-4.7',
  input: 'Explain why the sky is blue in one sentence.',
});

console.log(response.toText());
```

Keep API keys on the server. The SDK blocks browser and Worker environments by default because shipping a secret key to client-side code exposes it to users.

The client class is also exported as `SpaceXSI` (and as the deprecated alias `SpaceXAI`), so existing code continues to run.

## Resources

Explore the SDK repository, release history, and REST API schemas:

* [GitHub repository](https://github.com/xai-org/xai-sdk-ts) — Browse source code, release notes, and examples for @grok/sdk.

* [Changelog](https://github.com/xai-org/xai-sdk-ts/blob/main/CHANGELOG.md) — Review version history and breaking changes before upgrading.

* [Issue tracker](https://github.com/xai-org/xai-sdk-ts/issues) — Report bugs or request SDK features on GitHub.

* [Inference API reference](/developers/rest-api-reference/inference) — Explore full REST request and response schemas.
