# Instrument OpenAI Assistants

Canonical samples:

* [`samples/integrations/openai_traced.py`](https://github.com/layerlens/stratix-python/blob/main/samples/integrations/openai_traced.py) — manual trace upload around an OpenAI completion
* [`samples/integrations/openai_instrumented.py`](https://github.com/layerlens/stratix-python/blob/main/samples/integrations/openai_instrumented.py) — zero-code auto-instrumentation via `instrument_openai()`, `@trace`, `span()`

```bash
pip install 'layerlens[providers-openai]'
```

The OpenAI provider adapter emits one event per chat or embedding call: `model.invoke` (with parameters, token counts, latency, response\_id, system\_fingerprint, full messages); `cost.record` (USD computed from pricing table); `tool.call` (one per tool when present); `policy.violation` (on SDK error). Streaming responses emit a single consolidated `model.invoke` on completion.

Capture configs: `CaptureConfig.minimal()`, `.standard()`, or `.full()`. Circuit breaker opens after 10 consecutive sink failures (60s cooldown, silent drop while open).

## See also

* [SDK adapter doc: OpenAI](https://github.com/layerlens/stratix-python/blob/main/docs/adapters/providers-openai.md)
* [Integrations](/6.-build-wire-your-code/migration.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.layerlens.ai/6.-build-wire-your-code/instrument-openai-assistants.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
