KV

kv

KV

Namespaces

kv.namespaces

Methods

Delete Multiple Key Value Pairs -> Envelope<{ successful_key_count, unsuccessful_keys }>
post/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/delete

Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.

Write Multiple Key Value Pairs -> Envelope<{ successful_key_count, unsuccessful_keys }>
put/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk

Write multiple keys and values at once. Body should be an array of up to 10,000 key-value pairs to be stored, along with optional expiration information. Existing values and expirations will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. The entire request size must be 100 megabytes or less.

Create A Namespace -> Envelope<>
post/accounts/{account_id}/storage/kv/namespaces

Creates a namespace under the given title. A 400 is returned if the account already owns a namespace with this title. A namespace must be explicitly deleted to be replaced.

Remove A Namespace -> Envelope<{ }>
delete/accounts/{account_id}/storage/kv/namespaces/{namespace_id}

Deletes the namespace corresponding to the given ID.

Get A Namespace -> Envelope<>
get/accounts/{account_id}/storage/kv/namespaces/{namespace_id}

Get the namespace corresponding to the given ID.

List Namespaces -> V4PagePaginationArray<>
get/accounts/{account_id}/storage/kv/namespaces

Returns the namespaces owned by an account.

Rename A Namespace -> Envelope<{ }>
put/accounts/{account_id}/storage/kv/namespaces/{namespace_id}

Modifies a namespace's title.

Domain types

Namespace = { id, title, supports_url_encoding }
KVNamespaces

Analytics

kv.namespaces.analytics

Methods

Query Request Analytics Deprecated -> Envelope<>
get/accounts/{account_id}/storage/analytics

Retrieves Workers KV request metrics for the given account.

Security

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example: Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY

Accepted Permissions (at least one required)

Workers KV Storage Write Workers KV Storage Read

Parameters
account_id: string

Identifier

query: {
Optional

For specifying result metrics.

dimensions: Array<"accountId" | "responseCode" | "requestType">
Optional

Can be used to break down the data by given attributes.

filters: string
Optional

Used to filter rows by one or more dimensions. Filters can be combined using OR and AND boolean logic. AND takes precedence over OR in all the expressions. The OR operator is defined using a comma (,) or OR keyword surrounded by whitespace. The AND operator is defined using a semicolon (;) or AND keyword surrounded by whitespace. Note that the semicolon is a reserved character in URLs (rfc1738) and needs to be percent-encoded as %3B. Comparison options are:

Operator Name URL Encoded
== Equals %3D%3D
!= Does not equals !%3D
                   | Greater Than                    | %3E

< | Less Than | %3C = | Greater than or equal to | %3E%3D <= | Less than or equal to | %3C%3D .

limit: number
Optional

Limit number of returned metrics.

metrics: Array<"requests" | "writeKiB" | "readKiB">
Optional

One or more metrics to compute.

since: string
Optional

Start of time interval to query, defaults to 6 hours before request received.

sort: Array<string>
Optional

Array of dimensions or metrics to sort by, each dimension/metric may be prefixed by - (descending) or + (ascending).

until: string
Optional

End of time interval to query, defaults to current time.

}
Response fields
errors: Array<>
messages: Array<>
success: true

Whether the API call was successful

result:
Optional

Metrics on Workers KV requests.

Request example
200Example
Query Stored Data Analytics Deprecated -> Envelope<>
get/accounts/{account_id}/storage/analytics/stored

Retrieves Workers KV stored data metrics for the given account.

Domain types

Components = { data, data_lag, max, 5 more... }
Schema = { data, data_lag, max, 5 more... }

kv.namespaces.keys

Methods

List A Namespace S Keys -> CursorLimitPagination<>
get/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys

Lists a namespace's keys.

Domain types

Key = { name, expiration, metadata }
KVNamespaces

Metadata

kv.namespaces.metadata

Methods

Read The Metadata For A Key -> Envelope<Record<string, unknown>>
get/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/metadata/{key_name}

Returns the metadata associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

kv.namespaces.values

Methods

Delete Key Value Pair -> Envelope<{ }>
delete/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}

Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name.

Read Key Value Pair -> unknown
get/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}

Returns the value associated with the given key in the given namespace. Use URL-encoding to use special characters (for example, :, !, %) in the key name. If the KV-pair is set to expire at some point, the expiration time as measured in seconds since the UNIX epoch will be returned in the expiration response header.

Write Key Value Pair With Optional Metadata -> Envelope<{ }>
put/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}

Write a value identified by a key. Use URL-encoding to use special characters (for example, :, !, %) in the key name. Body should be the value to be stored. If JSON metadata to be associated with the key/value pair is needed, use multipart/form-data content type for your PUT request (see dropdown below in REQUEST BODY SCHEMA). Existing values, expirations, and metadata will be overwritten. If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored.