fashn-logo
FASHNAI
FASHN API

Endpoints

On this page you will find our HTTP API reference. Currently, we support 3 types of endpoints:

Run prediction

Initiate a new try-on prediction by posting to the following endpoint:

POSThttps://api.fashn.ai/v1/run

Request

curl -X POST https://api.fashn.ai/v1/run \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY_HERE" \
     -d '{
           "model_image": "http://example.com/path/to/model.jpg",
           "garment_image": "http://example.com/path/to/garment.jpg",
           "category": "tops"
         }'

Properties:

model_image
Required
image URL | base64

garment_image
Required
image URL | base64

category
Required
'tops' | 'bottoms' | 'one-pieces'

nsfw_filterboolean

Runs NSFW content filter on inputs.

Default: true

cover_feetboolean

Allows long garments to cover the feet/shoes or change their appearance.

Default: false

adjust_handsboolean

Allow to change the appearance of the model’s hands. Example use-cases: Remove gloves, get hands out of pockets, long sleeves that should cover hands.

Default: false

restore_backgroundboolean

Apply additional steps to preserve the original background. Runtime will be slower. Not needed for simple backgrounds.

Default: false

restore_clothesboolean

Apply additional steps to preserve the appearance of clothes that weren’t swapped (e.g. keep pants if trying-on top).

Default: false

garment_photo_typeauto | flat-lay | model

Specifies the type of garment photo to optimize internal parameters for better performance. 'model' is for photos of garments on a model, 'flat-lay' is for flat-lay or ghost mannequin images, and 'auto' attempts to automatically detect the photo type.

Default: auto

long_topboolean

Adjusts internal parameters for better performance on long tops such as: Longline shirts, tunics, coats, etc.

Default: false

guidance_scalefloat

Higher guidance scales can help with preserving garment detail, but risks oversaturated colors.

Default: 2 Range: 1.5-3

timestepsint

Determines how many steps the diffusion model will take to generate the image. For simple try-ons, steps can be reduced for faster runtime.

Default: 50 Range: 10-50

seedint

Sets random operations to a fixed state. Use the same seed to reproduce results with the same inputs, or different seed to force different results.

Default: 42

num_samplesint

Number of images to generate in a single run. Image generation has a random element in it, so trying multiple images at once increases the chances of getting a good result.

Default: 1 Range: 1-4

Base64 must include prefix (e.g. data:image/jpg;base64, <YOUR_BASE64>)

Rate limit: 25 generations/minute

Response

The reponse will return the id of the prediction which you will need to use for getting the status and result or canceling the prediction.

{
  "id": "123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1",
  "error": null
}

Get prediction status

Receive the status of the prediction by id. Unless in a queue, it takes up to 40 seconds to generate a try-on.

GEThttps://api.fashn.ai/v1/status/:id

Poll this endpoint to monitor the prediction’s progress and retrieve the final output once available.

Request

curl -X GET https://api.fashn.ai/v1/status/123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1 \
     -H "Authorization: Bearer YOUR_API_KEY_HERE"

Response

The response will return the prediction id and status.

Status types can be one of the following:

statusstarting | in_queue | processing | completed | failed | canceled

Prediction in progress

{
  "id": "123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1",
  "status": "processing",
  "error": null
}

Prediction completed

{
  "id": "123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1",
  "status": "completed",
  "output": [
    "https://cdn.staging.fashn.ai/123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1/output_0.png"
  ],
  "error": null
}

Cancel prediction

Request to cancel your running prediction.

GEThttps://api.fashn.ai/v1/cancel/:id

Request

curl -X GET https://api.fashn.ai/v1/cancel/123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1 \
     -H "Authorization: Bearer YOUR_API_KEY_HERE"

Response

Prediction canceled

{
  "id": "123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1",
  "status": "canceled",
  "error": null
}

Error Handling

In case of an error, the API will add the following object to the error key in the response:

namePipelineError | RequestError | ImageLoadError | NSFWError | PoseError | InputValidationError | PhotoTypeError

messagestring

Example:

{
  "error": {
    "name": "RequestError",
    "message": "The error message"
  }
}

Example of an error when polling the /status endpoint:

{
  "id": "123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1",
  "status": "failed",
  "error": {
    "name": "ImageLoadError",
    "message": "Error loading model image: The URL's Content-Type is not an image. Content-Type: text/plain;charset=UTF-8"
  }
}

If you encounter an unrecognized error, please contact us at support@fashn.ai.

On this page