The AIhairstyles API

Yes, we have an API! Build next-level apps with AIhairstyles. Generate hairstyles for your app, website or other projects in seconds.

Getting Started with the AI hairstyles API

These steps are a high-level outline of how to work with the AIhairstyles API. For more detailed information, please refer to the API documentation.

1

Get your API key

Create an account, and in your profile section create an API key.

2

Purchase credits (or use test mode)

Visit your profile section to purchase API credits. Each successful generation will consume one credit from your balance.

Credits never expire and can be used anytime. Volume discounts are available for bulk purchases.

For testing, you can use mode: 'test' in the API request. This will not consume any credits from your balance but let you test the full API flow.

3

Get the styles

Send a GET request to get the styles:

https://api.aihairstyles.com/api/styles
Copy

You'll get a JSON response with the styles, like below. Notice that the preview_images object contains the images for both sexes.

{
  "description": "Bob - disheveled",
  "preview_images": {
    "man-white": "https://ik.imagekit.io/aicosmetic/AAA-hairstyle_images/models/man-white/00037.png?updatedAt=1710976848880",
    "woman-white": "https://ik.imagekit.io/aicosmetic/AAA-hairstyle_images/models/woman-white/bob%20dishevled.png?updatedAt=1707320590149"
  },
  "preview_image": "https://ik.imagekit.io/aicosmetic/null",
  "sex": "feminine",
  "id": 817941,
  "tags": "disheveled, bob"
}
Copy

4

Create a generation

Send a POST request to create a new generation to

https://api.aihairstyles.com/api/preview
Copy

Your API key should be in the headers of your request, in the x-api-key field.

The request should be sent as form-data with the following fields:

Image (required)

  • It should ideally be a square image with the subject's face clearly visible. Images will be cropped to be square if not square
  • With enough area around the face and hair for the AI to generate different styles.
  • The maximum file size allowed is 8Mb.
hairstyle (required)

Multiple styles separated by comma

hair_colour (required)

Options: blonde, brown, black, ginger, grey

gender (optional)

Options: male, female, or person (default)

callback_url (optional)

Your webhook URL

mode (optional)

Options: test. Use during development to avoid being billed.

Important notes:

  • Images should be square with the face clearly visible
  • Maximum file size: 8MB
  • Ensure enough area around face and hair
  • Avoid images at extreme angles
  • All requested hairstyles must be valid or the request will fail
  • Use 'mode': 'test' during development to avoid charges

Successful response

{
  "data": {
    "id": 1234,
    "inputUrl": "https://ik.imagekit.io/aicosmetic/f8b915b2-57df-49b7/123123123"
  },
  "message": "Job created successfully",
  "status": "success"
}
Copy
5

Handling the result (polling or webhook)

You have two options for handling the result.

Webhook

Specify a callback_url in the original POST request to create a preview, and we'll send a POST request to that URL when the generation is complete.

Polling

Send a GET request to the preview ID to check the status. Note that polling faster than once per second will result in throttling.

https://aihairstyles.com/api/preview/[preview_id]
Copy

Successful response

{
  "data": {
    "images": [
      "https://ik.imagekit.io/aicosmetic/3291-preview-723335832172-7679_Se7y5RMBR"
    ],
    "status": "done"
  },
  "message": "",
  "status": "success"
}
Copy

Error response

{
  "data": null,
  "message": "Invalid API key",
  "status": "error"
}
Copy

Got questions?

If you have any questions or need assistance with the API, please don't hesitate to get in touch. We're here to help, and are eager to hear about any improvements you'd like to see to the API. support@aihairstyles.com.