> ## Documentation Index
> Fetch the complete documentation index at: https://www.adaline.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# xAI

> Integrate xAI Grok models through the Adaline Proxy for automatic telemetry and observability.

# xAI

Integrate xAI Grok models through the Adaline Proxy to automatically capture telemetry — requests, responses, token usage, latency, and costs — with minimal code changes. xAI uses an OpenAI-compatible API, so integration is straightforward.

## Supported Models

**Chat Models**

| Model | Description |
| - | - |
| `grok-4` | Latest and most capable Grok model |
| `grok-4-0709` | Grok 4 July 2025 snapshot |
| `grok-4-fast-reasoning` | Grok 4 optimized for fast reasoning |
| `grok-4-fast-non-reasoning` | Grok 4 fast non-reasoning mode |
| `grok-4.1-fast-reasoning` | Grok 4.1 fast reasoning |
| `grok-4.1-fast-non-reasoning` | Grok 4.1 fast non-reasoning |
| `grok-code-fast-1` | Optimized for code generation |
| `grok-3-beta` | Grok 3 beta |
| `grok-3-fast-beta` | Fast Grok 3 beta |
| `grok-3-mini-beta` | Compact Grok 3 beta |
| `grok-3-mini-fast-beta` | Fast compact Grok 3 beta |
| `grok-2` | Grok 2 |
| `grok-2-latest` | Latest Grok 2 snapshot |
| `grok-2-1212` | Grok 2 December 2024 snapshot |

## Proxy Base URL

```
https://gateway.adaline.ai/v1/xai/
```

## Prerequisites

1. An [xAI API key](https://x.ai)
2. An [Adaline API key](https://www.adaline.ai/docs/admin/create-api-keys.md), project ID, and prompt ID

## Chat Completions

### Complete Chat

```python Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="your-xai-api-key",
    base_url="https://gateway.adaline.ai/v1/xai/"
)

headers = {
    "adaline-api-key": "your-adaline-api-key",
    "adaline-project-id": "your-project-id",
    "adaline-prompt-id": "your-prompt-id"
}

response = client.chat.completions.create(
    model="grok-2",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What are the latest developments in AI?"}
    ],
    extra_headers=headers
)

print(response.choices[0].message.content)
```

```typescript TypeScript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "your-xai-api-key",
  baseURL: "https://gateway.adaline.ai/v1/xai/",
});

const response = await client.chat.completions.create(
  {
    model: "grok-2",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "What are the latest developments in AI?" },
    ],
  },
  {
    headers: {
      "adaline-api-key": "your-adaline-api-key",
      "adaline-project-id": "your-project-id",
      "adaline-prompt-id": "your-prompt-id",
    },
  }
);

console.log(response.choices[0].message.content);
```

### Stream Chat

```python Python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="your-xai-api-key",
    base_url="https://gateway.adaline.ai/v1/xai/"
)

headers = {
    "adaline-api-key": "your-adaline-api-key",
    "adaline-project-id": "your-project-id",
    "adaline-prompt-id": "your-prompt-id"
}

stream = client.chat.completions.create(
    model="grok-2",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain how neural networks work."}
    ],
    stream=True,
    extra_headers=headers
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")
```

## Next Steps

* [Multi-Step Workflows](https://www.adaline.ai/docs/integrations/examples/multi-step-workflows.md) — RAG pipelines, multi-step generation, and conversational agents
* [Headers Reference](https://www.adaline.ai/docs/reference/proxy/headers.md) — Complete header documentation

***

> [card] [Back to Integrations](https://www.adaline.ai/docs/integrations/introduction.md)
>
> Browse all integrations


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.