Skip to main content

Native Resources API

Access user-defined Cloudflare KV, D1, and Vectorize resources. All endpoints require Service Key authentication.


KV

POST /api/kv/:namespace

Action-based operations on a user-defined KV namespace. The namespace must be declared in config.kv.

Auth: Service Key required.

ActionBody FieldsDescription
getkeyGet value by key
setkey, value, ttl?Set value (TTL in seconds)
deletekeyDelete key
listprefix?, limit?, cursor?List keys

Examples:

Set a value:

{ "action": "set", "key": "user:123", "value": "cached-data", "ttl": 300 }

Get response:

{ "value": "cached-data" }

List response:

{ "keys": ["user:1", "user:2"], "cursor": null }

D1

POST /api/d1/:database

Execute SQL on a user-defined D1 database. The database must be declared in config.d1.

Auth: Service Key required.

FieldTypeRequiredDescription
querystringYesSQL query
paramsarrayNoParameter bindings

Request example:

{ "query": "SELECT * FROM events WHERE type = ? LIMIT 10", "params": ["click"] }

Response 200:

{
"results": [{ "id": 1, "type": "click", "createdAt": "..." }],
"meta": { "changes": 0, "rows_read": 10 }
}

Vectorize

POST /api/vectorize/:index

Action-based operations on a user-defined Vectorize index. The index must be declared in config.vectorize.

Auth: Service Key required.

ActionBody FieldsDescription
upsertvectors (array of {id, values, metadata?})Insert or update vectors
searchvector, topK?, filter?Search for similar vectors
deleteids (string array)Delete vectors by ID

Search example:

{ "action": "search", "vector": [0.1, 0.2, 0.3], "topK": 5 }