import requests
url = "https://app.langwatch.ai/api/gateway/v1/cache-rules"
payload = {
"name": "<string>",
"matchers": {
"vk_id": "<string>",
"vk_tags": ["<string>"],
"vk_prefix": "<string>",
"principal_id": "<string>",
"model": "<string>",
"request_metadata": {}
},
"action": {
"ttl": 43200,
"salt": "<string>"
}
}
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
matchers: {
vk_id: '<string>',
vk_tags: ['<string>'],
vk_prefix: '<string>',
principal_id: '<string>',
model: '<string>',
request_metadata: {}
},
action: {ttl: 43200, salt: '<string>'}
})
};
fetch('https://app.langwatch.ai/api/gateway/v1/cache-rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/gateway/v1/cache-rules \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>",
"matchers": {
"vk_id": "<string>",
"vk_tags": [
"<string>"
],
"vk_prefix": "<string>",
"principal_id": "<string>",
"model": "<string>",
"request_metadata": {}
},
"action": {
"ttl": 43200,
"salt": "<string>"
}
}
'{
"cache_rule": {
"id": "<string>",
"organization_id": "<string>",
"name": "<string>",
"description": "<string>",
"priority": 123,
"enabled": true,
"matchers": {},
"action": {
"mode": "respect",
"ttl": 123,
"salt": "<string>"
},
"mode_enum": "respect",
"archived_at": "<string>",
"created_at": "<string>",
"updated_at": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}Create a cache rule
Matchers are ANDed across non-null fields; at least one matcher is required. Mode is one of respect/force/disable. TTL is clamped to [0, 86400]. Salt is an optional cache-bust tag (max 64 chars). All writes emit a ChangeEvent so the gateway picks up the new rule within 30 s via its /changes long-poll. Send Idempotency-Key to make a retry safe.
import requests
url = "https://app.langwatch.ai/api/gateway/v1/cache-rules"
payload = {
"name": "<string>",
"matchers": {
"vk_id": "<string>",
"vk_tags": ["<string>"],
"vk_prefix": "<string>",
"principal_id": "<string>",
"model": "<string>",
"request_metadata": {}
},
"action": {
"ttl": 43200,
"salt": "<string>"
}
}
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
matchers: {
vk_id: '<string>',
vk_tags: ['<string>'],
vk_prefix: '<string>',
principal_id: '<string>',
model: '<string>',
request_metadata: {}
},
action: {ttl: 43200, salt: '<string>'}
})
};
fetch('https://app.langwatch.ai/api/gateway/v1/cache-rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/gateway/v1/cache-rules \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>",
"matchers": {
"vk_id": "<string>",
"vk_tags": [
"<string>"
],
"vk_prefix": "<string>",
"principal_id": "<string>",
"model": "<string>",
"request_metadata": {}
},
"action": {
"ttl": 43200,
"salt": "<string>"
}
}
'{
"cache_rule": {
"id": "<string>",
"organization_id": "<string>",
"name": "<string>",
"description": "<string>",
"priority": 123,
"enabled": true,
"matchers": {},
"action": {
"mode": "respect",
"ttl": 123,
"salt": "<string>"
},
"mode_enum": "respect",
"archived_at": "<string>",
"created_at": "<string>",
"updated_at": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}Authorizations
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
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.
8 - 255Body
Response
Created
Show child attributes
Show child attributes
Was this page helpful?