> ## 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.

# PrismML Tracing

> Trace PrismML Bonsai model calls in Phoenix with OpenInference auto-instrumentation for the OpenAI Python SDK, using PrismML's local OpenAI-compatible server.

[PrismML](https://prismml.com/) provides the open-weight [Bonsai](https://docs.prismml.com/) model family, which can run locally through an OpenAI-compatible server. The default server endpoint is `http://localhost:8080/v1`, so Phoenix captures PrismML calls via the [`openinference-instrumentation-openai`](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai) package, the same instrumentor that covers OpenAI's hosted API.

## Prerequisites

Start PrismML's OpenAI-compatible server at `http://localhost:8080` by following PrismML's [Run the Server](https://docs.prismml.com/run/server) guide. The server loads the model selected by its configuration and does not require authentication.

## Install

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

## Setup

PrismML's local server does not require an API key. The OpenAI client still requires a non-empty value, so the example uses `not-needed`.

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 PrismML

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

# Point the OpenAI client at PrismML's local OpenAI-compatible endpoint.
client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="not-needed",
)

response = client.chat.completions.create(
    # The server accepts any model ID and serves the model it loaded.
    model="bonsai",
    messages=[
        {
            "role": "user",
            "content": "Why is the ocean salty? Answer in two sentences.",
        },
    ],
    # Bonsai models think before answering, which can use thousands of tokens.
    max_tokens=8192,
)

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

## Observe

Now that you have tracing set up, all invocations of the OpenAI client pointed at PrismML 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
* **`Connection refused` or `ConnectError` to `localhost:8080`**: The PrismML server is not running or is listening on a different port. Start it with PrismML's [server instructions](https://docs.prismml.com/run/server)
* **Model not found**: The server exposes the model it loaded. Use the model name returned by `GET http://localhost:8080/v1/models`, or use `bonsai` as shown in this guide
* **Empty or cut-off answer**: Thinking used up `max_tokens` before the model finished. PrismML recommends a `max_tokens` of 8,192 or more with thinking on

## Resources

> **[PrismML OpenAI-Compatible Server](https://docs.prismml.com/run/server)**
>
> Run the PrismML server

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