Skip to content
Start here

Update a variant

PATCH/accounts/{account_id}/images/v1/variants/{variant_id}

Updating a variant purges the cache for all images associated with the variant.

Security
API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Images Write
Path ParametersExpand Collapse
account_id: string

Account identifier tag.

maxLength32
variant_id: string
maxLength99
Body ParametersJSONExpand Collapse
options: object { fit, height, metadata, width }

Allows you to define image resizing sizes for different use cases.

fit: "scale-down" or "contain" or "cover" or 2 more

The fit property describes how the width and height dimensions should be interpreted.

One of the following:
"scale-down"
"contain"
"cover"
"crop"
"pad"
height: number

Maximum height in image pixels.

minimum1
metadata: "keep" or "copyright" or "none"

What EXIF data should be preserved in the output image.

One of the following:
"keep"
"copyright"
"none"
width: number

Maximum width in image pixels.

minimum1
neverRequireSignedURLs: optional boolean

Indicates whether the variant can access an image without a signature, regardless of image access control.

ReturnsExpand Collapse
errors: array of ResponseInfo { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional object { pointer }
pointer: optional string
messages: array of ResponseInfo { code, message, documentation_url, source }
code: number
minimum1000
message: string
documentation_url: optional string
source: optional object { pointer }
pointer: optional string
result: object { variant }
variant: optional object { id, options, neverRequireSignedURLs }
id: string
maxLength99
options: object { fit, height, metadata, width }

Allows you to define image resizing sizes for different use cases.

fit: "scale-down" or "contain" or "cover" or 2 more

The fit property describes how the width and height dimensions should be interpreted.

One of the following:
"scale-down"
"contain"
"cover"
"crop"
"pad"
height: number

Maximum height in image pixels.

minimum1
metadata: "keep" or "copyright" or "none"

What EXIF data should be preserved in the output image.

One of the following:
"keep"
"copyright"
"none"
width: number

Maximum width in image pixels.

minimum1
neverRequireSignedURLs: optional boolean

Indicates whether the variant can access an image without a signature, regardless of image access control.

success: true

Whether the API call was successful

Update a variant

curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/images/v1/variants/$VARIANT_ID \
    -X PATCH \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    -d '{
          "options": {
            "fit": "scale-down",
            "height": 768,
            "metadata": "none",
            "width": 1366
          },
          "neverRequireSignedURLs": true
        }'
{
  "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
}
Returns Examples
{
  "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
}