Delivery
Cache
Purge the cache of a domain, write the rules that decide what is cached, and change its cache settings.
This part of the API controls the cache of one domain: what is cached, for how long, and how to remove it. The paths start with /v2/cdn/cache/{domain_public_id}/, where the id is the public id of the domain, taken from the domains list.
The examples on this page use these shell variables:
export DIAMWALL_API_KEY="your key"export CACHE="https://api.diamwall.com/v2/cdn/cache/your-domain-public-id"Purge the cache
Section titled “Purge the cache”A purge takes a body with a mode, and an Idempotency-Key header that you make up.
mode |
Other field | What is purged |
|---|---|---|
everything |
None | The whole cache of the domain |
prefix |
prefix |
Every path that begins with the prefix |
url |
urls |
The URLs of the list, 1 to 30 of them |
curl -X POST "$CACHE/actions/cache-purge/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: purge-all-2026-11-23-a1" \ -d '{ "mode": "everything" }'curl -X POST "$CACHE/actions/cache-purge/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: purge-images-2026-11-23-b2" \ -d '{ "mode": "prefix", "prefix": "/images/" }'curl -X POST "$CACHE/actions/cache-purge/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: purge-urls-2026-11-23-c3" \ -d '{ "mode": "url", "urls": [ "https://example.com/image-1.png", "https://www.example.com/image-2.png" ] }'- A field of another mode is refused:
prefixwithmode: "url", or either field withmode: "everything". prefixbegins with/and not with//, and holds at most 2048 bytes. Send it already URL-encoded, with no query string, no fragment, no spaces and no.or..segments. It is used exactly as you send it.- Each URL is absolute,
httporhttps, at most 2048 bytes, with no credentials, no fragment and no port other than 80 or 443. No URL comes twice. - Each URL belongs to the domain of the path, or to a name under it. A URL of another domain answers
400 INVALID_REQUESTwithurlsinfields. - The whole body holds at most 32768 bytes. Thirty URLs of the largest size do not fit.
Read the answer
Section titled “Read the answer”{ "revision": null, "consistency": "degraded", "publication": { "status": "unknown", "rollout": "unknown" }, "idempotency_replayed": false, "data": { "mode": "url", "total": 6, "succeeded": 5, "failed": 1, "results": [ { "total": 3, "succeeded": 3, "failed": 0 }, { "total": 3, "succeeded": 2, "failed": 1 } ] }}data.resultshas one entry for each target, in the order ofurls.everythingandprefixhave one entry.- The counts are servers, not bytes and not cached objects.
- A
200can be a purge that failed in part. Whenfailedis above zero the answer saysconsistency: "degraded". Show it as it is. It is not an error. revisionisnulland there is noETag.
The Idempotency-Key
Section titled “The Idempotency-Key”The key is 16 to 128 characters. The first is a letter or a digit, and the others are letters, digits, ., _, : or -. Make one key for each purge that a person asks for.
Sending the same key with the same body again within 24 hours purges nothing. You get the first answer back, with idempotency_replayed: true. After 24 hours no replay is promised, and the same request may purge again.
Some answers leave the outcome uncertain. What to do depends on the code:
| Answer | Did it run? | What to do |
|---|---|---|
502 FILE_SERVER_OUTCOME_UNKNOWN |
Maybe. The answer was lost. | Send the same request again with the same key, within 24 hours. |
503 ACTION_UNAVAILABLE |
Not confirmed. The cache servers could not be reached. | Back off, then send the same request again with the same key, within 24 hours. |
409 ACTION_OUTCOME_UNKNOWN |
Unknown. | Stop. Show the purge as uncertain. Do not repeat it and do not make a new key. |
409 IDEMPOTENCY_CONFLICT |
Unknown. The key may belong to another body. | Stop retrying. Do not change the key to get past it. |
429 ACTION_HISTORY_FULL |
No. | Do not send it again. Waiting does not end it. |
FILE_SERVER_V2_ERROR with a request_id |
Unconfirmed. | Show the purge as uncertain. Keep the request_id for support. |
A new key is only for a new purge that someone asks for later.
Cache rules
Section titled “Cache rules”A cache rule says which requests are cached and which bypass the cache. A domain holds at most 500 rules.
What a rule is made of
Section titled “What a rule is made of”| Field | What it is |
|---|---|
id |
Given by the API: r_ and 32 hexadecimal digits |
name |
Required. One line, 1 to 128 bytes. No two rules have the same name |
description |
Optional. One line, at most 1024 bytes. An empty string clears it |
enabled |
Required. true applies the rule, false keeps it without applying it |
priority |
Optional. A whole number from 1 to 1000000. The lowest is evaluated first. Without it, a new rule is given one |
type |
Required. all for every request of the domain, filter for the requests that expressions select |
expressions |
Required with filter: 1 to 64 conditions |
action |
Required. What the rule does. eligibility inside it is cache or bypass |
Each condition in expressions has exactly four fields:
| Field | Allowed values |
|---|---|
type |
main for the first condition. main, and or or for the others |
field |
ip, country, continent, asn, ua, cookie, hostname, referer, reqmethod, ssl, uri, fulluri, querystring, httpversion |
operator |
wildcard, equals, not_equals, contains, not_contains, starts_with, not_starts_with, ends_with, not_ends_with |
value |
One line, 1 to 2048 bytes |
What an action can hold
Section titled “What an action can hold”A rule that bypasses the cache has exactly { "eligibility": "bypass" }. A rule that caches can add these fields:
| Field | Allowed values |
|---|---|
runtime_version |
The version of the cache policy of the rule, 1 or 2. A new policy sends 2. An edit sends the version the rule was read with |
edge_ttl |
respect_origin, 5m, 30m, 1h, 4h, 12h, 1d, 7d, 30d, 60d, 90d, 1y |
browser_ttl |
respect_origin, match_edge, 5m, 30m, 1h, 4h, 12h, 1d, 7d, 30d, 1y |
query_string |
standard, sort, ignore_all |
strip_cookies |
true removes the cookies of an answer before it is cached |
origin_cache_control |
respect or ignore. ignore also overrides private, no-cache and no-store, so use it only for content you know is public |
min_uses |
1 to 1023: how many requests a key has before an answer is stored |
cache_retention |
1d, 7d, 14d, 30d, 60d, 90d, 180d, 365d, 730d: how long a copy is kept without being requested |
cache_statuses |
A list of 1 to 11 of: 200, 203, 204, 300, 301, 302, 303, 307, 308, 404, 410 |
revalidate |
true revalidates a stale copy with the origin |
stale_while_offline |
true serves a stale copy while the origin fails |
stale_while_revalidating |
true serves a stale copy while a fresh one is fetched |
auth_cookies |
The names of the cookies that mark a visitor as signed in: patterns (1 to 32 names, * allowed as the last character) and optionally except |
authenticated_fallback |
true serves a cached public copy to a signed-in visitor when the origin fails |
cache_key |
host_uri, kept for compatibility. A version 2 rule does not need it |
A few fields depend on each other. A request that breaks one of these answers 400 INVALID_REQUEST and names the field:
cache_retentionis longer than a fixededge_ttlin the same action. A year counts as 365 days, so365dwith1yis refused.authenticated_fallback: trueneedsauth_cookiesandstale_while_offline: truein the same action.- Each name in
auth_cookies.exceptis covered by one of thepatterns. - A bypass rule takes no
runtime_version. - With
runtime_version: 1,cache_retentionis90dandcache_statusesis[200].
Writes need the latest revision
Section titled “Writes need the latest revision”Every answer that reads the rules, the list or one rule, has an ETag header. It is the revision of all the rules of the domain together. A create, edit, delete or reorder sends it back in If-Match, exactly as it came, quotes included.
ETAG=$(curl -s -o /dev/null -D - "$CACHE/rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')Without If-Match the write answers 428. If the rules changed since your read it answers 412 REVISION_MISMATCH and writes nothing: read again, then send the change. Each write answers a new ETag to use on your next one.
List the rules
Section titled “List the rules”curl "$CACHE/rules/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:49976d9020e8...", "data": { "items": [ { "id": "r_00000000000000000000000000000002", "name": "Never cache the API", "description": "", "enabled": true, "priority": 10, "type": "filter", "expressions": [ { "type": "main", "field": "hostname", "operator": "equals", "value": "api.example.com" }, { "type": "or", "field": "uri", "operator": "starts_with", "value": "/api/" } ], "action": { "eligibility": "bypass" } } ], "page": { "limit": 50, "next_cursor": null, "total": 1 } }}limitgoes from 1 to 100. Without it a page holds 50 rules.- To read the next page, send
data.page.next_cursorback ascursor, until it isnull. cursorandlimitare the only query parameters. Any other answers400 INVALID_REQUEST.- If the rules change between two pages, the next page answers
409 CURSOR_STALE. Start again from the first page. - An empty
itemsmeans the domain has no cache rule. - A value the API does not offer is answered as
other. An action withotherin it cannot be sent back as it is.
Read one rule
Section titled “Read one rule”curl "$CACHE/rules/r_00000000000000000000000000000001/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"The rule is under data, with its whole action. The ETag is the same revision the list gives. An id that no rule has answers 404 RESOURCE_ITEM_NOT_FOUND.
Create a rule
Section titled “Create a rule”Read the list first to get the ETag. A domain with no rules has one too.
curl -X POST "$CACHE/rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "name": "Cache the blog", "description": "Public pages of the blog", "enabled": true, "priority": 10, "type": "filter", "expressions": [ { "type": "main", "field": "uri", "operator": "starts_with", "value": "/blog/" } ], "action": { "eligibility": "cache", "runtime_version": 2, "edge_ttl": "1h", "min_uses": 1, "cache_retention": "90d", "cache_statuses": [200, 301, 302, 404], "revalidate": true, "stale_while_offline": true, "stale_while_revalidating": true } }'curl -X POST "$CACHE/rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "name": "Never cache the API", "enabled": true, "type": "filter", "expressions": [ { "type": "main", "field": "hostname", "operator": "equals", "value": "api.example.com" }, { "type": "or", "field": "uri", "operator": "starts_with", "value": "/api/" } ], "action": { "eligibility": "bypass" } }'curl -X POST "$CACHE/rules/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "name": "Cache public assets", "enabled": true, "type": "all", "action": { "eligibility": "cache", "edge_ttl": "30m", "browser_ttl": "1h", "query_string": "ignore_all", "strip_cookies": true } }'The answer is 201 with the new rule under data, its id included, and a new ETag header.
The rule is stored as you send it. The API adds no default, no priority and no runtime_version. Nothing is trimmed or repaired, and an unknown field is refused.
Change a rule
Section titled “Change a rule”Send only the fields that change. A field you leave out keeps its value.
curl -X PATCH "$CACHE/rules/r_00000000000000000000000000000001/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "enabled": false }'The answer is the rule after the edit, under data. An empty body, {}, answers 400 NO_CHANGES.
Delete a rule
Section titled “Delete a rule”curl -X DELETE "$CACHE/rules/r_00000000000000000000000000000001/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $ETAG"The request has no body. The answer has no rule: operation.id is the id that was deleted, and the ETag header is the new revision. An id that is already gone answers 404 RESOURCE_ITEM_NOT_FOUND or 404 RULE_NOT_FOUND.
Reorder the rules
Section titled “Reorder the rules”Send every rule id in ids, in the order the rules are to have. It is the whole order, never only the rules that moved. Read every page of the list first.
curl -X PUT "$CACHE/rules/order/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "ids": [ "r_00000000000000000000000000000002", "r_00000000000000000000000000000001" ] }'The answer is all the rules in their new order, under data.items, with no paging. A list that leaves a rule out, names a rule that does not exist or has an id twice answers 400 INVALID_REQUEST. A reorder changes nothing else in a rule.
When a write gives no clear answer
Section titled “When a write gives no clear answer”502 FILE_SERVER_OUTCOME_UNKNOWN and FILE_SERVER_V2_ERROR mean the write may have been made. Do not send it again as it is. Read the rules, compare them with what you meant to write, and only then send a change with the new ETag. After a create, the rule may already be in the list.
Rule options
Section titled “Rule options”This read tells you what a cache rule can use on the domain, and the defaults that apply when no matching rule sets a value. Read it before you build or show a rule form.
curl "$CACHE/references/cache-rule-options/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:f3be288d25e7...", "consistency": "verified", "runtime_version": 2, "capabilities": { "policy_v2": true, "authenticated_fallback": true, "continuity": true }, "defaults": { "origin_cache_control": { "state": "resolved", "value": "respect" }, "min_uses": { "state": "resolved", "value": 3 }, "cache_retention": { "state": "resolved", "value": "1d" }, "cache_statuses": { "state": "resolved", "value": [200] }, "query_string": { "state": "resolved", "value": "standard" }, "edge_ttl": { "state": "resolved", "value": "respect_origin" } }, "choices": {}, "semantics": {}}The answer is one object, not a list. It takes no cursor and no limit, and has no ETag.
capabilities |
When it is false |
|---|---|
policy_v2 |
Do not create new rules with runtime_version: 2 |
authenticated_fallback |
Do not send authenticated_fallback: true |
continuity |
Do not offer Continuity |
A false never means you should delete a rule that is already saved.
About defaults:
- Use
valueonly whenstateisresolved. Withunknown,valueisnull: treat the default as unavailable and do not guess one. - A default is for display. Do not copy it into a rule.
origin_cache_controlcan have the valuepartial, withignored_headersandrespected_headers. It describes a default that ignores some origin headers and respects others. It is never a value to send in a rule.- A default that is missing from the answer was not answered. Do not fill it in.
Cache settings
Section titled “Cache settings”The settings are the cache configuration of the domain as a whole. Cache rules are not part of them.
Read the settings
Section titled “Read the settings”curl "$CACHE/settings/cache/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:8c2ebd6d17a1...", "consistency": "verified", "data": { "configuration": { "state": "resolved", "value": { "cache_enabled": true, "smart_cache": true, "stale_while_offline": false, "stale_while_revalidating": false, "cache_error_responses": false, "strip_response_cookies": false, "follow_redirects": false, "request_coalescing": true, "edge_ttl": "1d", "browser_ttl": "match_edge", "query_string": "standard", "static_content": { "images": { "enabled": true, "extensions": ["jpg", "jpeg", "gif", "png", "ico", "webp", "avif", "svg"] }, "assets": { "enabled": false, "extensions": ["js", "css"] }, "fonts": { "enabled": false, "extensions": ["woff", "woff2", "ttf", "eot", "otf"] } }, "vary": { "webp": false, "avif": false, "hostname": false, "country": false, "mobile": false } }, "updated": "2026-10-10T12:00:00.000Z" } }}static_content has seven types: images, assets, fonts, media, feed, documents and archives. The example shows three.
- Use
valueonly whenstateisresolved. Astateofunknownmeans the configuration is unavailable. It is not a cache that is off, and there is noETagto write with. - A field that is missing was not answered. A missing boolean is not
false. edge_ttl,browser_ttlorquery_stringcan be answered asotherwhen the domain holds a value outside the lists below. An edit can only set a value from the lists.updatedis the UTC time of the last change. It is read-only.- Keep the
ETagheader. An edit needs it.
Change the settings
Section titled “Change the settings”Read the settings to get their ETag, then send only the fields that change. This ETag is not the one of the cache rules.
SETTINGS_ETAG=$(curl -s -o /dev/null -D - "$CACHE/settings/cache/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
curl -X PATCH "$CACHE/settings/cache/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $SETTINGS_ETAG" \ -d '{ "smart_cache": false, "browser_ttl": "90d", "query_string": "ignore_all", "vary": { "webp": true, "avif": true } }'The answer is the settings after the edit, in the same form as the read, with a new ETag.
| Field | Allowed values |
|---|---|
cache_enabled |
true switches the cache of the domain on, false off |
smart_cache |
true or false |
stale_while_offline |
true serves a stale copy while the origin does not answer |
stale_while_revalidating |
true serves a stale copy while a fresh one is fetched |
cache_error_responses |
true caches the error answers of the origin |
strip_response_cookies |
true removes the cookies of an answer before it is cached |
follow_redirects |
true follows a redirect of the origin and caches what it leads to |
request_coalescing |
true makes requests for the same uncached content wait for one fetch |
edge_ttl |
respect_origin, 30m, 1h, 4h, 12h, 1d, 7d, 30d, 90d, 1y |
browser_ttl |
match_edge, 30m, 1h, 4h, 12h, 1d, 7d, 30d, 90d, 1y |
query_string |
standard, sort, ignore_all |
static_content |
For each type, enabled, extensions or both |
vary |
webp, avif, hostname, country, mobile: true keeps a separate copy for each |
- Booleans are JSON booleans.
"true",1andnullare refused. extensionsreplaces the whole list of its type. Each entry is 1 to 16 lower case letters and digits with no dot, such asjpgorwoff2. A list holds at most 128, none twice.5mand60dexist for cache rules, not for these settings.- An empty body,
{}, answers400 NO_CHANGES.
Limits and permissions
Section titled “Limits and permissions”- Credits. Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Reading the rules costs 6 credits. Reading the rule options or the settings, and every write of a rule or of the settings, costs 8. A purge costs 30.
- Refused early. A request the API refuses by itself, such as a
400for a wrong field or a428, spends no credits of the domain. - Out of credits. The call answers
429 TOO_MANY_REQUESTS, with the wait indetails.retry_after_secondsand in theRetry-Afterheader. - Rule limit. A domain holds at most 500 cache rules. A create beyond that answers
400 INVALID_REQUESTwith arequest_id. - Permissions. Reads need
speed.viewon the domain. Creating a rule needsspeed.create. Deleting a rule needsspeed.delete. Editing or reordering rules, changing the settings and purging needspeed.edit, andspeed.createorspeed.deletealso allow them.
Errors you are likely to see
Section titled “Errors you are likely to see”| Status | Code | Where | What happened |
|---|---|---|---|
400 |
INVALID_REQUEST |
All | A field is wrong. The answer names it in fields when it can. |
400 |
NO_CHANGES |
Rule edit, settings edit | An edit was sent with nothing to change. |
400 |
IDEMPOTENCY_KEY_REQUIRED, INVALID_IDEMPOTENCY_KEY |
Purge | The Idempotency-Key header is missing or not in its form. |
400 |
INVALID_PRECONDITION |
Writes | If-Match is not one quoted ETag as a read gave it. |
404 |
RESOURCE_ITEM_NOT_FOUND, RULE_NOT_FOUND |
Rules | No rule has that id. It may have been deleted. Read the list again. |
409 |
CURSOR_STALE |
Rule list | The rules changed while you were paging. Start from the first page. |
409 |
RULE_NAME_CONFLICT |
Rule create, edit | Another rule has that name. |
409 |
CACHE_POLICY_RUNTIME_UNAVAILABLE |
Rule create, edit | The rule asks for version 2 options that are not available on the domain. |
409 |
CACHE_AUTHENTICATED_FALLBACK_UNAVAILABLE |
Rule create, edit | authenticated_fallback: true is not available on the domain. |
409 |
CACHE_RULES_TRANSACTION_PENDING |
Rule writes, settings edit | A change of the cache rules is still pending. Read the rules again, then send the change with the new ETag. |
409 |
LEGACY_COLLECTION_DRIFT |
Rules | The rules of the domain are stored in an older form that cannot be verified. Nothing in the request can fix it. |
409 |
INVALID_STATE |
Settings edit | The change was refused for the state of the settings or of the domain. |
409 |
IDEMPOTENCY_CONFLICT, ACTION_OUTCOME_UNKNOWN |
Purge | See The Idempotency-Key. Stop, and do not retry. |
412 |
REVISION_MISMATCH |
Writes | What you are writing changed since your read. Read again and retry. |
428 |
PRECONDITION_REQUIRED |
Writes | The If-Match header is missing. |
429 |
TOO_MANY_REQUESTS |
All | The domain is out of credits for now. |
429 |
ACTION_HISTORY_FULL |
Purge | No more runs of the purge are kept for the domain. Waiting does not end it. Do not retry. |
502 |
FILE_SERVER_OUTCOME_UNKNOWN |
Writes, purge | The answer was lost and the change may have been made. |
503 |
ACTION_UNAVAILABLE |
Purge | The cache servers could not be reached. |
503 |
CACHE_RULE_OPTIONS_UNAVAILABLE |
Rule options | The options could not be read. Try again later. |
503 |
PUBLICATION_FAILED |
Settings edit | The change could not be published and verified. Read the settings again before another attempt. |
The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.
All Cache endpoints
Section titled “All Cache endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...