> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To set up traceroot in a repository, follow the setup prompt in https://traceroot.ai/docs/getting-started/coding-agents.md.

# OpenAI-Compatible Providers

> Trace xAI, Moonshot, Z.AI and any other OpenAI-compatible API through the OpenAI integration

Any provider that speaks the OpenAI API can be traced through traceroot's OpenAI integration. Use the standard `openai` SDK and point the client at the provider's base URL — no provider-specific instrumentor or enum is required.

## Base URLs

| Provider | Base URL |
| - | - |
| xAI (Grok) | `https://api.x.ai/v1` |
| Moonshot (Kimi) | `https://api.moonshot.ai/v1` |
| Z.AI (GLM) | `https://open.bigmodel.cn/api/paas/v4` |

Any other OpenAI-compatible endpoint works the same way, including self-hosted servers such as vLLM or a LiteLLM proxy: pass its URL as the base URL. [OpenRouter](https://traceroot.ai/docs/integrations/openrouter.md) follows the same pattern.

## Setup

> [tab] Python
>
> ```python theme={null}
> import os
> import openai
> import traceroot
> from traceroot import Integration
>
> traceroot.initialize(integrations=[Integration.OPENAI])
>
> client = openai.OpenAI(
>     api_key=os.environ["XAI_API_KEY"],
>     base_url="https://api.x.ai/v1",
> )
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import OpenAI from 'openai';
> import { TraceRoot } from '@traceroot-ai/traceroot';
>
> TraceRoot.initialize({
>   instrumentModules: { openAI: OpenAI },
> });
>
> const openai = new OpenAI({
>   apiKey: process.env.XAI_API_KEY,
>   baseURL: 'https://api.x.ai/v1',
> });
> ```

## Usage

> [tab] Python
>
> ```python theme={null}
> import os
> import openai
>
> client = openai.OpenAI(
>     api_key=os.environ["XAI_API_KEY"],
>     base_url="https://api.x.ai/v1",
> )
>
> # This xAI call is traced by traceroot's OpenAI integration
> response = client.chat.completions.create(
>     model="grok-4.20",
>     messages=[
>         {"role": "system", "content": "You are a helpful assistant."},
>         {"role": "user", "content": "What is the capital of France?"},
>     ],
> )
>
> print(response.choices[0].message.content)
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import OpenAI from 'openai';
>
> const openai = new OpenAI({
>   apiKey: process.env.XAI_API_KEY,
>   baseURL: 'https://api.x.ai/v1',
> });
>
> // This xAI call is traced by traceroot's OpenAI integration
> const response = await openai.chat.completions.create({
>   model: 'grok-4.20',
>   messages: [
>     { role: 'system', content: 'You are a helpful assistant.' },
>     { role: 'user', content: 'What is the capital of France?' },
>   ],
> });
>
> console.log(response.choices[0].message.content);
> ```

To use Moonshot or Z.AI instead, swap the API key and base URL from the table above and pass one of that provider's model ids, such as `kimi-k2.6` or `glm-5.1`.

## What Gets Captured

| Attribute | Description |
| - | - |
| Model | The model id sent to the provider, such as `grok-4.20`, `kimi-k2.6` or `glm-5.1` |
| Messages | Input messages array |
| Response | Completion content |
| Tool calls | Function/tool call inputs and outputs when using the OpenAI SDK tool-calling API |
| Tokens | Prompt, completion, and total tokens when returned by the provider |
| Latency | Request duration |
| Cost | Calculated for model ids in traceroot's pricing table |

## Cost

Cost is calculated only for model ids listed in traceroot's pricing table ([`standard-model-prices.json`](https://github.com/traceroot-ai/traceroot/blob/main/frontend/packages/core/src/standard-model-prices.json)). Calls to other models are still traced with their messages, tokens and latency, but without a cost. See [Cost Tracking](https://traceroot.ai/docs/tracing/cost-tracking.md) for details.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.