imgapi docs
Docs / Headless API

Headless API Reference

If you prefer to build your own custom drag-and-drop UI, you can use the headless API Client provided by imgapi to securely interface with the edge servers.

Using the Client Library

In your main application, import the uploadToExtUtil function. You can copy the src/lib/client/media-client.ts file directly into your own project.

import { uploadToExtUtil, commitExtUtilAsset } from './media-client';

async function handleImageDrop(file) {
  const result = await uploadToExtUtil({
    file: file,
    userId: 123,
    assetType: 'article_inline',
    projectId: 'my_blog_platform',
    apiBaseUrl: 'https://imgapi.avadhya.in'
  });

  if (result.error) {
    alert("Upload failed: " + result.error);
    return;
  }

  const { object_key, cdn_url } = result;
  console.log("Uploaded! URL:", cdn_url);

  // Phase 3: Commit the asset to prevent orphan cleanup
  await commitExtUtilAsset(object_key, 'articles', articleId, 123, 'https://imgapi.avadhya.in');
}

REST API Details

The client library wraps these two core endpoints. Use this reference if you are building your own client from scratch in another language (like Python or Swift).

EndpointMethodPurpose
/api/v1/media/upload-tokenPOSTRequests a short-lived, signed token for an upload.
/upload/[...key]PUTStreams the raw binary directly into Cloudflare R2 using the signed token.