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 Phoenix.
This page instruments OpenAI SDK calls to xAI’s API. It is not a separate xAI-specific OpenInference instrumentor.

Install

Setup

Add your xAI API key as an environment variable:
Connect your application to Phoenix with the register function:

Run xAI Grok

Observe

Now that you have tracing set up, all invocations of the OpenAI client pointed at xAI Grok will be streamed to your running Phoenix for observability and evaluation. Each call appears as a ChatCompletion LLM span with the prompt, response, model name, token usage, and latency.

Common Issues

  • Spans missing: register(..., auto_instrument=True) must run before your application sends requests, and openinference-instrumentation-openai must be installed in the same environment
  • 401 from xAI: Use your xAI API key, not an OpenAI key
  • Model not found: Replace grok-4.6 with a Grok model available in your xAI account
  • Base URL: Ensure you’re using https://api.x.ai/v1 as the base URL

Resources

xAI Quickstart

OpenInference OpenAI Instrumentation