This integration is used to log usage with the xAI API.
1

Create an account and generate an API key

Log into Helicone or create an account. Once you have an account, you can generate an API key here.
2

Set up your Helicone API key in your .env file

HELICONE_API_KEY=<your-helicone-api-key>
XAI_API_KEY=<your-xai-api-key>
3

Modify the base URL path and set up authentication

OpenAI SDK
from openai import OpenAI
from dotenv import load_dotenv
import os

load_dotenv()

helicone_api_key = os.getenv("HELICONE_API_KEY")
XAI_API_KEY = os.getenv("XAI_API_KEY")

client = OpenAI(
  api_key=XAI_API_KEY,
  base_url="https://x.helicone.ai/v1",
  default_headers={
    "Helicone-Auth": f"Bearer {helicone_api_key}"
  }
)

chat_completion = client.chat.completions.create(
  model="grok-4-latest",
  messages=[{"role": "user", "content": "Hello, how are you?"}],
  max_tokens=1024,
  temperature=0.7
)

print(chat_completion)
4

Verify your requests in Helicone

With the above setup, any calls to xAI will automatically be logged and monitored by Helicone. Review them in your Helicone dashboard.