LiteLLM spend log retention and prompt storage: what it controls and when you need it
A shared self-hosted LiteLLM gateway writes a spend record for every request to PostgreSQL, and whether that record also holds the prompt and response text is a setting you control. The two controls that decide this are store_prompts_in_spend_logs, which turns prompt and response storage on or off, and maximum_spend_logs_retention_period, which sets how long spend records are kept. Before a compliance or security team signs off, you need to know which of these is set, what it is set to, and who can change it.
store_prompts_in_spend_logs controls whether request and response content is written into the spend log entries at all. When it is off, spend logs still record the metadata needed for cost tracking, such as the key, team, model and token counts, but not the text. When it is on, every prompt and completion passes into LiteLLM_SpendLogs, so the table becomes a store of personal data wherever users type personal data into a prompt. The Admin UI can change this setting and the retention period without a restart, and values set in the UI take precedence over the config file. That means the effective value can differ from what your deployment repository says, so check the live setting in the UI and record who changed it. (Illustrative: a team that turned storage on while debugging may not remember to turn it off.)
The LiteLLM_SpendLogs table grows with request volume, whether or not prompt text is stored, because each request adds a row. LiteLLM's upgrade guide gives a rough planning figure of about 3 billion rows a year at 100 requests per second, and it recommends setting a retention period and, at high volume, partitioning the table. Storing prompts makes each row much larger and extends the privacy exposure to every row still in the table. Confirm your expected request rate and peak load, then choose a retention period that matches your business need and your privacy commitments, and confirm the cleanup job runs on schedule in your environment.
Configuration options for spend log storage and retention
This table compares the settings that decide whether prompts and responses are written to spend logs, how long rows are kept, and how cleanup runs. Read each row against your privacy position and the size of the LiteLLM_SpendLogs table you expect to run. The main takeaway is that prompt storage and retention should be decided together, because a retention period limits how long any stored content remains.
| Setting | What it controls | When it fits | Privacy or operational trade-off |
|---|---|---|---|
| store_prompts_in_spend_logs off | Request and response content is not written to spend logs; cost and usage metadata still is | Default choice when prompts may contain personal data and teams do not need transcripts in the database | Investigating a disputed answer or debugging output requires another source, such as application logs, so confirm that path exists first |
| store_prompts_in_spend_logs on | Full request and response content is stored in spend log rows | Teams that need transcripts for internal review, with a documented access model and a retention period | Every stored prompt becomes personal data exposure in PostgreSQL and in any backup or export, so access and retention must be set before enabling |
| maximum_spend_logs_retention_period | Age limit in general_settings after which spend log rows become eligible for deletion | Any deployment, whether or not prompts are stored, since it bounds table growth | Shorter periods reduce privacy exposure but remove spend history that finance or chargeback may need; agree the period with finance and legal |
| Cleanup interval | How often the proxy runs the deletion job against spend logs | Deployments where a steady, small cleanup load is preferred over occasional large deletes | Frequent runs spread database work; infrequent runs leave expired rows in place longer, so confirm the interval against your privacy commitment |
| Cron schedule | Fixed times when cleanup runs, set with a cron expression | Teams that want cleanup outside business hours or outside peak gateway traffic | A schedule that is misconfigured or paused lets the table grow silently, so add a check that confirms the job ran |
| Batch limits | Maximum rows removed per cleanup run | Large tables where unbounded deletes would lock or slow the database | Small batches keep the database responsive but take longer to clear a backlog; monitor table size after the first runs |
| Admin UI setting | Changes store_prompts_in_spend_logs and the retention period without a restart; UI values take precedence over the config file | Operators who need to change behavior quickly during an incident or policy change | Values set in the UI can differ from the config file under version control, so record UI changes and review them against the file regularly |
Setting retention and cleanup on a self-hosted gateway
This sequence moves a self-hosted LiteLLM gateway from default spend logging to a documented prompt storage policy, a bounded retention period and a cleanup schedule, with checks that prove old rows are removed and that the UI and config agree.
Confirm PostgreSQL as the backing store
The platform engineer confirms the proxy writes spend logs to PostgreSQL, the database LiteLLM names as its primary supported option, and that the proxy can connect to it with the expected credentials. Spend log cleanup depends on this database, so a proxy running without it has no retention to configure. Done when a test request produces a row in the LiteLLM_SpendLogs table and the platform team can query that table directly. Confirm the database sizing and backup approach with your database owner before the table begins to grow.
Decide the prompt storage policy
The security, privacy and platform owners agree in writing whether request and response content may be stored in spend logs at all. The decision controls the store_prompts_in_spend_logs setting, which determines whether content is written. Record the purpose, the teams allowed to read the table, and who approves changes. Done when the signed decision names the setting value for each environment. If the answer is no, the later retention settings still apply to the metadata rows that remain.
Set the retention period and cleanup schedule
The platform engineer adds maximum_spend_logs_retention_period under general_settings in the proxy configuration, along with the cleanup interval, cron schedule and batch limits the retention documentation describes. Choose values that match the retention period in the decision from the previous step, and confirm the exact key names against the current retention page before deploying. Retention and cleanup are open source features and do not need an Enterprise license. Done when the config file is committed to version control and the proxy starts without configuration errors.
Add Redis only for distributed locking
The platform engineer decides whether more than one proxy instance will run cleanup. Redis is needed only when several instances must coordinate through distributed locking so that cleanup does not run twice at once. A single-instance deployment can skip Redis for this feature. If Redis is added, confirm it meets the version requirement in the production guide, which is Redis 7.0 or newer for multi-instance use. Done when the team can name the instance count and whether cleanup locks are in use.
Apply and check the UI settings
The admin changes the prompt storage and retention values in the Admin UI only if the team has decided that UI-managed values are acceptable. The UI values take precedence over the config file and can change without a restart, so the team must record which source is authoritative. Compare the UI values with the committed config and resolve any difference. Done when the UI and config show the same retention period and storage setting, and the change log records who made each change.
Verify old rows are removed
The platform engineer creates test requests with a known timestamp, or waits for existing rows to pass the configured age in a non-production environment, then checks the LiteLLM_SpendLogs table after a scheduled cleanup run. Confirm that rows older than the retention period are gone and that recent rows remain. Check the proxy logs for cleanup messages and errors. Done when a dated query shows no rows past the retention boundary and the cleanup run is visible in logs.
Plan growth and table partitioning
The platform team reviews the upgrade guide's estimate that the spend log table gains roughly 3 billion rows a year at 100 requests per second, and compares that with its own request volume. If retention alone does not keep the table within the database capacity your team has sized, plan table partitioning with the database owner before volume grows. Done when the team has a written table size forecast for its traffic, a named owner for partition decisions, and a dated review point in its operations calendar.
Prompts reach the spend log only when the flag and retention allow it
The diagram starts with a caller sending a request to the LiteLLM proxy, which forwards it to the model provider. After the call, the proxy writes a spend log row to PostgreSQL. The store_prompts_in_spend_logs setting decides whether that row includes prompt and response content. Inside the database boundary, a scheduled cleanup job deletes rows older than the retention period. The Admin UI can change both settings at runtime, and its values take precedence over the config file, so check who can open that screen.
Prompt content reaches the database only when the flag allows it.
Privacy and security risks of storing prompts in spend logs
Storing prompts and responses in spend logs turns the gateway database into a store of personal and confidential data. The risks below share one root cause: content kept longer, in more places, and read by more people than the original request required. Each card names the exposure and the check that keeps it bounded.
Personal data outliving its purpose
When store_prompts_in_spend_logs is enabled, user messages that contain names, account numbers or health details are written to the LiteLLM_SpendLogs table. The data may be needed for a short support window, but the table keeps it until a retention rule removes it. Set maximum_spend_logs_retention_period to a period your privacy notice and data retention schedule actually support, and confirm with your privacy team which purpose the stored content serves.
- Rows a year at 100 RPS
- 3 billion
Backups holding deleted prompts
Deleting spend log rows does not remove them from database backups or replicas taken earlier. A prompt removed in production can still exist in a point-in-time recovery archive for as long as your backup retention runs. Ask your database team how long backups and standby copies keep the table, and decide whether that window is acceptable for prompt content or whether prompts should not be stored at all.
Broad read access to the spend log table
Anyone who can query LiteLLM_SpendLogs directly can read every stored prompt, regardless of which team or key produced it. Database administrators, analysts and reporting tools that only need token counts or cost can end up with content access by default. Restrict table grants to the roles that need them, and create a separate reporting view that omits the request and response columns.
Exports and chargeback queries exposing content
Spend data is often exported to spreadsheets, finance tools or data warehouses for chargeback and FinOps reporting. An export that selects all columns copies prompt text into systems with weaker access controls and their own retention. Define the approved export query in writing, exclude content fields by default, and review any new report that joins against the spend log table before it runs on a schedule.
Cleanup failures that go unnoticed
Retention only works if the scheduled cleanup job runs. A failed cron entry, a lock held by a stalled instance, or a missing database permission can leave the table growing while the configuration still reads as compliant. Confirm the cleanup interval and schedule in your deployment, alert on the table size and row age, and check the logs of the proxy instance that runs cleanup after each change.
Choosing a retention period that matches your privacy obligations
The retention period is a business and legal decision, not a technical default. LiteLLM will keep spend logs for whatever period you configure, and the documentation's retention and cleanup controls only enforce a number your organization has already chosen. Before you set maximum_spend_logs_retention_period, agree the period in writing with your privacy office, legal counsel and security owner. Ask them which obligations apply to prompts that may contain personal data, how long finance needs billing records, and whether any litigation hold or regulator request could require longer storage. DeployOpen does not set your legal retention period, and the figure you record should come from those owners, not from the gateway's defaults.
The most useful decision is to separate the two kinds of data the spend log holds. Billing data, such as the key or team that made a call, the model, token counts, cost and timestamp, is usually what chargeback and budget reporting need. Prompt and response content, which store_prompts_in_spend_logs controls, is the part that carries personal data and the larger privacy exposure. Many organizations keep billing fields for the finance period and keep content for a shorter window, or do not store content at all. Ask finance which fields they need and ask the privacy owner whether content storage is justified. Confirm in your own test environment exactly which fields are written with the setting on and off before you promise either outcome.
Once the period is agreed, record it alongside the cleanup schedule and the owner who approved it, and review it when your obligations change. The Admin UI can change both the content setting and the retention period without a restart, with UI values taking precedence over the config file, so make the approved value the one that holds in both places. For the privacy side of how these logs support obligations, the LiteLLM compliance material is the natural next read, though you should check the wording of each obligation against your own counsel's advice.
Limits to confirm in your environment
Retention settings look simple in a config file, but their effect depends on your LiteLLM version, your database topology and your backup policy. The cards below list the behaviors to verify in a test environment before you set a retention period or a cleanup schedule in production.
Cleanup behavior on your version
Confirm exactly how the retention cleanup runs on the LiteLLM release you deploy, including what it deletes, when it runs and what it logs on each pass. Cleanup behavior can change between releases, and the release line you run should match the one you test against. Run the cleanup on a copy of your spend log table and check row counts before and after.
Retention docsDeleted rows in backups and replicas
Deleting rows from LiteLLM_SpendLogs removes them from the live database only. Confirm whether copies persist in point-in-time recovery archives, nightly dumps and read replicas, and for how long. Your privacy commitment on deletion is only as strong as the slowest backup retention window, so align both with your data handling policy.
Batch limit effects on large tables
Confirm how the configured batch limits affect a table that has accumulated many rows before cleanup is first enabled. A small batch size can leave a backlog that keeps the table large for days, while a large batch can lock rows and slow proxy writes. Test the first cleanup run on a production-sized copy and watch database load and proxy latency.
Partitioning at high volume
The upgrade guide estimates roughly 3 billion new rows a year at 100 requests per second and recommends a retention period and, at high volume, table partitioning. Confirm your expected request rate, measure row growth over a week, and decide with your database team whether partitioning by time is needed before the table becomes hard to vacuum and back up.
Upgrade guideAdmin UI overrides during upgrades
The Admin UI values for prompt storage and retention take precedence over the config file. Before an upgrade, record the effective values in the UI and in config.yaml, then confirm which source wins after the new release starts. A mismatch can silently re-enable prompt storage or change the retention window, so test this on staging with the same database.
Multi-instance locking
Redis is needed for distributed locking only when more than one proxy instance runs cleanup. Confirm which instances run the scheduled job, how the lock behaves if a node fails mid-run, and whether a missed schedule is retried. Test this with two proxy instances and a forced restart during a cleanup pass.
Questions buyers ask about spend log retention
Does spend log retention require an Enterprise license?
No. The LiteLLM docs state that spend log retention and cleanup are open source and need no Enterprise license. The retention setting, maximum_spend_logs_retention_period, sits in general_settings, alongside optional cleanup interval, cron schedule and batch limits. Enterprise licensing matters for other features, such as SSO beyond the free user limit or audit logs, so check the LiteLLM Enterprise documentation against the controls you actually need before you assume the edition question is settled.
Should we store prompts and responses in spend logs at all?
Decide this before you set retention, because it determines how much personal data lands in the database. The store_prompts_in_spend_logs setting controls whether request and response content is written to spend logs. If you leave it off, the table holds usage and cost metadata rather than message text. If you turn it on, your privacy review needs to cover every row for the full retention period. The setting can also be changed from the Admin UI without a restart, and UI values take precedence over the config file, so confirm which source is active in your environment.
What drives the cost and effort of setting up retention?
Most of the effort is in the decisions, not the configuration. Retention needs PostgreSQL, and Redis is only required when several proxy instances need distributed locking for cleanup. The main cost drivers are the number of requests you serve, whether prompt storage is on, the retention period your legal and privacy teams agree to, and how much testing you do against a copy of production data. Who pays for what depends on whether your team or a partner does the work. Ask any quote to split the decision workshop, configuration, testing and handover into separate line items.
How long does the work take and what does it depend on?
The duration depends on how quickly your organization decides the retention period and whether prompt storage stays on, rather than on the configuration itself. Other factors include the state of your PostgreSQL environment, access to a staging database for testing deletes, and whether your change process requires approval for scheduled jobs that remove data. No duration is given here because none is supplied for this topic. Ask for a timeline that lists the decisions it assumes, and treat any estimate that skips the retention decision as incomplete.
What does our team need to provide?
You need to provide a named owner for the retention decision, the privacy or legal position on how long prompts may be kept, and read access to the current LiteLLM configuration and database sizing. You also need a PostgreSQL environment where cleanup can be tested safely, plus a way to restore data if a delete runs with the wrong period. If you run several proxy instances, you need Redis for distributed locking. Confirm with your database team who may approve schema or scheduling changes in production.
Can our own team set up spend log retention without a partner?
Yes, if your team already runs PostgreSQL and LiteLLM and can test changes before production. The configuration itself is short, and retention is open source. The harder part is validating that the chosen period, cron schedule and batch limits remove the right rows without locking the table during business hours. A partner adds the most value where the privacy decision is contested, several environments must match, or the team lacks time to rehearse deletes. DeployOpen implements and documents these controls inside your infrastructure under a written scope.
How do partitioning and a larger database change the effort?
The LiteLLM upgrade guide says the LiteLLM_SpendLogs table gains roughly 3 billion rows a year at 100 requests per second. At that volume, the guide recommends a retention period and, at high volume, table partitioning. Partitioning adds design and migration work, including choosing the partition key, planning how existing rows move, and changing how cleanup runs. A larger database also raises backup size and restore time, so include those in the scope. Ask for the expected request rate and row counts before agreeing on an approach.
How DeployOpen scopes and delivers spend log retention work
DeployOpen scopes spend log retention as a fixed-scope engagement, and the written scope comes before any configuration change. The agreement names which data the gateway stores in LiteLLM_SpendLogs, whether store_prompts_in_spend_logs is enabled, the retention period set through maximum_spend_logs_retention_period, the cleanup schedule and batch limits, and who owns each decision. Because the settings can also be changed from the Admin UI without a restart, the scope also records who may edit them there and how UI values are reconciled with the config file, since UI values take precedence. The deliverables are agreed in the same document, so the client knows exactly what it will receive before work starts. A quote follows from that scope.
Delivery has two parts that the compliance team can check independently. First, DeployOpen verifies that cleanup actually runs: it confirms the cron schedule fires, that old rows are removed in the agreed batches, and that the table size stabilizes instead of growing without bound. Second, it documents the evidence: the configuration as deployed, test results from a cleanup run, and a record of who changed which setting and when. DeployOpen prepares this evidence for your privacy and security reviewers, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those determinations, so confirm with your assessor in advance which artifacts they will accept.
Ongoing support is available as a retainer for the period after handover, covering schedule changes, PostgreSQL growth reviews, and re-verification after LiteLLM upgrades. Ask any provider to state in the quote which items recur, how changes to the retention period are approved, and what is included in each review.

