> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/cloudflare/cloudflare-typescript/llms.txt
> Use this file to discover all available pages before exploring further.

# Images

> Upload and manage images with Cloudflare Images

Cloudflare Images provides image storage, resizing, optimization, and delivery. The Images API allows you to upload and manage images programmatically.

## Upload an image

Upload an image with up to 10 megabytes using a single HTTP POST request.

```typescript theme={null}
const image = await client.images.v1.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  file: imageFile,
});
```

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="file" type="File">
  The image file to upload
</ParamField>

<ParamField path="url" type="string">
  A URL to an accessible image to upload (alternative to file upload)
</ParamField>

<ParamField path="id" type="string">
  An optional custom unique identifier for your image
</ParamField>

<ParamField path="requireSignedURLs" type="boolean">
  Whether the image can only be accessed using a signed URL
</ParamField>

<ParamField path="metadata" type="object">
  User modifiable key-value metadata. Must not exceed 1024 bytes.
</ParamField>

<ResponseField name="id" type="string">
  Image unique identifier
</ResponseField>

<ResponseField name="filename" type="string">
  Image file name
</ResponseField>

<ResponseField name="uploaded" type="string">
  When the image was uploaded
</ResponseField>

<ResponseField name="requireSignedURLs" type="boolean">
  Whether signed URLs are required to access the image
</ResponseField>

<ResponseField name="variants" type="array">
  Available variants for the image
</ResponseField>

<ResponseField name="meta" type="object">
  User-defined metadata
</ResponseField>

## List images (v1)

<Warning>
  This endpoint is deprecated. Use the v2 list endpoint instead.
</Warning>

List up to 100 images with one request.

```typescript theme={null}
for await (const image of client.images.v1.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
})) {
  console.log(image.id, image.filename);
}
```

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="page" type="number">
  Page number of paginated results
</ParamField>

<ParamField path="per_page" type="number">
  Number of items per page (max 100)
</ParamField>

## List images (v2)

List up to 10,000 images with continuation token support.

```typescript theme={null}
const response = await client.images.v2.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  per_page: 1000,
});

for (const image of response.images || []) {
  console.log(image.id, image.filename);
}

// Fetch next page if continuation token exists
if (response.continuation_token) {
  const nextPage = await client.images.v2.list({
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    continuation_token: response.continuation_token,
  });
}
```

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="per_page" type="number">
  Number of items per page (max 10,000)
</ParamField>

<ParamField path="continuation_token" type="string">
  Continuation token for fetching the next page
</ParamField>

<ParamField path="creator" type="string">
  Filter by creator ID. Use empty string "" for images without a creator.
</ParamField>

<ParamField path="sort_order" type="string">
  Sorting order by upload time: `asc` or `desc`
</ParamField>

<ResponseField name="images" type="array">
  Array of image objects
</ResponseField>

<ResponseField name="continuation_token" type="string">
  Token to fetch the next page (null if no more pages)
</ResponseField>

## Get an image

Fetch details for a single image.

```typescript theme={null}
const image = await client.images.v1.get(
  'image_id',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
);
```

<ParamField path="imageId" type="string" required>
  The image identifier
</ParamField>

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

## Update an image

Update image access control or metadata.

```typescript theme={null}
const image = await client.images.v1.edit(
  'image_id',
  {
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    requireSignedURLs: true,
    metadata: {
      alt: 'Product image',
      category: 'products',
    },
  },
);
```

<ParamField path="imageId" type="string" required>
  The image identifier
</ParamField>

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="requireSignedURLs" type="boolean">
  Whether the image requires signed URLs for access
</ParamField>

<ParamField path="metadata" type="object">
  User modifiable metadata. Must not exceed 1024 bytes.
</ParamField>

## Delete an image

Delete an image from Cloudflare Images. All copies of the image are deleted and purged from cache.

```typescript theme={null}
await client.images.v1.delete(
  'image_id',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
);
```

<ParamField path="imageId" type="string" required>
  The image identifier
</ParamField>

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

## Direct upload

Create a unique one-time upload URL for direct user uploads.

```typescript theme={null}
const upload = await client.images.v2.directUploads.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  requireSignedURLs: true,
  metadata: {
    user: 'user_123',
  },
});

console.log(upload.uploadURL); // Use this URL to upload the image
```

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="requireSignedURLs" type="boolean">
  Whether uploaded images require signed URLs
</ParamField>

<ParamField path="metadata" type="object">
  Metadata to associate with the uploaded image
</ParamField>

<ParamField path="expiry" type="string">
  Expiration time for the upload URL (RFC 3339)
</ParamField>

<ParamField path="id" type="string">
  Custom identifier for the image
</ParamField>

<ResponseField name="uploadURL" type="string">
  The unique upload URL for direct upload
</ResponseField>

<ResponseField name="id" type="string">
  The image identifier that will be assigned
</ResponseField>

## Image variants

Manage image variants to create different sizes and formats.

```typescript theme={null}
// Create a variant
const variant = await client.images.v1.variants.create({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  id: 'thumbnail',
  options: {
    fit: 'cover',
    width: 200,
    height: 200,
  },
});

// List variants
const variants = await client.images.v1.variants.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

// Get a variant
const variant = await client.images.v1.variants.get(
  'thumbnail',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
);

// Update a variant
await client.images.v1.variants.edit(
  'thumbnail',
  {
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    options: {
      fit: 'contain',
      width: 300,
      height: 300,
    },
  },
);

// Delete a variant
await client.images.v1.variants.delete(
  'thumbnail',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
);
```

## Signing keys

Manage signing keys for signed URL tokens.

```typescript theme={null}
// List signing keys
const keys = await client.images.v1.keys.list({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

// Update a signing key
await client.images.v1.keys.update(
  'key_id',
  {
    account_id: '023e105f4ecef8ad9ca31a8372d0c353',
    name: 'Production Key',
  },
);

// Delete a signing key
await client.images.v1.keys.delete(
  'key_id',
  { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
);
```

## Get usage statistics

Get statistics about image usage.

```typescript theme={null}
const stats = await client.images.v1.stats.get({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
});

console.log(`Images: ${stats.count.current} / ${stats.count.allowed}`);
```

## Get base image

Get the base image data without transformations.

```typescript theme={null}
const blob = await client.images.v1.blobs.get({
  account_id: '023e105f4ecef8ad9ca31a8372d0c353',
  image_id: 'image_id',
});
```

<ParamField path="account_id" type="string" required>
  The account identifier
</ParamField>

<ParamField path="image_id" type="string" required>
  The image identifier
</ParamField>
