SDK examples

Private beta The v1 contract is implemented; the endpoints are not publicly reachable yet and access is by request. Details may still change during the beta.

The API is plain HTTPS and JSON; any HTTP client works. Official SDKs are planned and will be announced with the public release. Until then, these are complete examples of the upload, create and wait flow.

Replace <API_ORIGIN> with the API origin from your beta invitation and keep the key in an environment variable, never in code.

curl

PERSON=$(curl -s -X POST <API_ORIGIN>/v1/uploads \
  -H "Authorization: Bearer $OUTFIT_AI_API_KEY" \
  -F purpose=person -F file=@person.jpg | jq -r .id)
CLOTHING=$(curl -s -X POST <API_ORIGIN>/v1/uploads \
  -H "Authorization: Bearer $OUTFIT_AI_API_KEY" \
  -F purpose=clothing -F file=@shirt.png | jq -r .id)

FIT=$(curl -s -X POST <API_ORIGIN>/v1/fits \
  -H "Authorization: Bearer $OUTFIT_AI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d "{\"person\":{\"upload\":\"$PERSON\"},\"clothing\":[{\"upload\":\"$CLOTHING\"}],\"options\":{\"output\":\"image\",\"pose\":\"original\"}}" \
  | jq -r .id)

until [ "$(curl -s <API_ORIGIN>/v1/fits/$FIT -H "Authorization: Bearer $OUTFIT_AI_API_KEY" | jq -r .status)" = "completed" ]; do
  sleep 3
done

TypeScript

const API_ORIGIN = process.env.OUTFIT_AI_API_ORIGIN!;
const KEY = process.env.OUTFIT_AI_API_KEY!;

async function upload(purpose: 'person' | 'clothing', file: Blob): Promise<string> {
  const form = new FormData();
  form.set('purpose', purpose);
  form.set('file', file, purpose === 'person' ? 'person.jpg' : 'clothing.png');
  const res = await fetch(`${API_ORIGIN}/v1/uploads`, {
    method: 'POST',
    headers: { Authorization: `Bearer ${KEY}` },
    body: form,
  });
  if (!res.ok) throw new Error((await res.json()).error.code);
  return (await res.json()).id;
}

async function createFit(person: string, clothing: string) {
  const res = await fetch(`${API_ORIGIN}/v1/fits`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${KEY}`,
      'Idempotency-Key': crypto.randomUUID(),
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      person: { upload: person },
      clothing: [{ upload: clothing }],
      options: { output: 'image', pose: 'original' },
    }),
  });
  if (!res.ok) throw new Error((await res.json()).error.code);
  return res.json();
}

async function waitForFit(id: string) {
  for (let delay = 2000; ; delay = Math.min(delay * 1.5, 15000)) {
    const res = await fetch(`${API_ORIGIN}/v1/fits/${id}`, {
      headers: { Authorization: `Bearer ${KEY}` },
    });
    const fit = await res.json();
    if (fit.status === 'completed' || fit.status === 'failed') return fit;
    await new Promise((r) => setTimeout(r, delay));
  }
}

Python

import os, time, uuid, requests

API_ORIGIN = os.environ["OUTFIT_AI_API_ORIGIN"]
HEADERS = {"Authorization": f"Bearer {os.environ['OUTFIT_AI_API_KEY']}"}


def upload(purpose: str, path: str) -> str:
    with open(path, "rb") as f:
        r = requests.post(f"{API_ORIGIN}/v1/uploads", headers=HEADERS,
                          data={"purpose": purpose}, files={"file": f})
    r.raise_for_status()
    return r.json()["id"]


def create_fit(person: str, clothing: str) -> dict:
    r = requests.post(
        f"{API_ORIGIN}/v1/fits",
        headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())},
        json={"person": {"upload": person}, "clothing": [{"upload": clothing}],
              "options": {"output": "image", "pose": "original"}},
    )
    r.raise_for_status()
    return r.json()


def wait_for_fit(fit_id: str) -> dict:
    delay = 2.0
    while True:
        fit = requests.get(f"{API_ORIGIN}/v1/fits/{fit_id}", headers=HEADERS).json()
        if fit["status"] in ("completed", "failed"):
            return fit
        time.sleep(delay)
        delay = min(delay * 1.5, 15.0)

Handling the result

const fit = await waitForFit(id);
if (fit.status === 'failed') {
  // fit.error.code, fit.error.message, fit.error.retryable
} else {
  // fit.output.image.url expires: fetch it now or store your own copy
}

Every response carries X-Request-Id; log it next to your own request id so support can find the call.