Skip to main content

LLM libraries

Besides your runs and steps, the SDK can record each call your application makes to an AI model: the request (prompt, messages, parameters), the answer, the model name, token counts, the finish reason and the duration. It does this automatically, with no code change, for the libraries below.

Supported libraries​

LibraryDetected when this is importableInstall the extra
OpenAI (openai), including OpenAI-compatible providers called through the openai clientopenaipip install "zyonix-sdk[openai]"
Anthropic (anthropic)anthropicpip install "zyonix-sdk[anthropic]"
LangChainlangchain_corepip install "zyonix-sdk[langchain]"
LlamaIndexllama_index.corepip install "zyonix-sdk[llama-index]"
LiteLLMlitellmpip install "zyonix-sdk[litellm]"
AWS Bedrock (through boto3)botocorepip install "zyonix-sdk[bedrock]"

Each extra installs the matching OpenInference instrumentation package. You never import or configure it yourself.

How it works​

When zyonix.init() starts, it looks for each library above. For every library that is installed and whose extra is installed, it switches on recording of that library's calls. A library that is installed without its extra is skipped with a warning:

zyonix: openai is installed but not instrumented; install zyonix-sdk[openai]

zyonix doctor lists what it found:

[ ok ] LLM library openai 1.82.0: auto-instrumented
[warn] LLM library anthropic 0.52.0: not instrumented; install zyonix-sdk[anthropic]

zyonix.shutdown() switches the recording off again.

How the calls appear​

A model call made inside a run is recorded as its own span under the step that made it. On the website, open a document: the call is shown inside its step (for example extract), with the model, the token counts and the duration; with full capture also the prompt and the answer, after redaction. Token counts also feed the Tokens page.

run doc_id=INV-2026-0042
├─ parse
├─ extract (replayable)
│ └─ ChatCompletion model=gpt-4o-mini prompt 1,204 tokens completion 312 tokens
├─ validate
└─ save_invoice (tool)
  • A model call made outside any run (at start-up, in a health check) is not sent.
  • A model call made in a thread you started is recorded only if that thread runs with the run's context (see threads).
  • In hash_only mode the prompt, the answer and every other content attribute the instrumentation records are replaced by hashes before they leave the process. Model names, token counts, timings and finish reasons stay readable.
  • Instrumentation attributes are redacted and size-capped like your step payloads.

Choosing which libraries to record​

The instrument setting in zyonix.yaml (or init(instrument=...)):

ValueMeaning
auto (default)Every supported library that is installed with its extra.
noneNo automatic recording. Your runs and steps are still recorded.
a list, for example [openai]Only these: openai, anthropic, langchain, llama-index, litellm, bedrock.
instrument: [openai]
zyonix.init(service="invoice-extractor", instrument="none")

Use a list when you have several libraries installed but call models through one of them (for example LangChain on top of OpenAI: recording both can show each call twice, once as a LangChain step and once as the OpenAI request; that is often useful, but you can keep only one).

Other libraries and your own HTTP calls​

For a library not in the table (or a model you call over plain HTTP), install zyonix-sdk without an extra. Your runs and steps are recorded as usual; only the separate model-call spans and their token counts are missing. Put the model call in its own step (@zyonix.step("extract")) so its inputs, output, errors and duration are recorded:

import httpx
import zyonix


@zyonix.step("extract", replayable=True)
def extract(document_text: str, config: dict) -> dict:
response = httpx.post(
config["url"],
json={"model": config["model"], "prompt": document_text},
timeout=60,
)
response.raise_for_status()
return response.json()["result"]

If your application already uses OpenTelemetry​

Many tracing tools are built on OpenTelemetry and install the same OpenInference instrumentation. Zyonix keeps out of their way:

  • The SDK records on its own, private tracer provider. Your exporters never receive Zyonix spans, and Zyonix receives only traces that start with a Zyonix run.

  • If your application has installed its own global tracer provider and already instrumented an LLM library, Zyonix leaves that instrumentation alone (so your tool keeps receiving the calls) and logs:

    zyonix: openai is already instrumented by the application; Zyonix leaves it alone and does not capture those LLM calls (set otel_provider: shared to share them)

    Your runs and steps are still recorded; only the model-call spans are missing in Zyonix.

  • To have both, set otel_provider: shared. The SDK then joins your application's tracer provider, and both tools see the model calls. Note that your own exporters then also receive the Zyonix spans and the instrumentation's prompts and answers, unredacted. zyonix doctor warns about this. See Configuration.

The order matters for detection: if your tool sets up its provider and instrumentation before zyonix.init(), Zyonix sees it and steps aside. Call zyonix.init() after your other tracing setup.