Implementation:BerriAI Litellm S3 Logger
| Attribute | Value |
|---|---|
| Sources | litellm/integrations/s3.py
|
| Domains | Logging, AWS S3, Integrations, Observability |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
S3Logger is a logging integration that writes LiteLLM request/response events as JSON objects to an Amazon S3 bucket for persistent observability and audit trails.
Description
The S3Logger class provides both synchronous and asynchronous logging of LiteLLM completion events to AWS S3. On initialization, it creates a boto3 S3 client using either constructor parameters or values from litellm.s3_callback_params (which supports environment variable references via os.environ/ prefix). Each event is serialized as a StandardLoggingPayload JSON object and uploaded to the configured S3 bucket with a date-based key structure. The class supports optional team-based path prefixes (when s3_use_team_prefix is enabled) and custom S3 paths. A standalone helper function get_s3_object_key constructs the S3 object key from the path, prefix, start time, and file name.
Usage
Import and instantiate S3Logger when you want to log LiteLLM API call events to S3 for auditing, cost tracking, or analytics. Configure it via litellm.s3_callback_params or pass S3 credentials directly.
Code Reference
Source Location
Signature
class S3Logger:
def __init__(self, s3_bucket_name=None, s3_path=None, s3_region_name=None, s3_api_version=None,
s3_use_ssl=True, s3_verify=None, s3_endpoint_url=None, s3_aws_access_key_id=None,
s3_aws_secret_access_key=None, s3_aws_session_token=None, s3_config=None, **kwargs)
async def _async_log_event(self, kwargs, response_obj, start_time, end_time, print_verbose)
def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose)
def get_s3_object_key(s3_path: str, prefix: str, start_time: datetime, s3_file_name: str) -> str
Import
from litellm.integrations.s3 import S3Logger
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
s3_bucket_name |
str |
Name of the S3 bucket to log events to. |
s3_path |
Optional[str] |
Optional path prefix within the bucket. |
s3_region_name |
Optional[str] |
AWS region name for the S3 client. |
s3_endpoint_url |
Optional[str] |
Custom endpoint URL (for S3-compatible services). |
s3_aws_access_key_id |
Optional[str] |
AWS access key ID. |
s3_aws_secret_access_key |
Optional[str] |
AWS secret access key. |
kwargs |
dict |
The LiteLLM call kwargs containing standard_logging_object, litellm_params, etc.
|
response_obj |
Any |
The completion response object. |
start_time |
datetime |
Start time of the API call. |
end_time |
datetime |
End time of the API call. |
Outputs
| Method | Return Type | Description |
|---|---|---|
log_event |
S3 put_object response | The boto3 S3 put_object response dictionary, or None on failure.
|
get_s3_object_key |
str |
The constructed S3 object key path for the log file. |
Usage Examples
import litellm
# Configure S3 logging via litellm params
litellm.s3_callback_params = {
"s3_bucket_name": "my-litellm-logs",
"s3_region_name": "us-east-1",
"s3_aws_access_key_id": "os.environ/AWS_ACCESS_KEY_ID",
"s3_aws_secret_access_key": "os.environ/AWS_SECRET_ACCESS_KEY",
"s3_path": "litellm-logs/",
}
# Add s3 as a success callback
litellm.success_callback = ["s3"]
Related Pages
- BerriAI_Litellm_S3_Cache - S3-based cache implementation for LiteLLM
- BerriAI_Litellm_Supabase_Logger - Alternative database-based logging integration
- BerriAI_Litellm_Weights_Biases_Logger - Weights & Biases logging integration