LiteLLM
Auto-instrument LiteLLM for unified LLM access.
Risicare automatically instruments LiteLLM for unified access to 100+ LLM providers.
Python only
Installation
pip install 'risicare[litellm]'
# or
pip install risicare litellmVersion Compatibility
Requires litellm >= 1.30.0.
Auto-Instrumentation
import risicare
import litellm
risicare.init()
# Automatically traced
response = litellm.completion(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)What's Captured
| Feature | Description |
|---|---|
| Completion Calls | All completion/acompletion calls |
| Provider Routing | Model-to-provider mapping |
| Fallbacks | Fallback chain execution |
| Cost Tracking | LiteLLM's own cost, in the span attribute gen_ai.usage.cost_usd |
| Cached and reasoning tokens | gen_ai.usage.cache_read.input_tokens, gen_ai.usage.cache_write.input_tokens and gen_ai.usage.reasoning.output_tokens, when the Usage object of LiteLLM gives them (Python 0.7.0 and later) |
| Load Balancing | Router selections |
Span Hierarchy
litellm.completion/{model} (LLM_CALL kind)
Provider Deduplication
Provider Deduplication
When using LiteLLM, underlying LLM provider spans are automatically suppressed to avoid duplicate traces. You don't need to disable provider instrumentation manually.
Multiple Providers
LiteLLM's unified interface works with all providers:
# OpenAI
response = litellm.completion(model="gpt-4o", messages=[...])
# Anthropic
response = litellm.completion(model="claude-sonnet-5-5", messages=[...])
# Bedrock
response = litellm.completion(model="bedrock/claude-3-sonnet", messages=[...])
# Together AI
response = litellm.completion(model="together_ai/meta-llama/Llama-3-70b", messages=[...])Streaming
response = litellm.completion(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a story"}],
stream=True
)
for chunk in response:
print(chunk.choices[0].delta.content or "", end="")Since Python 0.6.3, the SDK ends the span of a streamed call on your thread when your loop reads the stream to its end. A flush() right after the loop then includes that span. The token counts come only from the usage that LiteLLM puts on the last chunk. LiteLLM does this when you set stream_options={"include_usage": True}. Without that option, the span of a stream has no token counts and no cost. The cached and reasoning counts come from the same usage.
LiteLLM can write values that the provider did not give
The SDK sends the values of the Usage object of LiteLLM, and LiteLLM writes some values that the provider did not give (seen with LiteLLM 1.101.0 and 1.106.2). For an Anthropic model, LiteLLM writes 0 for a cache count or a reasoning count that Anthropic does not give. When Anthropic gives no reasoning count but the answer has thinking text, LiteLLM estimates the count from that text. For a stream of a text answer, LiteLLM writes a reasoning count of 0 when the provider gives none. The SDK cannot tell these values from the values of the provider.
Fallbacks
Fallback chains are fully traced:
response = litellm.completion(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}],
fallbacks=["claude-sonnet-5-5", "gemini/gemini-2.5-pro"]
)
# Each fallback attempt appears as a child spanRouter
The LiteLLM Router is instrumented:
from litellm import Router
router = Router(
model_list=[
{"model_name": "gpt-4", "litellm_params": {"model": "gpt-4o"}},
{"model_name": "gpt-4", "litellm_params": {"model": "azure/gpt-4"}},
]
)
# Load balancing decisions are captured
response = router.completion(model="gpt-4", messages=[...])Embeddings
response = litellm.embedding(
model="text-embedding-ada-002",
input=["Hello, world!"]
)Cost Tracking
LiteLLM's own cost calculation is recorded in the span attribute gen_ai.usage.cost_usd. The cost that the dashboard shows does not use it: it comes from the server's price table (see Cost Tracking). If the model name on the span is in the provider/model form, it gets the fallback price there.
from litellm import completion_cost
response = litellm.completion(model="gpt-4o", messages=[...])
cost = completion_cost(completion_response=response)
# LiteLLM's cost appears in the span attribute gen_ai.usage.cost_usd