---
title: "Cloudflare Images - Image Optimization & Delivery Platform"
description: "Streamlined image infrastructure built for scale. Global low-latency delivery, resizing, AI-powered optimization and background removal, and integrated with Cloudflare services for complete image workflows."
url: "https://www.cloudflare.com/products/images"
---

# Images

> Cloudflare Images helps teams build scalable, reliable media pipelines to store, optimize, and deliver images. Use Images to save time, engineering effort, and infrastructure costs.

## Key Features

- Automatic format conversion
- Responsive sizing
- Global CDN delivery
- Workers AI integration
- On-demand transformations
- WebP/AVIF support
- Image variants

## Benefits

### Global Low-Latency Delivery

Leverages Cloudflare's CDN to serve images fast, anywhere in the world with optimized formats and responsive sizing.

### Integrated with Cloudflare Services

Works seamlessly with Workers, Access, and other tools for full programmability and workflow control.

### AI-Powered Optimization

Automatically optimize images for different devices and formats, with AI-powered enhancements and transformations.

## Use Cases

### Deliver optimal formats

Automatically serve the most optimal format for the requesting browser (WebP, AVIF, JPEG) with intelligent format selection.

### AI image generation workflows

Optimize AI-generated images before storage or delivery — especially when using Workers and Workers AI for seamless integration.

### Multi-layered cache pipelines

Build cache-first media pipelines that check cache and R2 before transforming images on the fly for maximum efficiency.

### Responsive image delivery

Generate responsive images with srcset attributes, URL rewrites, and query parameters for perfect display across all devices.

## Code Examples

### Upload and optimize images

Upload images and serve them optimized with automatic format conversion and responsive sizing.

```typescript
export default {
  async fetch(request, env): Promise<Response> {
    if (request.method !== 'POST') {
      return new Response('Send a multipart/form-data POST with a "file" field', { status: 405 });
    }

    // Forward the incoming multipart upload straight to the Images API.
    // Content-Type must be preserved so the multipart boundary is parsed correctly.
    const uploadResponse = await fetch(
      `https://api.cloudflare.com/client/v4/accounts/${env.ACCOUNT_ID}/images/v1`,
      {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${env.CLOUDFLARE_API_TOKEN}`,
          'Content-Type': request.headers.get('Content-Type') ?? '',
        },
        body: request.body,
      }
    );

    const { success, result, errors } = await uploadResponse.json();
    if (!success) {
      return Response.json({ errors }, { status: 502 });
    }

    // Serve the optimized image via a predefined variant (e.g. "public").
    // For dynamic params like w=800,format=auto, enable Flexible Variants.
    const optimizedUrl = `https://imagedelivery.net/${env.DELIVERY_HASH}/${result.id}/public`;
    return Response.redirect(optimizedUrl, 302);
  },
};
```

### AI-Generated Image Optimization

Generate images with Workers AI and automatically optimize them for delivery. This example shows how to create an image with AI, store it in Images, and serve it with automatic format optimization.

```typescript
export interface Env {
  AI: Ai;
  CLOUDFLARE_API_TOKEN: string;
  CLOUDFLARE_ACCOUNT_ID: string;
  DELIVERY_HASH: string;
}

export default {
  async fetch(request, env): Promise<Response> {
    // Generate image with Workers AI
    const stream = await env.AI.run("@cf/lykon/dreamshaper-8-lcm", {
      prompt: "A beautiful sunset over mountains",
    });
    const bytes = await new Response(stream).bytes();

    // Upload to Cloudflare Images
    const formData = new FormData();
    formData.append("file", new File([bytes], "image.jpg"));

    const uploadResponse = await fetch(
      `https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACCOUNT_ID}/images/v1`,
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${env.CLOUDFLARE_API_TOKEN}`,
        },
        body: formData,
      },
    );

    const uploadResult = (await uploadResponse.json()) as {
      success: boolean;
      result: { id: string } | null;
      errors: Array<{ code: number; message: string }>;
    };

    if (!uploadResult.success || !uploadResult.result) {
      console.error("Image upload failed:", JSON.stringify(uploadResult, null, 2));
      return new Response(
        JSON.stringify({
          error: "Image upload failed",
          status: uploadResponse.status,
          details: uploadResult,
        }),
        {
          status: 500,
          headers: { "content-type": "application/json" },
        },
      );
    }

    const imageId = uploadResult.result.id;

    // Return optimized image URL (requires flexible variants enabled on the account)
    const optimizedUrl = `https://imagedelivery.net/${env.DELIVERY_HASH}/${imageId}/w=1200,h=800,format=auto,quality=85`;

    return new Response(
      JSON.stringify({
        imageUrl: optimizedUrl,
        originalId: imageId,
      }),
      {
        headers: { "content-type": "application/json" },
      },
    );
  },
} satisfies ExportedHandler<Env>;
```

## Resources

- [Full Documentation](https://developers.cloudflare.com/images): Complete technical documentation
- [Get Started](https://dash.cloudflare.com/sign-up): Sign up and start building
- [Pricing](/plans.md): See pricing details

## Related Products

- [RealtimeKit](/products/realtime.md): Live comms
- [Stream](/products/stream.md): Video streaming

---

*This is a markdown version of [https://www.cloudflare.com/products/images](https://www.cloudflare.com/products/images) for AI/LLM consumption.*
