OpenAI client and the SDK meters it with the OpenAI recipe.
Set up
Point theOpenAI client’s baseURL at xAI and wrap it:
What is reported
xAI returns ausage object in OpenAI’s format with the number of tokens each call consumed. The calls go through the OpenAI client, so they are reported under OpenAI event names. The wrapper reads the counts and reports them to Stigg as the metrics below.
Chat Completions
Responses
total_tokens includes the other token counts, so price the total or the parts, never both. To tell xAI apart from other vendors on the same event name, add a dimension such as provider to the stiggContext.
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.