> ## 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](/docs/admin/create-api-keys), project ID, and prompt ID

## Chat Completions

### Complete Chat

<CodeGroup>
  ```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);
  ```
</CodeGroup>

### Stream Chat

<CodeGroup>
  ```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="")
  ```
</CodeGroup>

## Next Steps

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

***

<Card title="Back to Integrations" icon="arrow-left" href="/docs/integrations/introduction">
  Browse all integrations
</Card>
