Skip to main content

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
ModelDescription
grok-4Latest and most capable Grok model
grok-4-0709Grok 4 July 2025 snapshot
grok-4-fast-reasoningGrok 4 optimized for fast reasoning
grok-4-fast-non-reasoningGrok 4 fast non-reasoning mode
grok-4.1-fast-reasoningGrok 4.1 fast reasoning
grok-4.1-fast-non-reasoningGrok 4.1 fast non-reasoning
grok-code-fast-1Optimized for code generation
grok-3-betaGrok 3 beta
grok-3-fast-betaFast Grok 3 beta
grok-3-mini-betaCompact Grok 3 beta
grok-3-mini-fast-betaFast compact Grok 3 beta
grok-2Grok 2
grok-2-latestLatest Grok 2 snapshot
grok-2-1212Grok 2 December 2024 snapshot

Proxy Base URL

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

Prerequisites

  1. An xAI API key
  2. An Adaline API key, project ID, and prompt ID

Chat Completions

Complete Chat

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)

Stream Chat

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


Back to Integrations

Browse all integrations