Skip to main content

Cache Controls

Once caching is on it applies to every supported call type. This page covers narrowing that: per request with a cache object in the body, per virtual key with key metadata, and proxy-wide with cache_params.

Dynamic Cache Controls​

ParameterTypeDescription
ttlOptional(int)Will cache the response for the user-defined amount of time (in seconds)
s-maxageOptional(int)Will only accept cached responses that are within user-defined range (in seconds)
no-cacheOptional(bool)Will not store the response in cache.
no-storeOptional(bool)Will not cache the response
namespaceOptional(str)Will cache the response under a user-defined namespace

Each cache parameter can be controlled on a per-request basis. Here are examples for each parameter:

ttl​

Set how long (in seconds) to cache a response.

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_body={
"cache": {
"ttl": 300 # Cache response for 5 minutes
}
}
)

s-maxage​

Only accept cached responses that are within the specified age (in seconds).

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_body={
"cache": {
"s-maxage": 600 # Only use cache if less than 10 minutes old
}
}
)

no-cache​

Force a fresh response, bypassing the cache.

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_body={
"cache": {
"no-cache": True # Skip cache check, get fresh response
}
}
)

no-store​

Will not store the response in cache.

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_body={
"cache": {
"no-store": True # Don't cache this response
}
}
)

namespace​

Store the response under a specific cache namespace.

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_body={
"cache": {
"namespace": "my-custom-namespace" # Store in custom namespace
}
}
)

Cache-Control request header​

Clients that cannot add a cache field to the body can send the standard HTTP Cache-Control request header instead. Since v1.112.0 The proxy reads no-cache and no-store from it and applies them like the body controls above.

from openai import OpenAI

client = OpenAI(
api_key="your-api-key",
base_url="http://0.0.0.0:4000"
)

chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Hello"}],
model="gpt-6-luna",
extra_headers={"Cache-Control": "no-cache"} # Skip the cached response for this request
)

Only no-cache and no-store are read from the header, and other directives such as max-age and s-maxage are ignored. A value in the body's cache field wins over the header. When a virtual key sets allowed_cache_controls, a header directive outside that list is ignored instead of rejected. Cache controls in a key's metadata, described below, take precedence over the header the same way they do over the body.

Some HTTP clients send Cache-Control: no-cache on every request by default (Postman does), so their requests skip the cache.

Per-key cache controls​

Set the cache field in a virtual key's metadata and the proxy applies it to every request made with that key, so clients need no changes. This is the usual way to keep one class of traffic out of the cache while leaving it on everywhere else.

curl http://localhost:4000/key/generate \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"metadata": {"cache": {"no-cache": true}}
}'

Supported key-level cache controls: ttl, s-maxage, no-cache, no-store.

Per-model cache controls​

Set cache under a model's litellm_params and the proxy applies it to every request routed to that deployment, so clients need no changes. It takes the same controls as the request body: ttl, s-maxage, no-cache, no-store. A model with no cache setting uses the proxy-wide cache settings.

model_list:
- model_name: cached-long
litellm_params:
model: openai/gpt-4o
cache: {ttl: 3600} # cache for 1 hour
- model_name: cached-short
litellm_params:
model: openai/gpt-4o-mini
cache: {ttl: 60} # cache for 1 minute
- model_name: uncached
litellm_params:
model: anthropic/claude-sonnet-4-5
cache: {no-cache: true, no-store: true} # never read from or write to the cache
allowed_response_cache_overrides: [] # clients cannot change this
- model_name: default
litellm_params:
model: openai/gpt-4o # no cache setting, uses litellm_settings

litellm_settings:
cache: true

The setting is per deployment. When several deployments share one model_name, repeat it on each of them.

A model that sets allowed_response_cache_overrides also decides caching for its fallbacks. When a request for that model is served by a fallback model with no allowed_response_cache_overrides of its own, the requested model's cache controls apply over the fallback's, and the fallback keeps any control the requested model does not set. When the fallback has its own allowed_response_cache_overrides, the stricter value of each control holds: no-cache or no-store set on either model stays on, and the shorter lifetime wins. A request control is honored only if both models allow it. A model without allowed_response_cache_overrides leaves each fallback on the fallback's own settings.

A virtual key's own cache controls still apply on a model with allowed_response_cache_overrides when they are at least as strict as the model's: a key set to no-store or no-cache stays uncached on a model whose list leaves those out, and a key's ttl or s-maxage holds when the model sets the same control to an equal or longer lifetime. A key control that would relax the model's rule is ignored and named in the response header like any other.

Choose which controls a client may override​

The model's cache and the request's cache are merged one control at a time. The model's value is the default for each control, and by default a request overrides the controls it sends and leaves the others in place. A request that sends "cache": {"ttl": 600} to the uncached model above would change the ttl only; no-cache and no-store stay set.

Add allowed_response_cache_overrides under the same litellm_params to list the controls a request may set on that model. A request control outside the list is ignored and the model's value is used.

allowed_response_cache_overridesWhat a client can change on this model
not setAny control it sends
[]Nothing, the model's cache is locked
["ttl"]Only the ttl
["no-cache", "no-store"]It can opt out of the cache, but cannot change the ttl

