# Extract the colours of a garment

> Read a garment's colours from its image, with their Pantone matches, largest share first. Delivered as a palette image with the colours in its data.

**Endpoint:** `POST https://api.refabric.com/v1/tasks/image.extract_colours` · **Task:** `image.extract_colours` · **Scope:** `tasks:run` · **Category:** Production prep

Send an image of a garment and get its colours back, the largest share first, each with its Pantone code when one is known, together with a palette chart image. If the image is one of your designs, the colours are also saved on that design.

## Quick start

```python
import os
import time
import requests

headers = {"Authorization": f"Key {os.environ['REFABRIC_API_KEY']}"}

job = requests.post(
    "https://api.refabric.com/v1/tasks/image.extract_colours",
    headers=headers,
    json={
        "image": "art:9f3c01",
    },
).json()
print(job["job_id"])

while True:
    status = requests.get(job["status_url"], headers=headers).json()
    if status["lifecycle"] == "terminal":
        break
    time.sleep(5)

print(requests.get(job["result_url"], headers=headers).json())
```

```javascript
const headers = {
  Authorization: `Key ${process.env.REFABRIC_API_KEY}`,
  "Content-Type": "application/json",
};

const job = await fetch("https://api.refabric.com/v1/tasks/image.extract_colours", {
  method: "POST",
  headers,
  body: JSON.stringify({
    "image": "art:9f3c01"
  }),
}).then((r) => r.json());
console.log(job.job_id);

let status = job;
while (status.lifecycle !== "terminal") {
  await new Promise((r) => setTimeout(r, 5000));
  status = await fetch(job.status_url, { headers }).then((r) => r.json());
}

console.log(await fetch(job.result_url, { headers }).then((r) => r.json()));
```

```bash
curl -X POST "https://api.refabric.com/v1/tasks/image.extract_colours" \
  -H "Authorization: Key $REFABRIC_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Prefer: wait=60" \
  -d '{"image":"art:9f3c01"}'
```

## Input schema

- `image` (string, _required_, pattern: ^(https://|art:|file:).+$) — The garment image to read its colours from, as one string: a URL, a file from an earlier result (`art:…` or its url) or an upload (`file:…`). If it is an image of one of your designs, the result is also saved on that design.
  Example: `art:9f3c01`

## Required-fields example

```json
{
  "image": "art:9f3c01"
}
```

## Full example

```json
{
  "image": "art:9f3c01"
}
```

## Output schema

- `files` (array<object>, _optional_) — One file: the palette chart (`image/*`), with the colours in `data`. Pass a colour on unchanged wherever a colour is taken (`moodboard.create`, `brand_kit.create`).
  - `data` (object, _optional_) — The garment's palette.
    - `colours` (array<object>, _optional_) — The garment's colours, the largest share first.
      - `hex` (string, _required_, pattern: ^#[0-9A-Fa-f]{6}$) — The colour as #RRGGBB, like "#E8D9C4".
      - `name` (string, _optional_) — A name for the colour.
      - `pantone` (string, _optional_) — Its Pantone code, when known.

## Response example

```json
{
  "job_id": "5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968",
  "lifecycle": "queued",
  "status_url": "http://v3-api.refabric.com/v1/jobs/5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968",
  "result_url": "http://v3-api.refabric.com/v1/jobs/5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968/result",
  "cancel_url": "http://v3-api.refabric.com/v1/jobs/5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968/cancel"
}
```

## Result example

```json
{
  "job_id": "5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968",
  "files": [
    {
      "file": "art:a1b2c4",
      "url": "https://files.example.com/image.extract_colours/1.png",
      "media_type": "image/png",
      "task": "image.extract_colours",
      "job_id": "5f0c2a1e9b8d4c7a8e6f1d2c3b4a5968",
      "created_at": "2026-10-01T09:30:00Z",
      "data": {
        "colours": [
          {
            "hex": "#E8D9C4",
            "name": "Bleached Sand",
            "pantone": "13-1008 TCX"
          },
          {
            "hex": "#2B2F36"
          },
          {
            "hex": "#F4F1EA",
            "name": "Snow White",
            "pantone": "11-0602 TCX"
          }
        ]
      }
    }
  ],
  "has_more": false
}
```

The file is the palette chart; `data.colours` is largest share first. The image is one of your designs, so the palette is also saved on that design's production details.

## Built for

- A garment's palette for a tech pack
- Colours to pass on to a moodboard or a brand kit
- Pantone references for production

## What you get

- One file: the palette chart image.
- `data.colours`: the garment's colours, the largest share first, one per hex.

## Specs

- **Input formats:** Images, each one string: a URL, an upload (`file:…`) or a file from an earlier result (`art:…`). Upload types and sizes: `GET /v1/meta` `limits.upload`.
- **Input count:** `image`: one
- **Output format:** Files: each one line with its `url` and its `media_type`, in the job's result.
- **Outputs per job:** One file per job.

## Choosing a task

- Use this when you only need the garment's colours. Use `image.extract_materials` when you need its fabrics, trims and components too.

## Errors

- `field_not_accepted`
- `invalid_request`
- `not_found`
- `permission_denied`
- `content_refused`
- `processing_failed`

## Related

- `moodboard.create` — It runs after: it takes this task's result.
- `brand_kit.create` — It runs after: it takes this task's result.
- `image.extract_materials` — It does a neighbouring job.

## For agents and code generation

- https://api.refabric.com/v1/tasks/image.extract_colours/llms.txt
- https://api.refabric.com/v1/tasks/image.extract_colours/openapi.json
- GET https://api.refabric.com/v1/tasks/image.extract_colours
