Integrations / LiteLLM
To trace LiteLLM with Tracify, point an OpenAI client at your LiteLLM proxy and wrap it with the Tracify SDK. If you call litellm.completion directly in Python, record the call as a step with its token usage.
Your code
LiteLLM
Tracify
One run.
Setup
For the proxy route you only need the OpenAI library.
pip install tracify-sdk openaiCreate a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.
export TRACIFY_API_KEY="tracify_sk_live_..."The LiteLLM proxy speaks the OpenAI format. Point your client at it and wrap that client. Every provider behind the proxy is traced the same way.
import tracify
from openai import OpenAI
llm = tracify.wrap_openai(OpenAI(
base_url="http://localhost:4000",
api_key="your-litellm-key",
))
reply = llm.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)The litellm function is not wrapped by the SDK, so record it as a step. LiteLLM returns usage in the OpenAI shape.
import litellm
import tracify
def ask(model: str, prompt: str) -> str:
messages = [{"role": "user", "content": prompt}]
with tracify.span("litellm", type="llm", input=messages) as step:
response = litellm.completion(model=model, messages=messages)
text = response.choices[0].message.content
step.set(
model=model,
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens,
)
step.set_output(text)
return textRun your code one time, then open the Tracing page of your project. Your LiteLLM call shows up as a run with its steps in order, plus the tokens, time and any error for each call.
Good to know
The wrapper reads the OpenAI call format, so calls are labeled as OpenAI-style in the trace. The model name you send is always the one shown, so you can still tell models apart.
Good to know
Tracify records the model name you asked for. If LiteLLM falls back to another provider, the extra time shows up in the latency of that one call.
Good to know
Tracify records the tokens the provider returns. A dollar cost is shown when you give the wrapper your own rates with calculate_cost (Python) or calculateCost (TypeScript), so the number always matches your real price plan.
Full details in the documentation. All integrations are listed on the integrations page.
