Skip to main content
Technology & EngineeringStorage Services166 lines

Imagekit

Build with ImageKit for real-time image optimization and delivery. Use this skill when the project needs to integrate ImageKit for image uploads, URL-based transformations, automatic format optimization, video optimization, or a Cloudinary alternative with simpler pricing. Covers the ImageKit SDK, URL transformations, upload API, and Next.js integration.

Quick Summary28 lines
You are a media specialist who integrates ImageKit into projects. ImageKit is a
real-time image and video optimization service with URL-based transformations,
automatic format negotiation, and a global CDN — similar to Cloudinary with
simpler, usage-based pricing.

## Key Points

- Always use `f-auto,q-auto` for automatic format and quality optimization
- Use `fo-auto` (focus auto) for smart cropping based on content
- Use the URL endpoint as a CDN origin — images are cached globally
- Use client-side uploads with server-generated auth tokens
- Organize files in folders and use tags for management
- Use named transformations for commonly used transform combinations
- Serving original unoptimized images — always use `q-auto,f-auto`
- Uploading already-transformed images — upload originals, transform via URL
- Exposing the private key to the client — use auth parameters for uploads
- Not using lazy loading for below-the-fold images
- Generating transformation URLs client-side without the SDK — error-prone

## Quick Example

```bash
npm install imagekitio-next  # For Next.js
# or
npm install imagekit         # Node SDK
```
skilldb get storage-services-skills/imagekitFull skill: 166 lines
Paste into your CLAUDE.md or agent config

ImageKit Integration

You are a media specialist who integrates ImageKit into projects. ImageKit is a real-time image and video optimization service with URL-based transformations, automatic format negotiation, and a global CDN — similar to Cloudinary with simpler, usage-based pricing.

Core Philosophy

URL-based transformations

ImageKit transforms images through URL parameters. Append width, height, crop, quality, and format parameters to any image URL. Transformations are processed and cached at the CDN edge on first request.

Automatic optimization

ImageKit's f-auto parameter serves the best format (WebP, AVIF) based on browser support. Combined with q-auto for quality, it delivers optimized images without manual format management.

Setup

Install

npm install imagekitio-next  # For Next.js
# or
npm install imagekit         # Node SDK

Initialize (Node SDK)

import ImageKit from 'imagekit';

const imagekit = new ImageKit({
  publicKey: process.env.IMAGEKIT_PUBLIC_KEY!,
  privateKey: process.env.IMAGEKIT_PRIVATE_KEY!,
  urlEndpoint: process.env.IMAGEKIT_URL_ENDPOINT!, // https://ik.imagekit.io/your_id
});

Next.js provider

import { ImageKitProvider, IKImage, IKUpload } from 'imagekitio-next';

function App({ children }) {
  return (
    <ImageKitProvider urlEndpoint={process.env.NEXT_PUBLIC_IMAGEKIT_URL_ENDPOINT!}>
      {children}
    </ImageKitProvider>
  );
}

Key Techniques

URL transformations

// Generate transformed URL
const url = imagekit.url({
  path: '/posts/hero.jpg',
  transformation: [{
    width: '800',
    height: '400',
    crop: 'maintain_ratio',
    focus: 'auto',
    quality: 'auto',
    format: 'auto',
  }],
});
// https://ik.imagekit.io/your_id/tr:w-800,h-400,c-maintain_ratio,fo-auto,q-auto,f-auto/posts/hero.jpg

// Thumbnail
const thumb = imagekit.url({
  path: '/posts/hero.jpg',
  transformation: [{ width: '150', height: '150', crop: 'at_max' }],
});

// Raw URL pattern
// https://ik.imagekit.io/your_id/tr:w-800,h-400/posts/hero.jpg

Upload

// Server-side upload
const result = await imagekit.upload({
  file: buffer, // or base64 string, or URL
  fileName: 'hero.jpg',
  folder: '/posts/',
  tags: ['blog', 'hero'],
});
// result.url, result.fileId, result.name

// Client-side upload (get auth params from server)
// API route
export async function GET() {
  const authParams = imagekit.getAuthenticationParameters();
  return Response.json(authParams);
}

Next.js components

import { IKImage, IKUpload } from 'imagekitio-next';

// Optimized image
function HeroImage({ path }: { path: string }) {
  return (
    <IKImage
      path={path}
      transformation={[{ width: '1200', height: '630', crop: 'maintain_ratio', quality: 'auto', format: 'auto' }]}
      alt="Hero"
      loading="lazy"
    />
  );
}

// Upload component
function Uploader({ onSuccess }: { onSuccess: (url: string) => void }) {
  return (
    <IKUpload
      fileName="upload"
      folder="/uploads/"
      onSuccess={(res) => onSuccess(res.url)}
      onError={(err) => console.error(err)}
    />
  );
}

File management

// List files
const files = await imagekit.listFiles({ path: '/posts/', limit: 50 });

// Delete
await imagekit.deleteFile(fileId);

// Get file details
const details = await imagekit.getFileDetails(fileId);

Best Practices

  • Always use f-auto,q-auto for automatic format and quality optimization
  • Use fo-auto (focus auto) for smart cropping based on content
  • Use the URL endpoint as a CDN origin — images are cached globally
  • Use client-side uploads with server-generated auth tokens
  • Organize files in folders and use tags for management
  • Use named transformations for commonly used transform combinations

Anti-Patterns

  • Serving original unoptimized images — always use q-auto,f-auto
  • Uploading already-transformed images — upload originals, transform via URL
  • Exposing the private key to the client — use auth parameters for uploads
  • Not using lazy loading for below-the-fold images
  • Generating transformation URLs client-side without the SDK — error-prone

Install this skill directly: skilldb add storage-services-skills

Get CLI access →

Related Skills

Tigris

Build with Tigris for globally distributed S3-compatible object storage. Use this skill when the project needs to integrate Tigris for file uploads, presigned URLs, automatic geo-replication, or edge-cached storage with zero egress fees. Covers the S3 API compatibility, Fly.io integration, and global caching patterns.

Storage Services168L

Uploadthing

Build with UploadThing for file uploads in Next.js and React. Use this skill when the project needs to integrate UploadThing for type-safe file uploads, presigned URLs, file validation, image/video uploads, or a developer-friendly upload service. Covers UploadThing route handlers, React components, file validation, and hooks.

Storage Services222L

Vercel Blob

Build with Vercel Blob for file storage in Next.js. Use this skill when the project needs to integrate Vercel Blob for file uploads, image storage, or serverless-friendly object storage on Vercel. Covers the Vercel Blob SDK, client uploads, server uploads, and file management.

Storage Services157L

AWS S3

Build with AWS S3 for object storage. Use this skill when the project needs to integrate Amazon S3 for file uploads, presigned URLs, static assets, backups, or CDN origin storage. Covers the AWS SDK v3, presigned URLs, multipart uploads, bucket policies, and CloudFront integration.

Storage Services204L

Backblaze B2

Build with Backblaze B2 for low-cost S3-compatible object storage. Use this skill when the project needs to integrate Backblaze B2 for file uploads, presigned URLs, lifecycle rules, or budget-friendly storage with Cloudflare CDN integration. Covers the S3-compatible API, native B2 API, and cost-optimization patterns.

Storage Services206L

Cloudflare R2

Build with Cloudflare R2 for S3-compatible object storage with zero egress fees. Use this skill when the project needs to integrate R2 for file uploads, presigned URLs, public buckets, Workers integration, or cost-effective storage without egress charges. Covers the S3 API compatibility, Workers bindings, and R2 patterns.

Storage Services172L