Cloudflare KV Workers KV Namespace API
The Workers KV Namespace API from Cloudflare KV — 8 operation(s) for workers kv namespace.
The Workers KV Namespace API from Cloudflare KV — 8 operation(s) for workers kv namespace.
openapi: 3.0.3
info:
title: Cloudflare Workers KV Workers KV Namespace API
description: 'Cloudflare Workers KV is a globally distributed key-value store accessible via REST API. Endpoints cover namespace management, key enumeration, value reads/writes, bulk operations, bulk deletes, and key metadata retrieval. All requests are authenticated with a Bearer API token.
'
version: 4.0.0
license:
name: BSD-3-Clause
url: https://opensource.org/licenses/BSD-3-Clause
servers:
- url: https://api.cloudflare.com/client/v4
description: Cloudflare API v4
tags:
- name: Workers KV Namespace
paths:
/accounts/{account_id}/storage/kv/namespaces:
get:
description: Returns the namespaces owned by an account.
operationId: workers-kv-namespace-list-namespaces
parameters:
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
- in: query
name: page
schema:
default: 1
description: Page number of paginated results.
minimum: 1
type: number
- in: query
name: per_page
schema:
default: 20
description: Maximum number of results per page.
maximum: 1000
minimum: 1
type: number
- in: query
name: order
schema:
description: Field to order results by.
enum:
- id
- title
example: id
type: string
- in: query
name: direction
schema:
description: Direction to order namespaces.
enum:
- asc
- desc
example: asc
type: string
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: List Namespaces response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-collection'
- properties:
result:
items:
$ref: '#/components/schemas/workers-kv_namespace'
type: array
type: object
description: List Namespaces response.
security:
- api_token: []
- api_email: []
api_key: []
summary: List Namespaces
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
post:
description: 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.
operationId: workers-kv-namespace-create-a-namespace
parameters:
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_create_rename_namespace_body'
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Create a Namespace response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common'
- properties:
result:
$ref: '#/components/schemas/workers-kv_namespace'
type: object
description: Create a Namespace response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Create a Namespace
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}:
delete:
description: Deletes the namespace corresponding to the given ID.
operationId: workers-kv-namespace-remove-a-namespace
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json: {}
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Remove a Namespace response failure.
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-no-result'
description: Remove a Namespace response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Remove a Namespace
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
get:
description: Get the namespace corresponding to the given ID.
operationId: workers-kv-namespace-get-a-namespace
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Get a Namespace response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common'
- properties:
result:
$ref: '#/components/schemas/workers-kv_namespace'
type: object
description: Get a Namespace response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Get a Namespace
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
put:
description: Modifies a namespace's title.
operationId: workers-kv-namespace-rename-a-namespace
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_create_rename_namespace_body'
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Rename a Namespace response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common'
- properties:
result:
$ref: '#/components/schemas/workers-kv_namespace'
required:
- result
type: object
description: Rename a Namespace response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Rename a Namespace
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk:
delete:
deprecated: true
description: Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
operationId: workers-kv-namespace-delete-multiple-key-value-pairs-deprecated
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_bulk_delete'
required: true
responses:
4XX:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Delete multiple key-value pairs response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Delete multiple key-value pairs response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Delete multiple key-value pairs
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
put:
description: 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.
operationId: workers-kv-namespace-write-multiple-key-value-pairs
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_bulk_write'
required: true
responses:
4XX:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Write multiple key-value pairs response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Write multiple key-value pairs response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Write multiple key-value pairs
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/delete:
post:
description: Remove multiple KV pairs from the namespace. Body should be an array of up to 10,000 keys to be removed.
operationId: workers-kv-namespace-delete-multiple-key-value-pairs
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_bulk_delete'
required: true
responses:
4XX:
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Delete multiple key-value pairs response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
$ref: '#/components/schemas/workers-kv_bulk-result'
type: object
description: Delete multiple key-value pairs response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Delete multiple key-value pairs
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/bulk/get:
post:
description: Retrieve up to 100 KV pairs from the namespace. Keys must contain text-based values. JSON values can optionally be parsed instead of being returned as a string value. Metadata can be included if `withMetadata` is true.
operationId: workers-kv-namespace-get-multiple-key-value-pairs
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json:
schema:
properties:
keys:
description: Array of keys to retrieve (maximum of 100).
items:
$ref: '#/components/schemas/workers-kv_key_name_bulk'
maxItems: 100
type: array
type:
default: text
description: Whether to parse JSON values in the response.
enum:
- text
- json
type: string
withMetadata:
default: false
description: Whether to include metadata in the response.
type: boolean
required:
- keys
type: object
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Get multiple key-value pairs response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common-no-result'
- properties:
result:
oneOf:
- $ref: '#/components/schemas/workers-kv_bulk-get-result'
- $ref: '#/components/schemas/workers-kv_bulk-get-result-with-metadata'
type: object
description: Get multiple key-value pairs response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Get multiple key-value pairs
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys:
get:
description: Lists a namespace's keys.
operationId: workers-kv-namespace-list-a-namespace'-s-keys
parameters:
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
- in: query
name: limit
schema:
default: 1000
description: Limits the number of keys returned in the response. The cursor attribute may be used to iterate over the next batch of keys if there are more than the limit.
maximum: 1000
minimum: 10
type: number
- in: query
name: prefix
schema:
description: Filters returned keys by a name prefix. Exact matches and any key names that begin with the prefix will be returned.
example: My-Prefix
type: string
- in: query
name: cursor
schema:
description: Opaque token indicating the position from which to continue when requesting the next set of records if the amount of list results was limited by the limit parameter. A valid value for the cursor can be obtained from the `cursors` object in the `result_info` structure.
example: 6Ck1la0VxJ0djhidm1MdX2FyDGxLKVeeHZZmORS_8XeSuhz9SjIJRaSa2lnsF01tQOHrfTGAP3R5X1Kv5iVUuMbNKhWNAXHOl6ePB0TUL8nw
type: string
x-stainless-pagination-property:
purpose: next_cursor_param
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: List a Namespace's Keys response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common'
- properties:
result:
items:
$ref: '#/components/schemas/workers-kv_key'
type: array
x-stainless-pagination-property:
purpose: items
result_info:
$ref: '#/components/schemas/workers-kv_cursor_result_info'
type: object
description: List a Namespace's Keys response.
security:
- api_token: []
- api_email: []
api_key: []
summary: List a Namespace's Keys
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/metadata/{key_name}:
get:
description: 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.
operationId: workers-kv-namespace-read-the-metadata-for-a-key
parameters:
- in: path
name: key_name
required: true
schema:
$ref: '#/components/schemas/workers-kv_key_name'
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Read the metadata for a key response failure.
'200':
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/workers-kv_api-response-common'
- properties:
result:
$ref: '#/components/schemas/workers-kv_list_metadata'
type: object
description: Read the metadata for a key response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Read the metadata for a key
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/values/{key_name}:
delete:
description: Remove a KV pair from the namespace. Use URL-encoding to use special characters (for example, `:`, `!`, `%`) in the key name.
operationId: workers-kv-namespace-delete-key-value-pair
parameters:
- in: path
name: key_name
required: true
schema:
$ref: '#/components/schemas/workers-kv_key_name'
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
requestBody:
content:
application/json: {}
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Delete key-value pair response failure.
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-no-result'
description: Delete key-value pair response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Delete key-value pair
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
get:
description: 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.
operationId: workers-kv-namespace-read-key-value-pair
parameters:
- in: path
name: key_name
required: true
schema:
$ref: '#/components/schemas/workers-kv_key_name'
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Read key-value pair response failure.
'200':
content:
application/octet-stream:
schema:
$ref: '#/components/schemas/workers-kv_value'
description: Read key-value pair response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Read key-value pair
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
- Workers KV Storage Read
put:
description: 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.
operationId: workers-kv-namespace-write-key-value-pair-with-metadata
parameters:
- in: path
name: key_name
required: true
schema:
$ref: '#/components/schemas/workers-kv_key_name'
- in: path
name: namespace_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_namespace_identifier'
- in: path
name: account_id
required: true
schema:
$ref: '#/components/schemas/workers-kv_identifier'
- in: query
name: expiration
schema:
$ref: '#/components/schemas/workers-kv_expiration'
- in: query
name: expiration_ttl
schema:
$ref: '#/components/schemas/workers-kv_expiration_ttl'
requestBody:
content:
application/octet-stream:
schema:
$ref: '#/components/schemas/workers-kv_value'
x-stainless-only:
- http
multipart/form-data:
encoding:
metadata:
contentType: application/json
schema:
properties:
metadata:
$ref: '#/components/schemas/workers-kv_metadata'
value:
$ref: '#/components/schemas/workers-kv_value'
required:
- value
type: object
required: true
responses:
4XX:
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-failure'
description: Write key-value pair with metadata response failure.
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/workers-kv_api-response-common-no-result'
description: Write key-value pair with metadata response.
security:
- api_token: []
- api_email: []
api_key: []
summary: Write key-value pair with optional metadata
tags:
- Workers KV Namespace
x-api-token-group:
- Workers KV Storage Write
components:
schemas:
workers-kv_list_metadata:
allOf:
- $ref: '#/components/schemas/workers-kv_any'
- description: Arbitrary JSON that is associated with a key.
example:
someMetadataKey: someMetadataValue
workers-kv_messages:
example: []
items:
properties:
code:
minimum: 1000
type: integer
message:
type: string
required:
- code
- message
type: object
type: array
uniqueItems: true
workers-kv_metadata:
allOf:
- $ref: '#/components/schemas/workers-kv_any'
- description: Associates arbitrary JSON data with a key/value pair.
example:
someMetadataKey: someMetadataValue
workers-kv_namespace_title:
description: A human-readable string name for a Namespace.
example: My Own Namespace
maxLength: 512
type: string
x-auditable: true
workers-kv_cursor:
description: Opaque token indicating the position from which to continue when requesting the next set of records if the amount of list results was limited by the limit parameter. A valid value for the cursor can be obtained from the cursors object in the result_info structure.
example: 6Ck1la0VxJ0djhidm1MdX2FyDGxLKVeeHZZmORS_8XeSuhz9SjIJRaSa2lnsF01tQOHrfTGAP3R5X1Kv5iVUuMbNKhWNAXHOl6ePB0TUL8nw
type: string
x-stainless-pagination-property:
purpose: next_cursor_field
workers-kv_identifier:
description: Identifier.
example: 023e105f4ecef8ad9ca31a8372d0c353
maxLength: 32
readOnly: true
type: string
x-auditable: true
workers-kv_api-response-common-failure:
properties:
errors:
allOf:
- $ref: '#/components/schemas/workers-kv_messages'
example:
- code: 7003
message: No route for the URI
minLength: 1
messages:
allOf:
- $ref: '#/components/schemas/workers-kv_messages'
example: []
result:
nullable: true
type: object
x-stainless-empty-object: true
success:
description: Whether the API call was successful.
enum:
- false
example: false
type: boolean
required:
- success
- errors
- messages
- result
type: object
workers-kv_bulk-get-result-with-metadata:
properties:
values:
additionalProperties:
nullable: true
properties:
expiration:
$ref: '#/components/schemas/workers-kv_expiration'
metadata:
allOf:
- $ref: '#/components/schemas/workers-kv_any'
- description: The metadata associated with the key.
value:
allOf:
- $ref: '#/components/schemas/workers-kv_any'
- description: The value associated with the key.
required:
- value
- metadata
type: object
description: Requested keys are paired with their values and metadata in an object.
example:
key1:
expiration: 1577836800.0
metadata:
someMetadataKey: someMetadataValue
value: value1
key2:
metadata:
anotherKey: anotherValue
value: value2
type: object
type: object
workers-kv_key:
description: A name for a value. A value stored under a given key may be retrieved via the same key.
properties:
expiration:
description: The time, measured in number of seconds since the UNIX epoch, at which the key will expire. This property is omitted for keys that will not expire.
example: 1577836800.0
type: number
metadata:
$ref: '#/components/schemas/workers-kv_list_metadata'
name:
$ref: '#/components/schemas/workers-kv_key_name'
required:
- name
type: object
workers-kv_create_rename_namespace_body:
properties:
title:
$ref: '#/components/schemas/workers-kv_namespace_title'
required:
- title
type: object
workers-kv_bulk-result:
properties:
successful_key_count:
description: Number of keys successfully updated.
example: 100
type: number
unsuccessful_keys:
description: Name of the keys that failed to be fully updated. They should be retried.
items:
type: string
type: array
type: object
workers-kv_result_info:
properties:
count:
description: Total number of results for the requested service.
example: 1
type: number
page:
description: Current page within paginated list of results.
example: 1
type: number
per_page:
description: Number of results per page of results.
example: 20
type: number
total_count:
description: Total results available without any search parameters.
example: 2000
type: number
type: object
workers-kv_key_name:
description: A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. Use percent-encoding to define key names as part of a URL.
example: My-Key
# --- truncated at 32 KB (36 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/cloudflare-kv/refs/heads/main/openapi/cloudflare-kv-workers-kv-namespace-api-openapi.yml