> 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/sdk-python.md).

# Python SDK — auto-instrumentation

Stratix Python SDK reference — Stratix, AsyncStratix, complete resource surface, errors.

`pip install layerlens --extra-index-url https://sdk.layerlens.ai/package`. Sync and async. Source available at [`stratix-python`](https://github.com/layerlens/stratix-python).

## Client classes

The SDK exposes four public client classes, all backed by the same API:

* `Stratix` — primary sync client (authenticated, full surface)
* `AsyncStratix` — primary async client (authenticated, full surface)
* `PublicClient` — read-only client over the public catalog (no auth required)
* `AsyncPublicClient` — async variant of `PublicClient`

```python
from layerlens import Stratix, AsyncStratix, PublicClient, AsyncPublicClient
```

## Resources

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Client configuration</strong></td><td>Stratix / AsyncStratix constructors, env vars, retries.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/client.md">Read</a></td></tr><tr><td><strong>Public client</strong></td><td>`client.public.*` and `PublicClient` for catalog access.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/public-client.md">Read</a></td></tr><tr><td><strong>Models and benchmarks</strong></td><td>`client.models`, `client.benchmarks` — get, get_by_key, add, create_custom, create_smart.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/models-benchmarks.md">Read</a></td></tr><tr><td><strong>Evaluations</strong></td><td>`client.evaluations` — create, wait_for_completion, get_many.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/evaluations.md">Read</a></td></tr><tr><td><strong>Scorers</strong></td><td>`client.scorers` — LLM-backed graders.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/scorers.md">Read</a></td></tr><tr><td><strong>Judges</strong></td><td>`client.judges` — create, get, get_many, update, delete.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/judges.md">Read</a></td></tr><tr><td><strong>Judge optimizations</strong></td><td>`client.judge_optimizations` — estimate, create, get, apply.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/judge-optimizations.md">Read</a></td></tr><tr><td><strong>Traces</strong></td><td>`client.traces` — upload, get, get_many, delete, get_sources.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/traces.md">Read</a></td></tr><tr><td><strong>Trace evaluations</strong></td><td>`client.trace_evaluations` — create, get, get_results, estimate_cost.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/trace-evaluations.md">Read</a></td></tr><tr><td><strong>Results</strong></td><td>`client.results` — get, get_all.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/results.md">Read</a></td></tr><tr><td><strong>Comparisons</strong></td><td>`client.public.comparisons` — compare, compare_models.</td><td>(see public-client)</td></tr><tr><td><strong>Errors</strong></td><td>Full exception hierarchy.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/errors.md">Read</a></td></tr></tbody></table>

## Auto-instrumentation

The `layerlens.instrument` subpackage provides drop-in instrumentation for LLM provider clients and supported frameworks. Importing `instrument_openai()`, `instrument_anthropic()`, or framework callbacks like `LangChainCallbackHandler` wraps the client so trace data is emitted automatically as your code runs.

See [Integrations](/6.-build-wire-your-code/sdk-python.md) for the production adapter list and [framework integration pages](/10.-integrate-connect-your-stack/10-integrate.md) for setup details.

## Authentication

```bash
export LAYERLENS_STRATIX_API_KEY="..."
```

```python
from layerlens import Stratix
client = Stratix() # picks up env var
client = Stratix(api_key="...") # or explicit
```

Environment variables:

| Variable                     | Default                           | Notes                                          |
| ---------------------------- | --------------------------------- | ---------------------------------------------- |
| `LAYERLENS_STRATIX_API_KEY`  | (required)                        | Primary API key env var                        |
| `LAYERLENS_STRATIX_BASE_URL` | `https://api.layerlens.ai/api/v1` | Override for self-hosted / staging deployments |

## Sync vs async

```python
# Sync
from layerlens import Stratix
client = Stratix()
result = client.evaluations.wait_for_completion(evaluation)

# Async
from layerlens import AsyncStratix
client = AsyncStratix()
result = await client.evaluations.wait_for_completion(evaluation)
```

Every resource is available in both sync (`Stratix`) and async (`AsyncStratix`) clients.

## Quick reference — every public method by resource

```
client.traces.upload(file_path).get(id).get_many().delete(id).get_sources()
client.judges.create(name=, evaluation_goal=, [model_id=]).get(id).get_many().update(id,...).delete(id)
client.evaluations.create(model=, benchmark=).get(id).get_many().wait_for_completion(evaluation)
client.trace_evaluations.create(trace_id=, judge_id=).get(id).get_results(id).estimate_cost(...).wait_for_completion(id)
client.judge_optimizations.estimate(...).create(...).get(id).apply(id)
client.results.get(evaluation=).get_all(...)
client.scorers.create(name=, description=, model_id=, prompt=).get(id).get_many().update(id,...).delete(id)
client.models.get([type=, name=]).get_by_key(key).add(...).create_custom(name=, key=, api_url=,...).remove(id)
client.benchmarks.get([type=, name=]).get_by_key(key).add(...).create_custom(...).create_smart(...).remove(id)
client.public.models.get(...)
client.public.benchmarks.get(...)
client.public.evaluations.get(...)
client.public.comparisons.compare(...).compare_models(...)
```

The exact signatures are in each per-resource page below.

## Adapters · CLI · Examples · Security · Troubleshooting

Deeper SDK material ported from the `stratix-python` repo:

<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Adapters</strong></td><td>Per-framework + per-provider instrumentation guides (LangChain, LlamaIndex, CrewAI, OpenAI, Anthropic, Bedrock,...). Also: OTLP sink, Pydantic v1/v2 matrix, certification suite, testing.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/adapters/frameworks-langchain.md">Browse</a></td></tr><tr><td><strong>CLI</strong></td><td>`stratix` CLI — getting started, full command reference, 15 workflow recipes.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/cli/getting-started.md">Browse</a></td></tr><tr><td><strong>Examples</strong></td><td>Runnable samples for evaluations, judges, traces, models, public catalog.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/examples/README.md">Browse</a></td></tr><tr><td><strong>Security</strong></td><td>API key management, data privacy, environment variables, rate limiting.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/security/README.md">Browse</a></td></tr><tr><td><strong>Troubleshooting</strong></td><td>Authentication, common issues, error codes reference.</td><td><a href="https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/troubleshooting/README.md">Browse</a></td></tr></tbody></table>

## Where to next

* [Client configuration](https://github.com/LayerLens/gitbook-full/blob/main/13-reference/sdk-python/client.md)
* [Cookbook](/2.-get-started/all-cookbook-recipes.md)
* [Samples](/2.-get-started/samples-overview.md)
* [API reference (REST)](/13.1-sdk-and-apis/api.md)
* [Source on GitHub](https://github.com/layerlens/stratix-python)
