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.
| Method | Path | Summary |
|---|---|---|
| GET | /cache/ping | Check the response cache connection |
| POST | /cache/delete | Delete cached responses by key |
| GET | /cache/redis/info | Read Redis server information |
| POST | /cache/flushall | Empty 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:
| Status | Description | Body |
|---|---|---|
| 200 | The cache answered the ping and accepted the test entry. | application/json CachePingResponse |
| 401 | No 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/ping | application/json ProxyError |
| 503 | No cache is configured, or the cache did not answer the ping or the test write | application/json ProxyError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | string | Yes | Status |
cache_type | string | Yes | Cache Type |
ping_response | boolean or null | No | Ping Response |
set_cache_response | string or null | No | Set Cache Response |
spanway_cache_params | string or null | No | Spanway Cache Params |
health_check_cache_params | object or null | No | Health 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):
| Field | Type | Required | Description |
|---|---|---|---|
keys | array of string | Yes | Cache 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:
| Status | Description | Body |
|---|---|---|
| 200 | The entries were removed. | application/json CacheStatusResponse |
| 400 | The response cache is not Redis | application/json ErrorDetail |
| 401 | No 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/delete | application/json ProxyError |
| 403 | An admin viewer key tried to change the cache. Admin viewers can only read | application/json ProxyError |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Redis refused the delete | application/json ErrorDetail |
| 503 | No response cache is configured | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | string | Yes | success 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:
| Status | Description | Body |
|---|---|---|
| 200 | The Redis INFO sections and the client list. | application/json CacheRedisInfoResponse |
| 400 | The response cache is not Redis | application/json ErrorDetail |
| 401 | No 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/info | application/json ProxyError |
| 503 | No response cache is configured, or Redis did not answer | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
num_clients | integer | Yes | Connected Redis clients, or -1 when CLIENT LIST is refused by the server |
clients | array of any | Yes | The CLIENT LIST rows, or one line saying the command is refused |
info | object | Yes | The 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:
| Status | Description | Body |
|---|---|---|
| 200 | The cached responses were removed. | application/json CacheFlushResponse |
| 400 | The response cache is not Redis | application/json ErrorDetail |
| 401 | No 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/flushall | application/json ProxyError |
| 403 | An admin viewer key tried to change the cache. Admin viewers can only read | application/json ProxyError |
| 503 | No response cache is configured, or Redis refused the flush | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
status | string | Yes | success when the cached responses were removed |
deleted_entries | integer | Yes | How many cached responses were removed |