## Photo try-on API

[Open the photo try-on tester ↗](https://platform.ikawn.com/photo-test.html) to upload a person photo and product photo with your API key.

Create a still try-on image from a person photo and a product photo, or edit a single source photo using instructions. Use your existing platform API key on your backend. This endpoint is hosted at `https://platform.ikawn.com/v1/images/try-on`, separately from the live-video API.

| Resolution | Output | Credits per image |
| --- | --- | --- |
| 720p | 720 × 1280 JPEG | 3 |
| 1080p | 1080 × 1920 JPEG | 5 |

Credits are reserved before generation and charged only for a successful image. Failed or timed-out jobs restore reserved credits. Video and photo generation share your account balance. 2K and 4K are not offered in this release.

### Create an image

Send `Authorization: Bearer YOUR_API_KEY`, `Content-Type: application/json`, and a unique `Idempotency-Key` (8–128 letters, digits, dots, underscores, colons or hyphens). Reuse the same idempotency key and identical payload when retrying; a different payload returns 409.

The JSON fields are `person_image`, `product_image` (raw base64, without a data-URL prefix), and `resolution` (`720p` or `1080p`). JPEG, PNG and static WebP are accepted. Each input must be at most 1.5 MiB, at least 128 pixels on each side, and no more than 12 megapixels. The JSON body must be under 4 MiB. Input images are reduced to fit 1536 × 1536 when necessary.

### Category and additional instructions

Set `category` to `clothing` (default), `eyewear`, `wigs`, `jewellery`, `headwear`, `footwear`, `accessories`, or `editing`. The server automatically builds category-specific instructions. Try-on modes preserve product details and the person’s appearance; editing mode follows your requested changes and preserves unrelated areas. Category selection does not change the credit price.

Optionally set `prompt` to up to 500 characters of fit, styling or placement preferences, such as “Place the bag on the left shoulder.” These preferences supplement the category instructions. Leave it out for the default try-on treatment. In editing mode, a non-blank prompt is required. Unknown categories or invalid prompts return 400 before reserving credits. Changing the category or instructions requires a new idempotency key.

Existing integrations may continue sending `garment_image` instead of `product_image`; send exactly one of these fields for try-on, or optionally one as a visual reference for editing. Requests without a category default to clothing. Job receipts include the selected category; customer instructions are kept with the temporary inputs and are not returned in history.

| Category | Recommended person photo |
| --- | --- |
| Clothing | The intended garment area visible |
| Eyewear | Clear face, eyes, nose and ears |
| Wigs / headwear | Full head and hairline, with space above |
| Jewellery | Clear view of the ears, neck, wrist or hand |
| Footwear | Feet and ground visible |
| Accessories | The intended placement visible |
| Editing | One source photo; optional second reference |



```
import { readFile, writeFile } from 'node:fs/promises';
import { randomUUID } from 'node:crypto';
const base = 'https://platform.ikawn.com/v1/images/try-on';
const headers = { Authorization: 'Bearer ' + process.env.IKAWN_API_KEY };
const response = await fetch(base, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json',
    'Idempotency-Key': randomUUID() },
  body: JSON.stringify({
    person_image: (await readFile('person.jpg')).toString('base64'),
    product_image: (await readFile('product.jpg')).toString('base64'),
    category: 'clothing',
    prompt: 'Tuck the shirt in', // Optional fit or placement instructions
    resolution: '720p'
  })
});
if (!response.ok) throw new Error(await response.text());
let job = await response.json();
const deadline = Date.now() + 150_000;
while (['queued', 'running'].includes(job.status)) {
  if (Date.now() > deadline) throw new Error('Polling timed out; check job status later');
  await new Promise(resolve => setTimeout(resolve, 1500));
  const status = await fetch(base + '/' + job.id, { headers });
  if (!status.ok) throw new Error(await status.text());
  job = await status.json();
}
if (job.status !== 'succeeded') throw new Error(job.error || 'Generation failed');
const image = await fetch(base + '/' + job.id + '/image', { headers });
if (!image.ok) throw new Error(await image.text());
await writeFile('try-on.jpg', Buffer.from(await image.arrayBuffer()));
```



### Instruction-based photo editing

Use the same endpoint with `category: "editing"`. Supply one source photo in `image` (or the backward-compatible `person_image` field), a required non-blank `prompt` of up to 500 characters, and `resolution`. The source can be a person, product or scene. Do not send both `image` and `person_image`. A second `product_image` is optional and acts as a visual reference. Omit it for a simple instruction-based edit.



```
{
  "category": "editing",
  "image": "BASE64_SOURCE_PHOTO",
  "prompt": "Replace the background with a softly lit studio. Keep the subject unchanged.",
  "resolution": "720p"
}
```



Editing uses the same job polling, authenticated downloads, idempotency and refund behavior as try-on. It costs 3 credits at 720p or 5 credits at 1080p. An absent or blank editing prompt returns `editing_prompt_required` (400) before credits are reserved. To make another edit, download the previous result and submit it as the next source with a new idempotency key. Edits are generative and may alter details; inspect results for your use case.

### Status and results

Creation returns 202 with a job ID, category, status and reserved credit count. Poll `GET /v1/images/try-on/{id}` every 1–2 seconds. States are `queued`, `running`, `succeeded` and `failed`. Download the JPEG from `GET /v1/images/try-on/{id}/image` using your API key. `GET /v1/images/try-on` lists your account’s latest 50 jobs.

Generated images are retained until you delete them from the Images page in your account. Image access requires authentication and is limited to the owning account and authorised staff. Deletion permanently removes the stored image; billing and audit records remain. Input files are deleted after completion, with remaining input files cleared by a one-day storage lifecycle rule. The Usage page shows photo jobs and credits charged.

### Playground and saved images

Open the [Photo playground](https://platform.ikawn.com/playground) after signing in. Choose sample photos or upload your own, select a category and quality, then generate. No API key is needed in the playground. It uses the same account wallet: 3 credits for 720p or 5 credits for 1080p, charged only on success. The [Images page](https://platform.ikawn.com/images) includes both API and playground results, with download and permanent deletion controls. Playground generations are labelled Playground; API generations show the key name.

### Capacity and quality

Photo generation is currently single-job capacity. A busy worker returns 429 before reserving credits; retry after a short delay. Creation is limited to 10 requests per minute per account, with 120 total photo API requests per minute per account. An unavailable worker returns 503. Jobs time out after 120 seconds and restore credits.

Use clear person and product photos with the intended placement visible. Category presets guide generation; quality across categories has not yet been independently benchmarked. Generated results can alter product details, fit, pose or facial details; evaluate fidelity for your use case. This is an image editing service, not a measurement or fit guarantee. Processing time varies with network transfer and service load.
