Skip to main content

Signature


Parameters

Any
required
Any LLM client instance. Auto-detects the provider.Supported: OpenAI, Anthropic, Google GenAI, LiteLLM, Cohere, Mistral.
bool
default:"False"
When True, captures prompt and response content in trace spans.
Only enable in development. Prompts may contain sensitive data.

Returns

A transparent proxy that behaves exactly like the original client, but emits OpenTelemetry spans for every API call.

Basic Usage

Your code doesn’t change. The proxy intercepts API calls transparently.

Supported Providers

OpenAI

Chat completions, embeddings, assistants.

Anthropic

Messages API, streaming.

Google GenAI

Gemini models, multimodal.

LiteLLM

100+ models via unified API.

Cohere

Command R+, embed, rerank.

Mistral

Mixtral, Mistral Large.

What Gets Traced

Every LLM API call emits an OTel span with GenAI semantic conventions:

Metrics


Streaming Support

hexr_llm() handles streaming responses transparently:
The span closes when the stream ends, with accurate token counts.

Async Support

Both sync and async clients are fully supported.

Cost Attribution

With per-process SPIFFE identity, hexr_llm() enables precise cost tracking:
This per-agent breakdown is visible in Jaeger traces and Grafana dashboards.

LLM Guard Integration

When LLM Guard is enabled, hexr_llm() automatically scans prompts and responses:
LLM Guard scanning happens transparently when HEXR_LLM_GUARD_ENABLED=true. No code changes needed.