> For the complete documentation index, see [llms.txt](https://docs.saas.haut.ai/haut.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.saas.haut.ai/haut.ai/developers/saas-api-overview/api-for-images/api-for-masks.md).

# API for Masks

This page contains description how to get images with applied masks via API.

{% hint style="danger" %}
There is newer and better version here, which generates masks similar to UI representation and in more frontend-friendly format: [API for SVG Masks](/haut.ai/developers/saas-api-overview/api-for-images/api-for-svg-masks.md)
{% endhint %}

**Masks** are additional results of image analysis, representing the spatial information about detected skin/hair health returned by the selected set of Algorithms.

{% hint style="info" %}
Check the [Masks description](/haut.ai/haut.ai-features/algorithms/algorithm-results.md#masks) for more details.
{% endhint %}

## What can you do?

You can find more details on these actions in the **Rasterisation** section of [Swagger](https://saas.haut.ai/service/rasterisation/docs/).

* [Apply masks to image with API](#apply-masks-to-image-with-api)

***

## Apply masks to image with API

## POST /service/rasterisation/v4/masks/

> Apply Mask V4 Http

```json
{"openapi":"3.1.0","info":{"title":"FastAPI","version":"0.1.0"},"servers":[{"url":"https://saas.haut.ai/"}],"security":[{"HTTPBearer":[]}],"components":{"securitySchemes":{"HTTPBearer":{"type":"http","scheme":"bearer"}},"schemas":{"ApplyMaskRequestV4":{"properties":{"image_id":{"type":"string","format":"uuid4","title":"Image Id"},"image_type":{"$ref":"#/components/schemas/ImageType"},"masks":{"items":{"$ref":"#/components/schemas/MaskRequestDetailsV4"},"type":"array","title":"Masks"}},"type":"object","required":["image_id","image_type","masks"],"title":"ApplyMaskRequestV4"},"ImageType":{"type":"string","enum":["original","restored"],"title":"ImageType"},"MaskRequestDetailsV4":{"properties":{"algorithm_tech_name":{"type":"string","title":"Algorithm Tech Name"},"fill_override":{"anyOf":[{"prefixItems":[{"type":"integer","maximum":255,"minimum":0},{"type":"integer","maximum":255,"minimum":0},{"type":"integer","maximum":255,"minimum":0},{"type":"number","maximum":1,"minimum":0}],"items":false,"type":"array"},{"type":"null"}],"title":"Fill Override"},"polyline_line_thickness":{"anyOf":[{"type":"number"},{"type":"null"}],"title":"Polyline Line Thickness","default":0.001},"main_metric":{"type":"boolean","title":"Main Metric","default":true},"sub_metrics":{"type":"boolean","title":"Sub Metrics","default":true},"concentric_lines":{"type":"boolean","title":"Concentric Lines","default":false}},"type":"object","required":["algorithm_tech_name"],"title":"MaskRequestDetailsV4"},"ApplyMaskResponseV4":{"properties":{"algorithm_tech_name":{"type":"string","title":"Algorithm Tech Name"},"masked_image_url":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Masked Image Url"},"error":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Error"},"main_metric":{"anyOf":[{"$ref":"#/components/schemas/SubMetricV3"},{"type":"null"}]},"sub_metrics":{"items":{"$ref":"#/components/schemas/SubMetricV3"},"type":"array","title":"Sub Metrics","default":[]},"feedback":{"additionalProperties":true,"type":"object","title":"Feedback","default":{}}},"type":"object","required":["algorithm_tech_name"],"title":"ApplyMaskResponseV4"},"SubMetricV3":{"properties":{"name":{"type":"string","title":"Name"},"tech_name":{"type":"string","title":"Tech Name"},"value":{"anyOf":[{"type":"integer"},{"type":"string"}],"title":"Value"},"widget_type":{"type":"string","title":"Widget Type"}},"type":"object","required":["name","tech_name","value","widget_type"],"title":"SubMetricV3"},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}}},"paths":{"/service/rasterisation/v4/masks/":{"post":{"tags":["apply mask to photo","apply mask to photo"],"summary":"Apply Mask V4 Http","operationId":"apply_mask_v4_http_service_rasterisation_v4_masks__post","parameters":[{"name":"company_id","in":"query","required":true,"schema":{"type":"string","format":"uuid","title":"Company Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApplyMaskRequestV4"}}}},"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ApplyMaskResponseV4"},"title":"Response Apply Mask V4 Http Service Rasterisation V4 Masks  Post"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}}}
```

Required arguments are company\_id and image\_id.

It's important which image you want to visualize masks on: original or restored.

Then you need to compile a `masks` list:

* `algorithm_tech_name` - it's internal ML algorithm tech\_name (e.g. `age` or `pores`). We know that this is an incosistency, because we have 2 types of tech names throughout API. It will be changed in future.
* **optional** `fill_override` - override mask color.
* **optional** `polyline_line_thickness` - override mask line thickness.
* **optional** `main_metric` - if API response should contain the metric for this algorithm.
* **optional** `sub_metrics` - if API response should contain submetrics for this algorithm.
* **optional** **deprecated** `concentric_lines` - if masks should be visualised as concentric lines. (Supported only for a few algorithms). Will be deleted in future.

This method returns signed URLs with images with applied masks.

**Note** We return 1 image per 1 mask, so if you request to apply 5 masks, you will receive 5 images, not 1 in response.

***

{% hint style="warning" %}
Not a Haut.AI client yet?
{% endhint %}

<a href="https://haut.ai/book-a-demo?utm_source=referral&#x26;utm_medium=saas_docs&#x26;utm_campaign=Docs_SaaS_HautAI" class="button primary" data-icon="user-vneck">Book a demo</a> <a href="https://haut.ai/product/ai-skin-analysis?utm_source=referral&#x26;utm_medium=saas_docs&#x26;utm_campaign=Docs_SaaS_HautAI" class="button secondary" data-icon="external-link">Platform overview on haut.ai</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.saas.haut.ai/haut.ai/developers/saas-api-overview/api-for-images/api-for-masks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
