Using Witdem with LiteLLM¶
Status: beta. The integration appends a content-safe LiteLLM custom callback. It records the actual provider/model response, usage, reported cost, failures, and OpenRouter routing evidence without replacing callbacks already owned by the application.
Embedded LiteLLM SDK¶
Install the optional dependency:
Wrap the application workload, not every completion(...) call:
import litellm
from witdem_sdk.integrations.litellm import instrument
def run_agent():
response = litellm.completion(
model="openrouter/openai/gpt-5-mini",
messages=[{"role": "user", "content": "Give one telemetry tip."}],
)
return {"answer": response.choices[0].message.content}
run_agent = instrument(run_agent)
result = run_agent()
The wrapper creates one execution for the workload, installs the callback for that invocation, preserves existing callbacks, and evaluates result using .witdem/witdem.yaml.
If the application already owns its execution lifecycle, install only the callback:
LiteLLM Proxy¶
The proxy can export its native OpenTelemetry directly to Witdem without adding the Witdem SDK to calling applications:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
Proxy-only telemetry provides operational model health and spend. To attach a final application outcome or product goal, the calling workflow still needs a correlated Witdem execution and YAML contract.
Observed facts¶
- requested and returned model;
- actual LiteLLM provider;
- input, output, cached, cache-write, reasoning, and audio tokens when present;
response_costas authoritative money withlitellm_reportedprovenance;- failure status without making telemetry failures break model calls;
- OpenRouter selected provider, route strategy, attempts, BYOK state, region, and charged cost when present.
Prompt and response content is never copied into Witdem attributes by this callback.