LiteLLM callback handler for Sigil Python SDK
Project description
Sigil Python Framework Module: LiteLLM
sigil-sdk-litellm is a LiteLLM callback handler that exports generation telemetry to Sigil.
Installation
pip install sigil-sdk sigil-sdk-litellm
pip install litellm
Quickstart
import litellm
from sigil_sdk import Client
from sigil_sdk_litellm import SigilLiteLLMLogger
client = Client()
handler = SigilLiteLLMLogger(client=client)
litellm.callbacks = [handler]
response = litellm.completion(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
client.shutdown()
Streaming
import litellm
from sigil_sdk import Client
from sigil_sdk_litellm import SigilLiteLLMLogger
client = Client()
litellm.callbacks = [SigilLiteLLMLogger(client=client)]
response = litellm.completion(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Give me three reliability tips."}],
stream=True,
)
for chunk in response:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
print()
client.shutdown()
Configuration
All options are keyword-only on SigilLiteLLMLogger:
| Parameter | Type | Default | Description |
|---|---|---|---|
client |
sigil_sdk.Client |
required | Sigil SDK client instance |
capture_inputs |
bool |
True |
Record input messages |
capture_outputs |
bool |
True |
Record output messages |
agent_name |
str |
"" |
Default agent name (see below for per-request) |
agent_version |
str |
"" |
Default agent version (see below for per-request) |
conversation_id |
str |
"" |
Default conversation ID (see below for per-request) |
extra_tags |
dict[str, str] |
None |
Additional tags merged into every generation |
extra_metadata |
dict[str, Any] |
None |
Additional metadata merged into every generation |
The create_sigil_litellm_logger factory accepts the same parameters.
Per-Request Metadata
The handler resolves agent_name, agent_version, and conversation_id from per-request LiteLLM metadata, falling back to the static values from handler init. This is useful when multiple agents share a single LiteLLM proxy.
response = litellm.completion(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Continue our chat."}],
metadata={
"agent_name": "search-agent",
"agent_version": "v2",
"conversation_id": "conv-abc-123",
},
)
For conversation_id, the handler also checks session_id and thread_id metadata keys as fallbacks.
LiteLLM Proxy (Docker)
When running LiteLLM as a proxy server in Docker, register the handler via a callback file next to your config.
1. Extend the Docker image:
FROM ghcr.io/berriai/litellm:v1.82.3-stable.patch.2
RUN pip install sigil-sdk sigil-sdk-litellm
2. Create a callback file (sigil_callback.py, same directory as config.yaml):
import os
from sigil_sdk import Client
from sigil_sdk.config import AuthConfig, ClientConfig, GenerationExportConfig
from sigil_sdk_litellm import SigilLiteLLMLogger
client = Client(ClientConfig(
generation_export=GenerationExportConfig(
protocol="http",
endpoint=os.environ["SIGIL_ENDPOINT"],
auth=AuthConfig(
mode="basic",
tenant_id=os.environ.get("SIGIL_TENANT_ID", ""),
basic_password=os.environ.get("SIGIL_API_KEY", ""),
),
),
))
sigil_handler = SigilLiteLLMLogger(
client=client,
agent_name="litellm-proxy",
)
3. Reference it in config.yaml:
model_list:
- model_name: gpt-4o-mini
litellm_params:
model: openai/gpt-4o-mini
litellm_settings:
callbacks: sigil_callback.sigil_handler
The proxy resolves sigil_callback.sigil_handler by importing sigil_callback.py from the config directory and using the sigil_handler instance.
4. Mount both files and run:
docker run -d \
-v $(pwd)/config.yaml:/app/config.yaml \
-v $(pwd)/sigil_callback.py:/app/sigil_callback.py \
-e SIGIL_ENDPOINT=https://your-sigil-endpoint \
-e SIGIL_TENANT_ID=your-tenant \
-e SIGIL_API_KEY=your-key \
-p 4000:4000 \
your-litellm-image \
--config /app/config.yaml
The callback file reads connection details from environment variables. Adjust the AuthConfig mode to match your deployment (see sigil_sdk.config for tenant, bearer, and basic modes).
Behavior
- Mode mapping: non-stream calls ->
SYNC, stream calls ->STREAMwith first-token timestamp. - Provider detection: uses
custom_llm_providerfrom LiteLLM's standard logging object. - Failed calls are recorded with the error attached via
set_call_error. - Only chat completion call types (
completion,acompletion) are recorded; embeddings and other call types are skipped. - Framework tags are always set:
sigil.framework.name=litellmsigil.framework.source=handlersigil.framework.language=python
- LiteLLM
request_tagsare forwarded aslitellm.tag.<value>. - Token usage includes detailed breakdowns (cached tokens, reasoning tokens) when the provider returns them.
- Tool calls and tool results in messages are mapped to Sigil's tool call/result parts.
Call client.shutdown() during teardown to flush buffered telemetry.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sigil_sdk_litellm-0.2.0.tar.gz.
File metadata
- Download URL: sigil_sdk_litellm-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e618b8e9b003082622526c90da3537998532540a15f9414b6d33822caccd3a9b
|
|
| MD5 |
59ccab292fd15ac7929e7029d6f1e59d
|
|
| BLAKE2b-256 |
ecc0301717c2189ffec331055b7926d18b92a4a67c5226ea31b09527d1faaf10
|
Provenance
The following attestation bundles were made for sigil_sdk_litellm-0.2.0.tar.gz:
Publisher:
python-sdks-publish.yml on grafana/sigil-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigil_sdk_litellm-0.2.0.tar.gz -
Subject digest:
e618b8e9b003082622526c90da3537998532540a15f9414b6d33822caccd3a9b - Sigstore transparency entry: 1417607129
- Sigstore integration time:
-
Permalink:
grafana/sigil-sdk@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sigil_sdk_litellm-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sigil_sdk_litellm-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10bc41f5e87ce484bc1a4c2c19ffe7934154dac0b462a37ef3c45baad3c345ba
|
|
| MD5 |
b32b9b5d2277b99f74d3c20d8b9029f9
|
|
| BLAKE2b-256 |
8157c99f14310f0bd77134126bc352d2a9a914def5a457c775453f9f6492d216
|
Provenance
The following attestation bundles were made for sigil_sdk_litellm-0.2.0-py3-none-any.whl:
Publisher:
python-sdks-publish.yml on grafana/sigil-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigil_sdk_litellm-0.2.0-py3-none-any.whl -
Subject digest:
10bc41f5e87ce484bc1a4c2c19ffe7934154dac0b462a37ef3c45baad3c345ba - Sigstore transparency entry: 1417607382
- Sigstore integration time:
-
Permalink:
grafana/sigil-sdk@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@3cfc596f2d3ca631ce9fa8fe3107d71c17caf924 -
Trigger Event:
workflow_dispatch
-
Statement type: