Skip to main content
xAI provides Grok models through an API that is compatible with the OpenAI SDK. Set the OpenAI client’s base_url to https://api.x.ai/v1 and use openinference-instrumentation-openai to send Grok traces to Arize AX.
This page instruments OpenAI SDK calls to xAI’s API. It is not a separate xAI-specific OpenInference instrumentor.

Prerequisites

  • Python 3.9+
  • An Arize AX account (sign up)
  • An XAI_API_KEY from xAI

Launch Arize

  1. Sign in to your Arize AX account.
  2. From Space Settings, copy your Space ID and API Key. You will set them as ARIZE_SPACE_ID and ARIZE_API_KEY below.

Install

Configure credentials

Setup tracing

Run xAI Grok

Expected output

Verify in Arize

  1. Open your Arize AX space and select project xai-grok-tracing-example.
  2. You should see a new trace within ~30 seconds containing a ChatCompletion LLM span with prompt, response, model, token, and latency metadata.
  3. If no traces appear, see Troubleshooting.

Check from the skill, CLI, or SDK

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.
Install the Arize Skills plugin and let your coding agent check for you:
Then prompt your agent:
Use the arize-trace skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.

Troubleshooting

  • No traces in Arize. Confirm ARIZE_SPACE_ID and ARIZE_API_KEY are set in the same shell that runs example.py.
  • xAI spans missing but other spans present. OpenAIInstrumentor().instrument(...) must run before any import openai.
  • 401 from xAI. Use your xAI API key, not your OpenAI or Arize API key.
  • Model not found. Replace grok-4.6 with a Grok model available in your xAI account.

Resources

xAI Quickstart

OpenInference OpenAI Instrumentor

LLM Evaluation Guide

Agent Evaluation Guide