Skip to main content

Caching API

This page documents the 4 gateway endpoints tagged caching in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.

MethodPathSummary
GET/cache/pingCheck the response cache connection
POST/cache/deleteDelete cached responses by key
GET/cache/redis/infoRead Redis server information
POST/cache/flushallEmpty the Redis response cache

Endpoints​

GET /cache/ping​

Check the response cache connection

Connect to the response cache the gateway is using right now. For a Redis cache the gateway pings the server and writes a test entry, then reports the cache type and the masked connection settings. Proxy admins and Admin Viewers may call it. The Cache Health tab of the Response Cache page runs this check.

Example request:

curl -X GET "http://localhost:4000/cache/ping" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The cache answered the ping and accepted the test entry.application/json CachePingResponse
401No key was sent, or the key is not a proxy admin or admin viewer key. An internal user or org admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/cache/pingapplication/json ProxyError
503No cache is configured, or the cache did not answer the ping or the test writeapplication/json ProxyError

Response fields (200):

FieldTypeRequiredDescription
statusstringYesStatus
cache_typestringYesCache Type
ping_responseboolean or nullNoPing Response
set_cache_responsestring or nullNoSet Cache Response
spanway_cache_paramsstring or nullNoSpanway Cache Params
health_check_cache_paramsobject or nullNoHealth Check Cache Params

POST /cache/delete​

Delete cached responses by key

Remove the listed entries from a Redis response cache. Every response the gateway serves carries the key of its cache entry in the x-spanway-cache-key header, so copy that value to evict one answer without flushing the whole cache. Each worker's in-memory copy of those entries is dropped too, on the other workers through the coordination Redis when one is configured. Only a Redis cache supports this. Proxy admins only, and every call writes an audit row with the number of keys and their SHA-256 hashes.

Request body (application/json, schema CacheDeleteRequest):

FieldTypeRequiredDescription
keysarray of stringYesCache keys to remove, as the x-spanway-cache-key response header reported them

Example request:

curl -X POST "http://localhost:4000/cache/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"keys": [
"5f2a...c1",
"8bd0...9e"
]
}'

Responses:

StatusDescriptionBody
200The entries were removed.application/json CacheStatusResponse
400The response cache is not Redisapplication/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. An internal user or org admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/cache/deleteapplication/json ProxyError
403An admin viewer key tried to change the cache. Admin viewers can only readapplication/json ProxyError
422Validation Errorapplication/json HTTPValidationError
500Redis refused the deleteapplication/json ErrorDetail
503No response cache is configuredapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
statusstringYessuccess when the cache accepted the operation

GET /cache/redis/info​

Read Redis server information

Return the Redis INFO sections and the connected client list of the Redis response cache, for checking memory, version and connection counts from the gateway's point of view. Managed Redis services that refuse CLIENT LIST report -1 clients and the gateway still returns the INFO sections.

Example request:

curl -X GET "http://localhost:4000/cache/redis/info" \
-H "Authorization: Bearer $SPANWAY_API_KEY"

Responses:

StatusDescriptionBody
200The Redis INFO sections and the client list.application/json CacheRedisInfoResponse
400The response cache is not Redisapplication/json ErrorDetail
401No key was sent, or the key is not a proxy admin or admin viewer key. An internal user or org admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/cache/redis/infoapplication/json ProxyError
503No response cache is configured, or Redis did not answerapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
num_clientsintegerYesConnected Redis clients, or -1 when CLIENT LIST is refused by the server
clientsarray of anyYesThe CLIENT LIST rows, or one line saying the command is refused
infoobjectYesThe Redis INFO sections as the server reports them

POST /cache/flushall​

Empty the Redis response cache

Delete every cached response from the Redis response cache. The next request for each prompt goes to the provider again and is cached afresh. Only keys shaped like response cache entries are removed, so rate limit and spend counters, pod locks and any other data on the same Redis stay in place. Cached key lookups stored there are cleared too and are read again from the database on the next request. Entries saved under a per-request namespace are kept, delete those by key. Every worker's in-memory copy of cached answers is emptied too, on the other workers through the coordination Redis when one is configured. The route reads no body, only a Redis cache supports it, only proxy admins may call it, and every call writes an audit row with the number of entries removed.

Request body (application/json, object):

Example request:

curl -X POST "http://localhost:4000/cache/flushall" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Responses:

StatusDescriptionBody
200The cached responses were removed.application/json CacheFlushResponse
400The response cache is not Redisapplication/json ErrorDetail
401No key was sent, or the key is not a proxy admin key. An internal user or org admin key gets the same status with the message Authentication Error, Only proxy admin can be used to generate, delete, update info for new keys/users/teams. Route=/cache/flushallapplication/json ProxyError
403An admin viewer key tried to change the cache. Admin viewers can only readapplication/json ProxyError
503No response cache is configured, or Redis refused the flushapplication/json ErrorDetail

Response fields (200):

FieldTypeRequiredDescription
statusstringYessuccess when the cached responses were removed
deleted_entriesintegerYesHow many cached responses were removed