> For the complete documentation index, see [llms.txt](https://docs.layerlens.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layerlens.ai/6.-build-wire-your-code/instrument-openai-assistants.md).

# Instrument OpenAI Assistants

Recipe — instrument OpenAI / Assistants. Pointer to the SDK samples.

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)
