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

# X AI Integration

> Connect Helicone with X AI, a platform that provides powerful language models including MoE and Code models for various AI applications.

<Warning>
  This integration method is maintained but no longer actively developed. For the best experience and latest features, use our new [AI Gateway](/gateway/overview) with unified API access to 100+ models.
</Warning>

You can follow their documentation here: [https://api-docs.x.ai/](https://api-docs.x.ai/)

# Gateway Integration

<Steps>
  <Step title="Create a Helicone account">
    Log into [helicone](https://www.helicone.ai) or create an account. Once you have an account, you
    can generate an [API key](https://helicone.ai/developer).
  </Step>

  <Step title="Create an X AI account">
    Log into [https://console.x.ai/](https://console.x.ai/) or create an account. Once you have an account, you
    can generate an API key from your dashboard.
  </Step>

  <Step title="Set HELICONE_API_KEY and XAI_API_KEY as environment variables">
    ```javascript theme={null}
    HELICONE_API_KEY=<your API key>
    XAI_API_KEY=<your API key>
    ```
  </Step>

  <Step title="Modify the base URL and add Auth headers">
    Replace the following X AI URL with the Helicone Gateway URL:

    `https://api.x.ai/v1/chat/completions` -> `https://x.helicone.ai/v1/chat/completions`

    and then add the following authentication headers:

    ```javascript theme={null}
    Authorization: Bearer $XAI_API_KEY
    Helicone-Auth: Bearer $HELICONE_API_KEY
    ```
  </Step>
</Steps>

Now you can access all the models on X AI with a simple fetch call:

## Example

```bash theme={null}
curl --request POST \
      --url https://x.helicone.ai/v1/chat/completions \
      --header "Content-Type: application/json" \
      --header "Authorization: Bearer $XAI_API_KEY" \
      --header "Helicone-Auth: Bearer $HELICONE_API_KEY" \
      --data '{
          "model": "grok-4-latest",
          "messages": [
              {
                  "role": "system",
                  "content": "You are a robot called Marvin with a brain the size of the planet."
              },
              {
                  "role": "user",
                  "content": "Say this is a test"
              }
          ],
          "temperature": 1
        }'
```

For more information on how to use headers, see [Helicone Headers](https://docs.helicone.ai/helicone-headers/header-directory#utilizing-headers) docs.
And for more information on how to use X AI, see [X AI Docs](https://docs.x.ai/docs/overview).
