LiteLLM spend log retention starts with one decision: store prompts or not
Whether a self-hosted LiteLLM gateway stores request and response content in its spend logs is the first decision, and it controls both privacy exposure and how fast the spend log table grows. The gateway writes a spend record for each call to PostgreSQL. With store_prompts_in_spend_logs enabled, those records also carry prompt and response text, so every retained row may hold personal data. With the setting disabled, the table holds usage, cost and identifiers, which is less sensitive but still needs a retention period. Teams need retention at any volume, and the need is most pressing when prompts may contain personal data about customers, employees or patients.
Retention is configured with maximum_spend_logs_retention_period in general_settings. Optional settings control the cleanup interval, a cron schedule and batch limits. According to LiteLLM's documentation, retention and cleanup are open source features, so they need no Enterprise license. Cleanup requires PostgreSQL. Redis is needed only when more than one proxy instance must coordinate through distributed locking. Before you plan the Redis dependency, confirm with your own deployment design how many proxy instances will run and where they will sit, because that answer determines whether the cleanup job needs shared locking at all.
Treat this as a governance decision for security and privacy owners, with the platform team implementing it. Privacy owners should decide whether prompts are stored at all, which teams or keys may store them, how long records persist, and who can read the table through the database or the admin UI. Ask which categories of personal data reach the gateway, which data subjects they describe, and whether the retention period matches what your privacy notices and internal retention schedule promise. Record the decision, its owner and the review date in your governance documentation so the setting does not drift from the policy it is meant to enforce.
The admin UI can change store_prompts_in_spend_logs and the retention period without a restart, and values set in the UI take precedence over the config file. A file that says one thing may not describe the running gateway. Decide who may change these settings in the UI, keep the config file as the reviewed baseline, and check the effective values after any change. A practical check is to compare the UI values with the config file on a schedule and to confirm in the database that newly written rows match the stated policy.
Set the retention period before go-live, not after the table has grown. LiteLLM's upgrade guide says the LiteLLM_SpendLogs table gains roughly 3 billion rows a year at 100 requests per second, and it recommends a retention period and, at high volume, table partitioning. Treat that figure as a reference point and size storage, backups and query performance against your own request rate and peak traffic. Ask your database team to plan partitioning and to confirm how cleanup jobs interact with backups, since deleting old rows does not shrink storage until the database reclaims the space.
Which spend log settings fit which risk
This table compares the settings that decide whether prompts are stored, how long spend log rows are kept, and how cleanup runs. Read each row for what the setting changes, which risk it fits, and what it costs in privacy exposure or debugging value. Confirm default values in your LiteLLM version before setting anything, and treat Admin UI changes as production configuration changes because they override the config file without a restart.
| Setting | When it fits | Trade-off | Who may change it and how |
|---|---|---|---|
| store_prompts_in_spend_logs: stores request and response content in spend logs | Metadata only when prompts may contain personal or confidential data | Content is unavailable for debugging or dispute review after the fact | Config owner or Admin UI user. Confirm in your version whether UI changes are logged elsewhere |
| maximum_spend_logs_retention_period: how long spend log rows are kept | Short retention for debugging windows, longer only with a documented purpose | Short periods lose billing history; long periods grow the table and widen exposure | Platform owner via config. Admin UI can override, so approve changes in your change process |
| Cleanup interval (optional): how often the cleanup job runs | Any deployment with a retention period, so deletion happens on schedule | Frequent runs add database load; infrequent runs let the table grow between runs | Platform owner via config. Test the chosen interval in a non-production database first |
| Cron schedule: when cleanup runs | An off-peak window that matches your traffic pattern | Cleanup overlapping peak traffic can compete with request logging for database resources | Platform owner via config. Record the schedule in your runbook and monitoring |
| Batch limits: how many rows each cleanup pass deletes | Large spend log tables where a single delete would be too heavy | Small batches clear data slowly; large batches increase lock time and load | Platform owner via config. Confirm the parameter names and limits in your LiteLLM version |
| Admin UI spend log settings: UI values override the config file without restart | Teams that need a quick, audited change to prompt storage or retention | Silent drift from the config file; the UI value wins until someone reconciles it | Restrict to named admins. Record each change in a ticket and sync it back to config |
| Prompt storage on with long retention | Only where a data owner documents the purpose, lawful basis and access rules | Stored prompts with personal data expand privacy exposure and breach impact | Data owner sign-off required before enabling. Review the decision at each retention review |
How to configure LiteLLM spend log retention step by step
This sequence sets whether prompts and responses are stored in spend logs, caps how long rows are kept, and proves that the cleanup job runs and that content stays out of storage when it should.
Confirm PostgreSQL and record the prompt storage decision
Confirm the proxy uses PostgreSQL as its database, since spend log cleanup requires it, and that the LiteLLM_SpendLogs table is where spend records land. Then agree with the privacy owner whether request and response content may be stored at all, and record the decision, the legal basis or internal rule behind it, and who approved it. Done when the signed decision exists and the database check passes in your environment. Ask LiteLLM or your own platform team to confirm any version-specific table behavior before go-live.
Set prompt storage and retention in general settings
Edit the proxy configuration so general_settings contains store_prompts_in_spend_logs with the value your privacy owner approved, and maximum_spend_logs_retention_period with the retention window your policy sets. Keep the values in your configuration repository so they are reviewed like other code. Restart or redeploy the proxy, then confirm the running instance reports the same values. Done when a test request produces a spend log row whose content field matches the decision.
Configure cleanup interval, schedule and batch limits
Set the optional cleanup interval, cron schedule and batch limits in the same configuration so deletion runs in a window your database team accepts, away from peak traffic. Small batches keep locks short on a large table, while a schedule that is too frequent adds load for little gain. Ask your DBA to review the chosen window and batch size against your traffic pattern. Done when the scheduled run appears in the proxy logs at the expected time and the window has been agreed in writing.
Add Redis only for distributed cleanup locking
Add Redis only if more than one proxy instance runs and the instances must coordinate so that only one performs cleanup at a time. LiteLLM's production guide requires Redis 7.0 or newer once multiple instances run, and it also uses Redis for shared rate limits, router state and cache, so the decision is broader than cleanup. A single-instance deployment can skip Redis for this feature. Done when every instance points to the same Redis endpoint and only one cleanup run appears per scheduled window in the logs.
Check the Admin UI setting against the config file
Open the Admin UI spend log settings and compare the stored prompt setting and retention period with the configuration file. LiteLLM documents that UI values take precedence over the config file and can change without a restart, so a mismatch means someone has overridden the file. Confirm that UI changes are recorded in your audit trail, and restrict who can edit these settings. Done when the UI and file values match, and a deliberate test change in the UI appears in the logs or audit export.
Verify sample rows, row counts and the cleanup output
Inspect a sample of spend log rows to confirm the content fields are populated or empty as the decision requires, then record the row count and oldest timestamp on a schedule. The count should stop growing without bound once the retention period is in effect. Review the cleanup job's log output for each run, including deleted row counts and errors. Done when rows older than the retention window disappear across at least one full scheduled cycle and the logs show the runs.
Test that content is absent when storage is off
With prompt storage switched off, send test requests containing clearly marked synthetic strings, then search the spend log table and any exported copies for those strings. The test passes only when none of the markers appear in the stored records, while token counts and spend still appear. Keep the test as a repeatable script and rerun it after each upgrade or configuration change. Done when the search returns no matches and the result is filed with the privacy owner's decision record.
How LiteLLM spend log cleanup keeps the table bounded
The cleanup job deletes spend log rows once they are older than the period set in maximum_spend_logs_retention_period under general_settings. If store_prompts_in_spend_logs is enabled, those rows can hold request and response content, so expiry also ends the stored prompt exposure for those records. Confirm with the vendor exactly which columns and related records the job removes, whether any data is kept for billing or reporting, and how the job interacts with database backups and replicas, which it does not manage. The docs state that retention and cleanup are open source and need no Enterprise license, so the decision sits with your team and your database operators.
The optional cleanup interval and cron schedule control when the job runs, and batch limits cap how many rows each pass removes. Together they spread deletes over time so the job does not hold long locks or generate a large write burst on a table that receives a write for every request. Choose the schedule with your DBA, ideally in a window with lower traffic. Then test on a copy of production-scale data and measure run duration, lock waits, replication lag and whether each run finishes before the next one starts. Do not carry values over from another environment without measuring them against your own write rate.
When more than one proxy instance runs, each instance can trigger the cleanup on its own schedule. Without coordination, instances can attempt the same deletes, contend for locks or interfere with each other's batches. The docs say Redis is needed for cleanup only when multiple instances require distributed locking. Confirm with the vendor how the lock is acquired and released, what happens if the lock holder fails partway through a batch, and how the cleanup behaves if Redis is unavailable. Also plan Redis as a dependency for this job, since the production guide already requires Redis 7.0 or newer once more than one instance runs.
The upgrade guide says the LiteLLM_SpendLogs table gains roughly 3 billion rows a year at 100 requests per second. A retention period keeps that table from growing forever, but the table still takes heavy inserts and deletes at steady state. At high volume, the guide recommends table partitioning. Partitioning is a database design decision, not a switch in the proxy configuration. Your PostgreSQL team must decide the partition key and interval, how partitions are created and dropped, how the cleanup job's delete path fits, the index strategy, backup and restore impact, and how future LiteLLM upgrades handle the partitioned table. Plan it, then test it on realistic data before go-live.
Before go-live, put specific questions to the vendor and your DBA. For the vendor: which data the cleanup removes when prompt storage is on, whether partitioned tables are supported in the release you will run, how the job behaves with multiple instances and Redis failures, and how upgrades treat the table. For the DBA: the expected row growth at your actual request rate, the partition interval, the index plan, autovacuum settings for a high-churn table, the effect of deletes on replica lag, and whether a restore from backup has been tested with the retained data. Record the answers in the design so the retention period is an agreed control, not a default.
Privacy and security exposure of stored prompts and responses
Storing prompt and response content in LiteLLM spend logs turns the gateway database into a repository of whatever users type, including personal and health data. The cards below cover where that exposure sits, who can reach it, and which configuration and secret controls you should confirm before turning storage on.
Personal and health data in plain text
When store_prompts_in_spend_logs is enabled, request and response content is written to the spend log table in the PostgreSQL database. Users may paste patient details, customer records or employee information into prompts without thinking about it. Before enabling storage, check what your users send, and confirm with LiteLLM whether any content is encrypted within the table or only protected by database-level controls.
Database administrator and reporting access
Anyone with read access to the LiteLLM_SpendLogs table can see stored prompts and responses, including database administrators, backup operators and analysts who query spend data for chargeback. Map every PostgreSQL role that can select from that table, separate spend reporting roles from content access where your database allows it, and document who can run ad hoc queries against production.
Exposure through exports and backups
Prompt content spreads beyond the live database through database dumps, replicas, snapshots, log exports and spreadsheets built from spend reports. Each copy inherits the sensitivity of the original and may sit in storage with weaker controls or longer retention. Inventory where spend log data is copied, confirm that backup encryption and access rules match production, and make sure the retention period also applies to backups you control.
Encryption at rest and database roles
Encryption at rest for the PostgreSQL volumes, backups and replicas is a control you configure in your own infrastructure, so confirm it in your environment rather than assuming it. Pair it with tightly scoped database roles that grant the LiteLLM service account only the privileges it needs and keep human accounts out of the spend log table by default.
Restricting changes to store_prompts_in_spend_logs
The store_prompts_in_spend_logs setting can be changed from the Admin UI without a restart, and UI values take precedence over the config file. That makes the Admin UI a point where anyone with admin rights can switch content capture on or off. Limit which users hold admin roles, confirm how your SSO and RBAC options map to those roles, and record who changed the setting and when.
Monitoring configuration changes and secrets
Changes to the storage flag, the retention period and the master key should trigger review, so monitor the Admin UI, the config file and the deployment pipeline for them. Keep LITELLM_MASTER_KEY and database credentials in a secret manager rather than in config files or environment files on hosts, and confirm which secret manager integrations your LiteLLM edition supports and how access to those secrets is audited.
Where prompt copies can still exist after cleanup
Deleting rows from the LiteLLM_SpendLogs table removes only the live copy of what the gateway recorded. If store_prompts_in_spend_logs was enabled at any point, prompt and response content can also sit in database backups, streaming replicas, point-in-time recovery archives, log shipping pipelines, observability tools that received the same callback data, and any logging integration the gateway forwards to. Each of these has its own schedule and its own owner, and none of them is cleared by the cleanup job. Before you rely on maximum_spend_logs_retention_period as a privacy control, list every place the data could have gone.
Build a copy inventory with one row per location. For each, record the system, the team that owns it, the data it holds (prompt text, response text, metadata only), the retention period that applies, and where that period is configured. Map the spend log window to each row. A copy should not be kept longer than the spend log policy allows unless someone has documented and approved the exception. Ask the PostgreSQL database owner for the actual backup retention, replica lag, and point-in-time recovery window. Ask the owners of each callback destination the same questions. Do not assume any of these values from the gateway settings alone.
Test the deletion path end to end in a non-production environment. Send a synthetic request containing a unique marker string with prompt storage enabled, then wait past the retention window and let the cleanup job run. Confirm the marker is gone from the live table, the replica, and each observability destination. Then restore a backup taken before the window and a point-in-time recovery to a time after the window, and search both for the marker. The time between the deletion and the point where the marker disappears from backups is the effective exposure window. Compare it with the window your policy states, and record the test date and the results.
Two settings need attention during this review. The Admin UI can change store_prompts_in_spend_logs and the retention period without a restart, and UI values take precedence over the config file, so audit both sources and the running state. Also check whether the callback payloads sent to other systems include prompt content regardless of the spend log setting. At high request volume, the spend log table grows quickly, so the cleanup batch limits also affect how large the backups become. Assign one owner for the inventory, and review it whenever the storage setting, the backup schedule, or a callback destination changes.
What to confirm before you rely on spend log retention
Spend log retention and prompt storage depend on settings that can change between LiteLLM releases and deployments. The checks below are questions to answer in your own environment before you set a retention period or a cleanup schedule, and before you tell anyone that old prompts are removed.
Field names and defaults in your version
Confirm in the spend log retention documentation for the exact release you run how maximum_spend_logs_retention_period, store_prompts_in_spend_logs and the optional cleanup settings are named and what each one defaults to. Ask whether the cleanup feature is present in your release at all. Record the answers against the version number, because a copied config from another release may silently use different names or defaults.
Interval, cron and batch limits together
Ask how the cleanup interval, the cron schedule and the batch limits interact when all three are set. Confirm which one takes precedence, how long one cleanup run can take on your table, and whether a run that is still going when the next one is due will overlap or wait. Also confirm what happens to rows that a batch limit leaves behind, so the table keeps shrinking rather than stalling.
Admin UI changes across restarts
The Admin UI can change store_prompts_in_spend_logs and the retention period, and UI values take precedence over the config file. Confirm in your deployment that a UI change survives a proxy restart, a pod rescheduling and a redeploy from your configuration repository. If it does not persist, a restart could quietly restore prompt storage or a longer retention period that your privacy review rejected.
Cleanup during upgrades and migrations
Ask how cleanup behaves while the proxy is upgraded and while database migrations run against the LiteLLM_SpendLogs table. Confirm whether a scheduled run can start during a migration, whether it can lock the table, and whether a rollback restores the previous schedule. The upgrade guide recommends a retention period and, at high volume, table partitioning, so confirm which of those your release and your database team support together.
Test cleanup on production-sized data
Run the retention job against a copy of production-sized spend log data before you enable it in production. Measure how long a run takes, how much write and lock contention it creates, and how much disk space is freed and when. The upgrade guide estimates roughly 3 billion rows a year at 100 requests per second, so a test on a small table will not show how the job behaves at your volume.
Release line and PostgreSQL support
Check the LiteLLM releases page for the latest release line before you set a schedule, because the most recent release at the time you read this may differ from the one you deploy. Confirm in the release notes which PostgreSQL versions your release supports, and confirm that the release is still within the four most recent stable minor versions that LiteLLM maintains. Redis is needed for distributed locking only when more than one proxy instance runs.
What LiteLLM spend log retention costs and what it needs from your team
How much effort does spend log retention take compared with the rest of the work?
Most of the effort sits in the privacy decision and in testing the cleanup job, not in the settings themselves. The decision comes first: whether prompts and responses should be stored in spend logs at all, which is controlled by store_prompts_in_spend_logs. Configuring maximum_spend_logs_retention_period, the cleanup interval, the cron schedule and batch limits is often the smallest part. Testing against a staging copy confirms that deletion removes what it should and that database load stays acceptable. Monitoring is recurring: someone must confirm that the table size and the cleanup job stay on track. A written scope should show each of these four parts separately so you can see where the effort goes.
What drives the cost of spend log retention work up?
The main drivers are the volume of requests, the number of proxy instances, whether the table needs partitioning, how much backup scope must change, and how many people must approve and review the result. LiteLLM's upgrade guide states that the LiteLLM_SpendLogs table gains roughly 3 billion rows a year at 100 requests per second, so higher traffic makes the cleanup job and any partitioning work larger. Multiple instances that need distributed locking require Redis 7.0 or newer. Backup scope matters because retention deletes data that your backups may still hold. Stakeholders and audit evidence add review time. Ask for the quote to list each driver as a separate line, and to mark which items are one-time and which recur.
Does LiteLLM spend log retention need an Enterprise license?
No. LiteLLM's docs state that spend log retention and cleanup are open source and need no Enterprise license. Setting maximum_spend_logs_retention_period in general_settings, along with the optional cleanup interval, cron schedule and batch limits, works on the open source release. The LICENSE file in the BerriAI/litellm repository states that code outside the enterprise/ directory uses the MIT license, while content under enterprise/ uses the license in that directory. Other capabilities you may need, such as SSO beyond the free user limit, audit logs or team-level logging controls, fall under Enterprise terms. Confirm the license position for each feature in your plan with LiteLLM before you commit to a design.
What does your team need to provide before spend log retention work starts?
Expect to provide five things. First, database access to the PostgreSQL instance that holds LiteLLM_SpendLogs, because PostgreSQL is required for spend log cleanup. Second, a named privacy owner who signs off on whether prompts and responses are stored and for how long. Third, a staging copy of the data so the cleanup job can be tested without touching production records. Fourth, Redis access if more than one proxy instance runs, since distributed locking depends on it. Fifth, change control for the Admin UI setting, because store_prompts_in_spend_logs and the retention period can be changed there without a restart and UI values take precedence over the config file. Agree on who may change these values and how changes are recorded.
Can an internal platform team set up spend log retention without outside help?
Yes, a team comfortable with PostgreSQL and LiteLLM configuration can usually set the retention period and cleanup schedule alone. The configuration keys are documented and the cleanup needs only PostgreSQL, plus Redis for multiple instances. The harder parts are partitioning, which changes how the table is laid out and may require a careful migration of existing rows, and producing evidence that satisfies an internal audit or external assessment. DeployOpen can prepare systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications, and independent auditors make that determination. Many teams configure the feature internally and bring in outside help for partitioning and the evidence pack.
How long does spend log retention work take to complete?
Duration depends on scope and environment, and the written scope sets it out for each engagement. The main factors are the current size of the spend log table, the number of proxy instances, whether partitioning is needed, how many databases and backups are affected, and how long privacy and change approvals take inside your organization. A single-instance setup with a short approval path differs from a multi-instance deployment that needs partitioning and formal evidence. Ask for a timeline that separates the privacy decision, configuration, testing and the first monitoring period, and that names the client tasks each stage depends on.
What happens to spend logs if we skip retention entirely?
The table keeps growing, and any prompts and responses stored in it stay in the database for as long as the table exists. LiteLLM's upgrade guide states that the LiteLLM_SpendLogs table gains roughly 3 billion rows a year at 100 requests per second, and it recommends setting a retention period and, at high volume, partitioning the table. Growth affects query speed, backup size and restore time, and the privacy exposure grows with the data held. If prompts are not stored, the table still grows with request metadata, so retention remains useful. Review the retention decision with your privacy owner before you decide the period.
How DeployOpen scopes and delivers LiteLLM spend log retention
DeployOpen starts with a decision on whether prompts and responses should be stored in spend logs at all, then sets a retention period and cleanup schedule that match your privacy obligations. The work runs inside your own infrastructure, on a fixed scope agreed in writing before any configuration changes are made.
How we scope
- Record the decision on whether store_prompts_in_spend_logs stays off or is enabled for specific use cases.
- Agree the retention period, cleanup interval and batch limits against your data handling rules.
- Confirm the PostgreSQL database and whether Redis is needed for distributed locking across proxy instances.
- Write the scope, deliverables and timeline in a fixed-scope agreement before work starts.
How we build
- Set maximum_spend_logs_retention_period and the cleanup schedule in the proxy configuration.
- Test cleanup against a copy of the LiteLLM_SpendLogs table to confirm deletes and locking behave as expected.
- Review whether Admin UI changes to prompt storage and retention will be locked down or left to administrators.
- Plan table partitioning for the spend log table if your expected request volume is high.
How we hand over
- Document the retention setting, the decision record and who approved each stored data category.
- Provide a runbook for checking table growth, running cleanup jobs and handling a failed cleanup.
- Walk your operations and privacy teams through how to change retention and prompt storage safely.
- Hand over configuration files and test evidence so your auditors can trace the settings.
How we support
- Ongoing support, upgrades and monitoring of the spend log table are available as a retainer.
- Review retention settings again when you upgrade LiteLLM or change the volume of requests.
- Confirm cleanup still runs after database migrations, version changes and infrastructure moves.
- Ask for a quote based on the written scope, which covers your environment and team size.

