# Images # V1 ## List images `client.images.v1.list(V1ListParamsparams, RequestOptionsoptions?): V4PagePagination` **get** `/accounts/{account_id}/images/v1` List up to 100 images with one request. Use the optional parameters below to get a specific range of images. ### Parameters - `params: V1ListParams` - `account_id: string` Path param: Account identifier tag. - `creator?: string | null` Query param: Internal user ID set within the creator field. Setting to empty string "" will return images where creator field is not set - `page?: number` Query param: Page number of paginated results. - `per_page?: number` Query param: Number of items per page. ### Returns - `V1ListResponse` - `images?: Array` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); // Automatically fetches more pages as needed. for await (const v1ListResponse of client.images.v1.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', })) { console.log(v1ListResponse.images); } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "images": [ { "id": "id", "creator": "107b9558-dd06-4bbd-5fef-9c2c16bb7900", "filename": "logo.png", "meta": { "key": "value" }, "requireSignedURLs": true, "uploaded": "2014-01-02T02:20:00.123Z", "variants": [ "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/thumbnail", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/hero", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/original" ] } ] }, "success": true } ``` ## Image details `client.images.v1.get(stringimageId, V1GetParamsparams, RequestOptionsoptions?): Image` **get** `/accounts/{account_id}/images/v1/{image_id}` Fetch details for a single image. ### Parameters - `imageId: string` Image unique identifier. - `params: V1GetParams` - `account_id: string` Account identifier tag. ### Returns - `Image` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const image = await client.images.v1.get('image_id', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(image.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "id", "creator": "107b9558-dd06-4bbd-5fef-9c2c16bb7900", "filename": "logo.png", "meta": { "key": "value" }, "requireSignedURLs": true, "uploaded": "2014-01-02T02:20:00.123Z", "variants": [ "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/thumbnail", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/hero", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/original" ] }, "success": true } ``` ## Upload an image `client.images.v1.create(V1CreateParamsparams, RequestOptionsoptions?): Image` **post** `/accounts/{account_id}/images/v1` Upload an image with up to 10 Megabytes using a single HTTP POST (multipart/form-data) request. An image can be uploaded by sending an image file or passing an accessible to an API url. ### Parameters - `params: V1CreateParams` - `account_id: string` Path param: Account identifier tag. - `id?: string` Body param: An optional custom unique identifier for your image. - `creator?: string` Body param: Can set the creator field with an internal user ID. - `file?: Uploadable` Body param: An image binary data. Only needed when type is uploading a file. - `metadata?: unknown` Body param: User modifiable key-value store. Can use used for keeping references to another system of record for managing images. - `requireSignedURLs?: boolean` Body param: Indicates whether the image requires a signature token for the access. - `url?: string` Body param: A URL to fetch an image from origin. Only needed when type is uploading from a URL. ### Returns - `Image` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const image = await client.images.v1.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); console.log(image.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "id", "creator": "107b9558-dd06-4bbd-5fef-9c2c16bb7900", "filename": "logo.png", "meta": { "key": "value" }, "requireSignedURLs": true, "uploaded": "2014-01-02T02:20:00.123Z", "variants": [ "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/thumbnail", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/hero", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/original" ] }, "success": true } ``` ## Update image `client.images.v1.edit(stringimageId, V1EditParamsparams, RequestOptionsoptions?): Image` **patch** `/accounts/{account_id}/images/v1/{image_id}` Update image access control. On access control change, all copies of the image are purged from cache. ### Parameters - `imageId: string` Image unique identifier. - `params: V1EditParams` - `account_id: string` Path param: Account identifier tag. - `creator?: string` Body param: Can set the creator field with an internal user ID. - `metadata?: unknown` Body param: User modifiable key-value store. Can be used for keeping references to another system of record for managing images. No change if not specified. - `requireSignedURLs?: boolean` Body param: Indicates whether the image can be accessed using only its UID. If set to `true`, a signed token needs to be generated with a signing key to view the image. Returns a new UID on a change. No change if not specified. ### Returns - `Image` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const image = await client.images.v1.edit('image_id', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(image.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "id", "creator": "107b9558-dd06-4bbd-5fef-9c2c16bb7900", "filename": "logo.png", "meta": { "key": "value" }, "requireSignedURLs": true, "uploaded": "2014-01-02T02:20:00.123Z", "variants": [ "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/thumbnail", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/hero", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/original" ] }, "success": true } ``` ## Delete image `client.images.v1.delete(stringimageId, V1DeleteParamsparams, RequestOptionsoptions?): V1DeleteResponse` **delete** `/accounts/{account_id}/images/v1/{image_id}` Delete an image on Cloudflare Images. On success, all copies of the image are deleted and purged from cache. ### Parameters - `imageId: string` Image unique identifier. - `params: V1DeleteParams` - `account_id: string` Account identifier tag. ### Returns - `V1DeleteResponse = unknown | string` - `unknown` - `string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const v1 = await client.images.v1.delete('image_id', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(v1); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": {}, "success": true } ``` ## Domain Types ### Image - `Image` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### V1 List Response - `V1ListResponse` - `images?: Array` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### V1 Delete Response - `V1DeleteResponse = unknown | string` - `unknown` - `string` # Keys ## List Signing Keys `client.images.v1.keys.list(KeyListParamsparams, RequestOptionsoptions?): KeyListResponse` **get** `/accounts/{account_id}/images/v1/keys` Lists your signing keys. These can be found on your Cloudflare Images dashboard. ### Parameters - `params: KeyListParams` - `account_id: string` Account identifier tag. ### Returns - `KeyListResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const keys = await client.images.v1.keys.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); console.log(keys.keys); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "keys": [ { "name": "default", "value": "Oix0bbNaT8Rge9PuyxUBrjI6zrgnsyJ5=" } ] }, "success": true } ``` ## Create a new Signing Key `client.images.v1.keys.update(stringsigningKeyName, KeyUpdateParamsparams, RequestOptionsoptions?): KeyUpdateResponse` **put** `/accounts/{account_id}/images/v1/keys/{signing_key_name}` Create a new signing key with specified name. Returns all keys available. ### Parameters - `signingKeyName: string` - `params: KeyUpdateParams` - `account_id: string` Account identifier tag. ### Returns - `KeyUpdateResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const key = await client.images.v1.keys.update('someKey', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(key.keys); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "keys": [ { "name": "default", "value": "Oix0bbNaT8Rge9PuyxUBrjI6zrgnsyJ5=" } ] }, "success": true } ``` ## Delete Signing Key `client.images.v1.keys.delete(stringsigningKeyName, KeyDeleteParamsparams, RequestOptionsoptions?): KeyDeleteResponse` **delete** `/accounts/{account_id}/images/v1/keys/{signing_key_name}` Delete signing key with specified name. Returns all keys available. When last key is removed, a new default signing key will be generated. ### Parameters - `signingKeyName: string` - `params: KeyDeleteParams` - `account_id: string` Account identifier tag. ### Returns - `KeyDeleteResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const key = await client.images.v1.keys.delete('someKey', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(key.keys); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "keys": [ { "name": "default", "value": "Oix0bbNaT8Rge9PuyxUBrjI6zrgnsyJ5=" } ] }, "success": true } ``` ## Domain Types ### Key - `Key` - `name?: string` Key name. - `value?: string` Key value. ### Key List Response - `KeyListResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. ### Key Update Response - `KeyUpdateResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. ### Key Delete Response - `KeyDeleteResponse` - `keys?: Array` - `name?: string` Key name. - `value?: string` Key value. # Stats ## Images usage statistics `client.images.v1.stats.get(StatGetParamsparams, RequestOptionsoptions?): Stat` **get** `/accounts/{account_id}/images/v1/stats` Fetch image statistics details for Cloudflare Images. The returned statistics detail storage usage, including the current image count vs this account's allowance. ### Parameters - `params: StatGetParams` - `account_id: string` Account identifier tag. ### Returns - `Stat` - `count?: Count` - `allowed?: number` Cloudflare Images allowed usage. - `current?: number` Cloudflare Images current usage. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const stat = await client.images.v1.stats.get({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); console.log(stat.count); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "count": { "allowed": 100000, "current": 1000 } }, "success": true } ``` ## Domain Types ### Stat - `Stat` - `count?: Count` - `allowed?: number` Cloudflare Images allowed usage. - `current?: number` Cloudflare Images current usage. # Variants ## List variants `client.images.v1.variants.list(VariantListParamsparams, RequestOptionsoptions?): Variant` **get** `/accounts/{account_id}/images/v1/variants` Lists existing variants. ### Parameters - `params: VariantListParams` - `account_id: string` Account identifier tag. ### Returns - `Variant` - `variants?: Variants` - `hero?: Hero` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const variant = await client.images.v1.variants.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(variant.variants); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "variants": { "hero": { "id": "hero", "options": { "fit": "scale-down", "height": 768, "metadata": "none", "width": 1366 }, "neverRequireSignedURLs": true } } }, "success": true } ``` ## Variant details `client.images.v1.variants.get(stringvariantId, VariantGetParamsparams, RequestOptionsoptions?): VariantGetResponse` **get** `/accounts/{account_id}/images/v1/variants/{variant_id}` Fetch details for a single variant. ### Parameters - `variantId: string` - `params: VariantGetParams` - `account_id: string` Account identifier tag. ### Returns - `VariantGetResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const variant = await client.images.v1.variants.get('hero', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(variant.variant); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "variant": { "id": "hero", "options": { "fit": "scale-down", "height": 768, "metadata": "none", "width": 1366 }, "neverRequireSignedURLs": true } }, "success": true } ``` ## Create a variant `client.images.v1.variants.create(VariantCreateParamsparams, RequestOptionsoptions?): VariantCreateResponse` **post** `/accounts/{account_id}/images/v1/variants` Specify variants that allow you to resize images for different use cases. ### Parameters - `params: VariantCreateParams` - `account_id: string` Path param: Account identifier tag. - `id: string` Body param - `options: Options` Body param: Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Body param: Indicates whether the variant can access an image without a signature, regardless of image access control. ### Returns - `VariantCreateResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const variant = await client.images.v1.variants.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', id: 'hero', options: { fit: 'scale-down', height: 768, metadata: 'none', width: 1366, }, }); console.log(variant.variant); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "variant": { "id": "hero", "options": { "fit": "scale-down", "height": 768, "metadata": "none", "width": 1366 }, "neverRequireSignedURLs": true } }, "success": true } ``` ## Update a variant `client.images.v1.variants.edit(stringvariantId, VariantEditParamsparams, RequestOptionsoptions?): VariantEditResponse` **patch** `/accounts/{account_id}/images/v1/variants/{variant_id}` Updating a variant purges the cache for all images associated with the variant. ### Parameters - `variantId: string` - `params: VariantEditParams` - `account_id: string` Path param: Account identifier tag. - `options: Options` Body param: Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Body param: Indicates whether the variant can access an image without a signature, regardless of image access control. ### Returns - `VariantEditResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const response = await client.images.v1.variants.edit('hero', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', options: { fit: 'scale-down', height: 768, metadata: 'none', width: 1366, }, }); console.log(response.variant); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "variant": { "id": "hero", "options": { "fit": "scale-down", "height": 768, "metadata": "none", "width": 1366 }, "neverRequireSignedURLs": true } }, "success": true } ``` ## Delete a variant `client.images.v1.variants.delete(stringvariantId, VariantDeleteParamsparams, RequestOptionsoptions?): VariantDeleteResponse` **delete** `/accounts/{account_id}/images/v1/variants/{variant_id}` Deleting a variant purges the cache for all images associated with the variant. ### Parameters - `variantId: string` - `params: VariantDeleteParams` - `account_id: string` Account identifier tag. ### Returns - `VariantDeleteResponse = unknown | string` - `unknown` - `string` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const variant = await client.images.v1.variants.delete('hero', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(variant); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": {}, "success": true } ``` ## Domain Types ### Variant - `Variant` - `variants?: Variants` - `hero?: Hero` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Variant Get Response - `VariantGetResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Variant Create Response - `VariantCreateResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Variant Edit Response - `VariantEditResponse` - `variant?: Variant` - `id: string` - `options: Options` Allows you to define image resizing sizes for different use cases. - `fit: "scale-down" | "contain" | "cover" | 2 more` The fit property describes how the width and height dimensions should be interpreted. - `"scale-down"` - `"contain"` - `"cover"` - `"crop"` - `"pad"` - `height: number` Maximum height in image pixels. - `metadata: "keep" | "copyright" | "none"` What EXIF data should be preserved in the output image. - `"keep"` - `"copyright"` - `"none"` - `width: number` Maximum width in image pixels. - `neverRequireSignedURLs?: boolean` Indicates whether the variant can access an image without a signature, regardless of image access control. ### Variant Delete Response - `VariantDeleteResponse = unknown | string` - `unknown` - `string` # Blobs ## Base image `client.images.v1.blobs.get(stringimageId, BlobGetParamsparams, RequestOptionsoptions?): Response` **get** `/accounts/{account_id}/images/v1/{image_id}/blob` Fetch base image. For most images this will be the originally uploaded file. For larger images it can be a near-lossless version of the original. ### Parameters - `imageId: string` Image unique identifier. - `params: BlobGetParams` - `account_id: string` Account identifier tag. ### Returns - `unnamed_schema_3 = Response` ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const blob = await client.images.v1.blobs.get('image_id', { account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(blob); const content = await blob.blob(); console.log(content); ``` # V2 ## List images V2 `client.images.v2.list(V2ListParamsparams, RequestOptionsoptions?): V2ListResponse` **get** `/accounts/{account_id}/images/v2` List up to 10000 images with up to 1000 results per page. Use the optional parameters below to get a specific range of images. Pagination is supported via continuation_token. **Metadata Filtering (Optional):** You can optionally filter images by custom metadata fields using the `meta.[]=` syntax. **Supported Operators:** - `eq` / `eq:string` / `eq:number` / `eq:boolean` - Exact match - `in` / `in:string` / `in:number` - Match any value in list (pipe-separated) **Metadata Filter Constraints:** - Maximum 5 metadata filters per request - Maximum 5 levels of nesting (e.g., `meta.first.second.third.fourth.fifth`) - Maximum 10 elements for list operators (`in`) - Supports string, number, and boolean value types **Examples:** ``` # List all images /images/v2 # Filter by metadata [eq] /images/v2?meta.status[eq:string]=active # Filter by metadata [in] /images/v2?meta.status[in]=pending|deleted|flagged # Filter by metadata [in:number] /images/v2?meta.ratings[in:number]=4|5 # Filter by nested metadata /images/v2?meta.region.name[eq]=eu-west # Combine metadata filters with creator /images/v2?meta.status[eq]=active&creator=user123 # Multiple metadata filters (AND logic) /images/v2?meta.status[eq]=active&meta.priority[eq:number]=5 ``` ### Parameters - `params: V2ListParams` - `account_id: string` Path param: Account identifier tag. - `continuation_token?: string | null` Query param: Continuation token to fetch next page. Passed as a query param when requesting List V2 api endpoint. - `creator?: string | null` Query param: Internal user ID set within the creator field. Setting to empty string "" will return images where creator field is not set - `meta?: Meta` Query param - `"[]"?: string` Optional metadata filter(s). Multiple filters can be combined with AND logic. **Operators:** - `eq`, `eq:string`, `eq:number`, `eq:boolean` - Exact match - `in`, `in:string`, `in:number` - Match any value in pipe-separated list **Examples:** - `meta.status[eq]=active` - `meta.priority[eq:number]=5` - `meta.enabled[eq:boolean]=true` - `meta.region[in]=us-east|us-west|eu-west` - `per_page?: number` Query param: Number of items per page - `sort_order?: "asc" | "desc"` Query param: Sorting order by upload time - `"asc"` - `"desc"` ### Returns - `V2ListResponse` - `continuation_token?: string | null` Continuation token to fetch next page. Passed as a query param when requesting List V2 api endpoint. - `images?: Array` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const v2s = await client.images.v2.list({ account_id: '023e105f4ecef8ad9ca31a8372d0c353' }); console.log(v2s.continuation_token); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "continuation_token": "continuation_token", "images": [ { "id": "id", "creator": "107b9558-dd06-4bbd-5fef-9c2c16bb7900", "filename": "logo.png", "meta": { "key": "value" }, "requireSignedURLs": true, "uploaded": "2014-01-02T02:20:00.123Z", "variants": [ "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/thumbnail", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/hero", "https://imagedelivery.net/MTt4OTd0b0w5aj/107b9558-dd06-4bbd-5fef-9c2c16bb7900/original" ] } ] }, "success": true } ``` ## Domain Types ### V2 List Response - `V2ListResponse` - `continuation_token?: string | null` Continuation token to fetch next page. Passed as a query param when requesting List V2 api endpoint. - `images?: Array` - `id?: string` Image unique identifier. - `creator?: string | null` Can set the creator field with an internal user ID. - `filename?: string` Image file name. - `meta?: unknown` User modifiable key-value store. Can be used for keeping references to another system of record for managing images. Metadata must not exceed 1024 bytes. - `requireSignedURLs?: boolean` Indicates whether the image can be a accessed only using it's UID. If set to true, a signed token needs to be generated with a signing key to view the image. - `uploaded?: string` When the media item was uploaded. - `variants?: Array` Object specifying available variants for an image. # Direct Uploads ## Create authenticated direct upload URL V2 `client.images.v2.directUploads.create(DirectUploadCreateParamsparams, RequestOptionsoptions?): DirectUploadCreateResponse` **post** `/accounts/{account_id}/images/v2/direct_upload` Direct uploads allow users to upload images without API keys. A common use case are web apps, client-side applications, or mobile devices where users upload content directly to Cloudflare Images. This method creates a draft record for a future image. It returns an upload URL and an image identifier. To verify if the image itself has been uploaded, send an image details request (accounts/:account_identifier/images/v1/:identifier), and check that the `draft: true` property is not present. ### Parameters - `params: DirectUploadCreateParams` - `account_id: string` Path param: Account identifier tag. - `id?: string` Body param: Optional Image Custom ID. Up to 1024 chars. Can include any number of subpaths, and utf8 characters. Cannot start nor end with a / (forward slash). Cannot be a UUID. - `creator?: string` Body param: Can set the creator field with an internal user ID. - `expiry?: string` Body param: The date after which the upload will not be accepted. Minimum: Now + 2 minutes. Maximum: Now + 6 hours. - `metadata?: unknown` Body param: User modifiable key-value store. Can be used for keeping references to another system of record, for managing images. - `requireSignedURLs?: boolean` Body param: Indicates whether the image requires a signature token to be accessed. ### Returns - `DirectUploadCreateResponse` - `id?: string` Image unique identifier. - `uploadURL?: string` The URL the unauthenticated upload can be performed to using a single HTTP POST (multipart/form-data) request. ### Example ```node import Cloudflare from 'cloudflare'; const client = new Cloudflare({ apiToken: process.env['CLOUDFLARE_API_TOKEN'], // This is the default and can be omitted }); const directUpload = await client.images.v2.directUploads.create({ account_id: '023e105f4ecef8ad9ca31a8372d0c353', }); console.log(directUpload.id); ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "id": "id", "uploadURL": "https://upload.imagedelivery.net/FxUufywByo0m2v3xhKSiU8/e22e9e6b-c02b-42fd-c405-6c32af5fe600" }, "success": true } ``` ## Domain Types ### Direct Upload Create Response - `DirectUploadCreateResponse` - `id?: string` Image unique identifier. - `uploadURL?: string` The URL the unauthenticated upload can be performed to using a single HTTP POST (multipart/form-data) request.