> ## Documentation Index
> Fetch the complete documentation index at: https://arizeai-433a7140.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Z.ai Tracing

> Trace Z.ai GLM model calls in Phoenix with OpenInference auto-instrumentation for the OpenAI Python SDK, since Z.ai provides an OpenAI-compatible API endpoint.

[Z.ai](https://z.ai/) provides GLM models through an API compatible with the OpenAI SDK. Set the OpenAI client's `base_url` to Z.ai and use [`openinference-instrumentation-openai`](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai) to send LLM traces to Phoenix.

> [!NOTE]
>
> This page instruments OpenAI SDK calls to Z.ai's OpenAI-compatible endpoint. It is not a separate Z.ai-specific OpenInference instrumentor.

## Install

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
pip install arize-phoenix-otel openinference-instrumentation-openai openai
```

## Setup

Add your Z.ai API key as an environment variable:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export ZAI_API_KEY="<your-zai-api-key>"
```

Connect your application to Phoenix with the `register` function:

from phoenix.otel import register

&#x20; \# configure the Phoenix tracer
&#x20; tracer\_provider = register(
&#x20; project\_name="my-llm-app", # Default is 'default'
&#x20; auto\_instrument=True # Auto-instrument your app based on installed OI dependencies
&#x20; )

## Run Z.ai

```python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.z.ai/api/paas/v4/",
    api_key=os.environ["ZAI_API_KEY"],
)

response = client.chat.completions.create(
    model="glm-5.3",
    messages=[
        {
            "role": "user",
            "content": "What production signal should an LLM observability tool capture?",
        },
    ],
)

print(response.choices[0].message.content)
```

## Observe

Now that you have tracing set up, all invocations of the OpenAI client pointed at Z.ai 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 Z.ai**: Use your Z.ai API key, not an OpenAI key
* **Model not found**: Replace `glm-5.3` with a model available in your Z.ai account. Some Z.ai plans use a different OpenAI-compatible base URL, so confirm the endpoint in your Z.ai console

## Resources

> **[Z.ai OpenAI SDK Guide](https://docs.z.ai/guides/develop/openai/python)**
>
> Z.ai OpenAI SDK docs

> **[OpenInference OpenAI Instrumentation](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai)**
>
> OpenAI instrumentation package