An ignored control is not dropped silently. The response carries an x-litellm-ignored-cache-controls header that names every ignored control, and the request still succeeds.

curl -i http://localhost:4000/v1/chat/completions   -H "Authorization: Bearer $LITELLM_API_KEY"   -H "Content-Type: application/json"   -d '{
"model": "uncached",
"messages": [{"role": "user", "content": "Hello"}],
"cache": {"ttl": 600, "no-store": false}
}'

# HTTP/1.1 200 OK
# x-litellm-ignored-cache-controls: ttl,no-store

This differs from allowed_cache_controls on a virtual key, which rejects a control outside its list with a 403. It is also unrelated to a provider's prompt caching, such as Anthropic's cache_control on a message block, which this setting does not touch.

Order of precedence​

Proxy-wide settings in litellm_settings decide whether caching is on at all and give the default ttl. A model's cache overrides those defaults for its deployment. The request's controls come next and are resolved in this order: the virtual key's metadata, then the body's cache field, then the Cache-Control header. The result overrides the model's value for each control the model allows, so a model's allowed_response_cache_overrides also applies to controls that come from a virtual key. No request or key setting turns caching on when it is off for the whole proxy.

Set caching default off (opt in only)​

  1. Set mode: default_off for caching
model_list:
- model_name: fake-openai-endpoint
litellm_params:
model: openai/fake
api_key: fake-key
api_base: https://exampleopenaiendpoint-production.up.railway.app/

# default off mode
litellm_settings:
set_verbose: True
cache: True
cache_params:
mode: default_off # Key change cache is default_off
  1. Opting in to cache when cache is default off
import os
from openai import OpenAI

client = OpenAI(api_key="<litellm-api-key>", base_url="http://0.0.0.0:4000")

chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model="gpt-6-luna",
extra_body = { # OpenAI python accepts extra args in extra_body
"cache": {"use-cache": True}
}
)

Control Call Types Caching is on for - (/chat/completion, /embeddings, etc.)​

By default, caching is on for all call types. You can control which call types caching is on for by setting supported_call_types in cache_params

Cache will only be on for the call types specified in supported_call_types

litellm_settings:
cache: True
cache_params:
type: redis
supported_call_types:
["acompletion", "atext_completion", "aembedding", "atranscription", "aresponses"]
# /chat/completions, /completions, /embeddings, /audio/transcriptions, /v1/responses

Exclude call types from caching​

excluded_call_types is merged on LiteLLM main in PR #52902 and is not in a tagged release yet.

excluded_call_types removes call types from supported_call_types, or from the default list when supported_call_types is not set, and leaves every other call type cached as before. List both embedding and aembedding, since /embeddings on the proxy runs as aembedding and the SDK embedding() call runs as embedding.

litellm_settings:
cache: True
cache_params:
type: redis
excluded_call_types: ["embedding", "aembedding"]

An excluded call type skips cache reads as well as writes, so entries cached before the exclusion are no longer served. The setting does not delete existing entries; their existing expiration and eviction rules still apply. An unset or empty excluded_call_types changes nothing, and supported_call_types: [] or null still caches nothing. Embeddings stay cached by default. See Keep embeddings from evicting rate limits and spend for when to use this.

Set cache for proxy, but not on the actual llm api call​

Use this if you just want to enable features like rate limiting, and loadbalancing across multiple instances.

Set supported_call_types: [] to disable caching on the actual api call.

litellm_settings:
cache: True
cache_params:
type: redis
supported_call_types: []

Deleting Cache Keys - /cache/delete​

To delete a cache key, send a request to /cache/delete with the keys you want to delete

Example

curl -X POST "http://0.0.0.0:4000/cache/delete" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{"keys": ["586bf3f3c1bf5aecb55bd9996494d3bbc69eb58397163add6d49537762a7548d", "key2"]}'
# {"status":"success"}

Viewing Cache Keys from responses​

You can view the cache_key in the response headers, on cache hits the cache key is sent as the x-litellm-cache-key response headers

curl -i --location 'http://0.0.0.0:4000/chat/completions' \
--header "Authorization: Bearer $LITELLM_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-6-luna",
"user": "ishan",
"messages": [
{
"role": "user",
"content": "what is litellm"
}
],
}'

Response from litellm proxy

date: Thu, 04 Apr 2024 17:37:21 GMT
content-type: application/json
x-litellm-cache-key: 586bf3f3c1bf5aecb55bd9996494d3bbc69eb58397163add6d49537762a7548d

{
"id": "chatcmpl-9ALJTzsBlXR9zTxPvzfFFtFbFtG6T",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "I'm sorr.."
"role": "assistant"
}
}
],
"created": 1712252235,
}

Provider-Specific Optional Parameters Caching​

By default, LiteLLM only includes standard OpenAI parameters in cache keys. However, some providers (like Vertex AI) use additional parameters that affect the output but aren't included in the standard cache key generation.

Enable Provider-Specific Parameter Caching​

Add this setting to your config.yaml to include provider-specific optional parameters in cache keys:

litellm_settings:
cache: True
cache_params:
type: "redis"
enable_caching_on_provider_specific_optional_params: True # Include provider-specific params in cache keys