Image dominant color

$0.003 per call · USDC via x402 · POST /api/image-dominant-color

Extract the dominant colors of an image as a palette of hex values with pixel ratios. Send POST /api/image-dominant-color with no required fields (3 optional) and pay $0.003 per call over x402 or MPP (there is no free tier). It returns a JSON object with width, height, sampled and colors.

Send a public image URL or a base64 image, and optionally how many colors (1-10, default 5). Deterministic bucketed quantization; transparent pixels are ignored.

Category: Web & documents · Tags: image color palette dominant hex

TRY IN PLAYGROUND →

Parameters

NameTypeRequiredDescription
urlstringnopublic http(s) image URL (fetched server-side, 5MB cap)
imagestringnoalternative: base64 image, optionally a data: URL
colorsnumbernopalette size, 1-10 (default 5)

Example request

curl -i -X POST https://agent402.tools/api/image-dominant-color \
  -H "Content-Type: application/json" \
  -d '{"url":"https://agent402.tools/fixtures/sample-photo.jpg","colors":3}'

Without payment this returns HTTP 402 Payment Required with the exact price for image-dominant-color; any x402 v2 or MPP client pays it and retries.

Example response

{
  "width": 120,
  "height": 80,
  "sampled": 6144,
  "colors": [
    {
      "hex": "#1f7a8b",
      "rgb": [
        31,
        122,
        139
      ],
      "ratio": 0.5938
    },
    {
      "hex": "#df7a1e",
      "rgb": [
        223,
        122,
        30
      ],
      "ratio": 0.2813
    },
    {
      "hex": "#22223a",
      "rgb": [
        34,
        34,
        58
      ],
      "ratio": 0.0938
    }
  ]
}
FieldTypeAlways presentIn the example
widthnumberyes120
heightnumberyes80
samplednumberyes6144
colorsarray of objectsyes3 items in the example

From an MCP client

catalog.call {
  "slug": "image-dominant-color",
  "params": {
    "url": "https://agent402.tools/fixtures/sample-photo.jpg",
    "colors": 3
  }
}

The hosted connector at https://agent402.tools/mcp needs a payment for image-dominant-color; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/image-dominant-color", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "url": "https://agent402.tools/fixtures/sample-photo.jpg",
    "colors": 3
  }),
});

Related tools

Image convert

FREE w/ compute · or $0.005 · POST /api/image-convert

Convert an image between formats (PNG, JPEG, BMP). Send a base64 image and the target format; returns the converted imag…

Image crop

$0.002 · POST /api/image-crop

Crop an image to a pixel box, and/or rotate (90/180/270) and flip it - applied in that order. Send a public image URL or…

Image EXIF

$0.003 · POST /api/image-exif

Extract EXIF metadata from an image (camera make/model, timestamps, exposure, orientation, GPS). Send a public image URL…

Image resize

FREE w/ compute · or $0.001 · POST /api/image-resize

Resize an image to given pixel dimensions. Send a base64 PNG/JPEG/BMP and width and/or height (give one to scale proport…

Image thumbnail

FREE w/ compute · or $0.001 · POST /api/image-thumbnail

Make a square thumbnail of an image - scales and center-crops to NxN (default 128). Send a base64 image and optional siz…

Color convert

FREE w/ compute · or $0.001 · POST /api/color

Convert a color between hex, RGB, and HSL. Accepts "#1a2b3c", "rgb(26,43,60)", or "hsl(210,40%,17%)".