Implementation:BerriAI Litellm Literal AI Logger
| Attribute | Value |
|---|---|
| Sources | litellm/integrations/literal_ai.py
|
| Domains | Logging, Observability, LLM Monitoring, Integrations |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
The LiteralAILogger is a batch logging integration that sends LLM step data to the Literal AI observability platform via its GraphQL API.
Description
LiteralAILogger extends CustomBatchLogger to collect LLM call metadata -- including messages, token counts, model parameters, thread and parent IDs, prompt management data, and timing -- and sends them as GraphQL ingestStep mutations to the Literal AI API. It supports both sync and async logging, batched GraphQL operations (multiple steps per mutation), configurable batch sizes, and integration with Literal AI's threading and prompt tracking features.
Usage
Import and register LiteralAILogger when you need to send LLM call traces to Literal AI. Requires a LITERAL_API_KEY environment variable or passing the key directly to the constructor.
Code Reference
Source Location
litellm/integrations/literal_ai.py
Signature
class LiteralAILogger(CustomBatchLogger):
def __init__(
self,
literalai_api_key=None,
literalai_api_url="https://cloud.getliteral.ai",
env=None,
**kwargs,
)
Import
from litellm.integrations.literal_ai import LiteralAILogger
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
literalai_api_key |
str |
No | API key. Falls back to LITERAL_API_KEY env var.
|
literalai_api_url |
str |
No | API base URL. Defaults to "https://cloud.getliteral.ai". Overridden by LITERAL_API_URL env var.
|
env |
str |
No | Optional environment header value sent as x-env.
|
kwargs |
dict |
No | Additional arguments passed to CustomBatchLogger.
|
Key Methods
| Method | Returns | Description |
|---|---|---|
log_success_event(kwargs, response_obj, start_time, end_time) |
None |
Sync success logging. Queues data and flushes when batch size is reached. |
log_failure_event(kwargs, response_obj, start_time, end_time) |
None |
Sync failure logging. |
async_log_success_event(kwargs, response_obj, start_time, end_time) |
None |
Async success logging. |
async_log_failure_event(kwargs, response_obj, start_time, end_time) |
None |
Async failure logging. |
async_send_batch() |
None |
Sends accumulated steps as a batched GraphQL mutation. |
Outputs
| Output | Type | Description |
|---|---|---|
| Side effect | HTTP POST (GraphQL) | Posts batched ingestStep mutations to {api_url}/api/graphql.
|
Usage Examples
import litellm
# Register the callback
litellm.success_callback = ["literalai"]
response = litellm.completion(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
metadata={
"literalai_thread_id": "thread-abc-123",
"literalai_parent_id": "parent-step-id",
"literalai_tags": ["production", "v2"],
},
)
# Direct instantiation
from litellm.integrations.literal_ai import LiteralAILogger
logger = LiteralAILogger(
literalai_api_key="my-api-key",
literalai_api_url="https://cloud.getliteral.ai",
env="production",
)
Related Pages
- BerriAI_Litellm_Argilla_Logger - another batch logging integration
- BerriAI_Litellm_Braintrust_Logger - another observability integration
- BerriAI_Litellm_MLflow_Logger - another tracing integration