Skip to main content
xAI serves its Grok models. Its API follows OpenAI’s format, so you wrap it with the OpenAI client and the SDK meters it with the OpenAI recipe.

Set up

Point the OpenAI client’s baseURL at xAI and wrap it:
xAI supports both the Chat Completions and Responses APIs. Both are metered.

What is reported

xAI returns a usage object in OpenAI’s format with the number of tokens each call consumed. Calls are reported under the openai.chat.completions.create or openai.responses.create event name, with the same metrics as OpenAI. Every usage field the provider returns is also included, with a raw. prefix. See How usage is reported. For details on xAI’s API, see xAI’s API reference.