Skip to contentSkip to page list

Docs

Create a cache rule

Matchers are ANDed across non-null fields; at least one matcher is required.

POST/api/gateway/v1/cache-rules
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/gateway/v1/cache-rules"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "X-Auth-Token": api_key,    "Content-Type": "application/json",}payload = {    "matchers": {},    "action": {},}​response = requests.post(    origin + path,    headers=headers,    json=payload,)print(response.json())

Success

application/json · Generated from schema

{  "cache_rule": {    "id": "string",    "organization_id": "string",    "name": "string",    "description": "string",    "priority": -9007199254740991,    "enabled": false,    "matchers": {},    "action": {      "mode": "respect",      "ttl": -9007199254740991,      "salt": "string"    },    "mode_enum": "respect",    "archived_at": "string",    "created_at": "string",    "updated_at": "string"  }}
api-reference/gateway-cache-rules/create-a-cache-rule

Authorization

X-Auth-Tokenstringheaderrequired

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

Headers

Idempotency-Keystring

A caller-chosen key, 8 to 255 characters, that makes this create safe to retry. The first request to use a key runs normally and its response is stored for 24 hours. A later request with the same key and the same body is not executed again: it returns the stored response, marked with X-Idempotent-Replay: true. The same key with a different body is refused 409 idempotency_error, as is a retry sent while the original is still running. Only successful responses are stored, so a create that failed can simply be retried with the same key.

At least 8 charactersUp to 255 characters

Request body

application/json · Required

namestringrequired
At least 1 characterUp to 128 characters
descriptionstring | null
Option 1string
Option 2null
priorityinteger
Minimum 0Maximum 1000
enabledboolean
matchersobjectrequired
vk_idstring
vk_tagsstring[]
vk_prefixstring
principal_idstring
modelstring
request_metadataobject
actionobjectrequired
modestringrequired
One of"respect""force""disable"
ttlinteger
Minimum 0Maximum 86400
saltstring
Up to 64 characters

Responses

201

Success

application/json

cache_ruleobjectrequired
idstringrequired
organization_idstringrequired
namestringrequired
descriptionstring | nullrequired
priorityintegerrequired
Minimum -9007199254740991Maximum 9007199254740991
enabledbooleanrequired
matchersobjectrequired
actionobjectrequired
mode_enumstringrequired
One of"respect""force""disable"
archived_atstring | nullrequired
created_atstringrequired
updated_atstringrequired
400

Bad Request

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
401

Unauthorized

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
403

Forbidden

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
409

Conflict

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
500

Internal Server Error

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]

Documentation