openapi: 3.0.3 info: title: Cloudflare Workers KV 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 externalDocs: url: https://developers.cloudflare.com/kv/ description: Cloudflare Workers KV Documentation servers: - url: https://api.cloudflare.com/client/v4 description: Cloudflare API v4 components: schemas: workers-kv_any: anyOf: - type: string - type: number - type: integer - type: boolean - additionalProperties: true nullable: true type: object - items: $ref: '#/components/schemas/workers-kv_any' type: array x-stainless-override-schema: type: unknown workers-kv_api-response-collection: allOf: - $ref: '#/components/schemas/workers-kv_api-response-common' - properties: result_info: $ref: '#/components/schemas/workers-kv_result_info' type: object type: object workers-kv_api-response-common: properties: errors: $ref: '#/components/schemas/workers-kv_messages' messages: $ref: '#/components/schemas/workers-kv_messages' success: description: Whether the API call was successful. enum: - true example: true type: boolean required: - success - errors - messages type: object 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_api-response-common-no-result: allOf: - $ref: '#/components/schemas/workers-kv_api-response-common' - properties: result: nullable: true type: object x-stainless-empty-object: true type: object workers-kv_bulk-get-result: properties: values: additionalProperties: description: The value associated with the key. oneOf: - type: string - type: number - type: boolean - additionalProperties: true type: object description: Requested keys are paired with their values in an object. example: key1: value1 key2: value2 type: object 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: 1.5778368e+09 metadata: someMetadataKey: someMetadataValue value: value1 key2: metadata: anotherKey: anotherValue value: value2 type: object 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_bulk_delete: items: $ref: '#/components/schemas/workers-kv_key_name_bulk' type: array workers-kv_bulk_write: items: properties: base64: default: false description: Indicates whether or not the server should base64 decode the value before storing it. Useful for writing values that wouldn't otherwise be valid JSON strings, such as images. type: boolean expiration: $ref: '#/components/schemas/workers-kv_expiration' expiration_ttl: $ref: '#/components/schemas/workers-kv_expiration_ttl' key: $ref: '#/components/schemas/workers-kv_key_name_bulk' metadata: $ref: '#/components/schemas/workers-kv_list_metadata' value: description: A UTF-8 encoded string to be stored, up to 25 MiB in length. example: Some string maxLength: 26214400 type: string required: - key - value type: object type: array workers-kv_create_rename_namespace_body: properties: title: $ref: '#/components/schemas/workers-kv_namespace_title' required: - title type: object 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_cursor_result_info: properties: count: description: Total results returned based on your list parameters. example: 1 type: number cursor: $ref: '#/components/schemas/workers-kv_cursor' type: object workers-kv_expiration: description: Expires the key at a certain time, measured in number of seconds since the UNIX epoch. example: 1.578435e+09 type: number workers-kv_expiration_ttl: description: Expires the key after a number of seconds. Must be at least 60. example: 300 minimum: 60 type: number workers-kv_identifier: description: Identifier. example: 023e105f4ecef8ad9ca31a8372d0c353 maxLength: 32 readOnly: true type: string x-auditable: true 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: 1.5778368e+09 type: number metadata: $ref: '#/components/schemas/workers-kv_list_metadata' name: $ref: '#/components/schemas/workers-kv_key_name' required: - name 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 maxLength: 512 type: string workers-kv_key_name_bulk: description: A key's name. The name may be at most 512 bytes. All printable, non-whitespace characters are valid. example: My-Key maxLength: 512 type: string 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: properties: id: $ref: '#/components/schemas/workers-kv_namespace_identifier' supports_url_encoding: description: True if keys written on the URL will be URL-decoded before storing. For example, if set to "true", a key written on the URL as "%3F" will be stored as "?". example: true readOnly: true type: boolean x-auditable: true title: $ref: '#/components/schemas/workers-kv_namespace_title' required: - id - title type: object workers-kv_namespace_identifier: description: Namespace identifier tag. example: 0f2ac74b498b48028cb68387c421e279 maxLength: 32 readOnly: true type: string x-auditable: true 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_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_value: anyOf: - type: string - format: binary type: string description: A byte sequence to be stored, up to 25 MiB in length. example: Some Value 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