# /create

{% hint style="info" %}
Чтобы отправлять авторизованные запросы нужно получить API ключ, как это сделать написано в разделе [**С чего начать?**](https://docs.gptunnel.ru/)
{% endhint %}

Рассмотрим пример, где мы хотим заменить лицо на фотографии sourceImage лицом с фотографии faceImage. Обратите внимание: лицо должно быть хорошо видимым, повернуто в сторону камеры и не должно быть слишком близко (голова не должна быть обрезана), иначе возможны ошибки.

<div><figure><img src="/files/GzUh0iAWDc353twP161I" alt="" width="251"><figcaption><p>sourceImage</p></figcaption></figure> <figure><img src="/files/o6s0rwXrQigBd7SsplV2" alt="" width="232"><figcaption><p>faceImage</p></figcaption></figure></div>

## Создать задачу на замену лица

<mark style="color:green;">`POST`</mark> `https://gptunnel.ru/v1/faceswap/create`

Замена лица на фото может занимать от 1 до 30 секунд в зависимости от загрузки сервера, поэтому мы создаем асинхронные задачи и получаем результат по мере готовности через webhook либо дополнительный запрос.

#### Headers

| Name                                            | Type   | Description |
| ----------------------------------------------- | ------ | ----------- |
| Authorization<mark style="color:red;">\*</mark> | string | API ключ    |

#### Request Body

| Name                                          | Type   | Description                 |
| --------------------------------------------- | ------ | --------------------------- |
| sourceImage<mark style="color:red;">\*</mark> | string | png or jpeg                 |
| faceImage<mark style="color:red;">\*</mark>   | string | png or jpeg                 |
| useWalletBalance                              | bool   | Использовать личный счет    |
| enhanceFace                                   | bool   | Улучшить качество лица      |
| enhanceBackground                             | bool   | Улучшить качество фона      |
| webhook                                       | string | URL для отправки результата |

{% tabs %}
{% tab title="200: OK Успешный ответ" %}
{% code fullWidth="false" %}

```
{
	"id": "65819c485337280001a609e7",
	"parentId": null,
	"object": "task",
	"type": "@FaceSwap",
	"percent": 0,
	"status": "idle",
	"error": null,
	"usage": {
		"prompt_tokens": 0,
		"completion_tokens": 1,
		"total_tokens": 1,
		"prompt_cost": 0,
		"completion_cost": 15,
		"total_cost": 15
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request Неверный запрос" %}

```json
{
  "error": {
    "message": "'sourceImage' is a required property",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}
```

{% endtab %}

{% tab title="402: Payment Required Недостаточно средств" %}

```json
{
  "error": {
    "message": "Organization balance is too low to use API",
    "type": "insufficient_balance_error",
    "param": null,
    "code": null
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized Ошибка авторизации" %}

```json
{
  "error": {
    "message": "Unauthorized",
    "type": "unauthorized_request_error",
    "param": null,
    "code": null,
  }
}
```

{% endtab %}
{% endtabs %}

### Пример запроса

{% tabs %}
{% tab title="NodeJS" %}

```typescript
import axios from 'axios'

const request = axios({
  method: 'POST',
  url: 'https://gptunnel.ru/v1/faceswap/create',
  headers: {
    // use your API key here
    Authorization: 'YOUR_API_KEY',
  },
  data: {
    sourceImage: "https://storage.yandexcloud.net/timenote/fs_source.jpg",
    faceImage: "https://storage.yandexcloud.net/timenote/fs_face.jpg",
    webhook: null,
    useWalletBalance: false
  }
})

request.then((result) => {
  console.log(result)
}).catch((error) => {
  console.error(error)
})
```

{% endtab %}

{% tab title="Curl" %}

```bash
curl --request POST \
  --url https://gptunnel.ru/v1/faceswap/create \
  --header 'Authorization: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "sourceImage": "https://storage.yandexcloud.net/timenote/fs_source.jpg",
    "faceImage": "https://storage.yandexcloud.net/timenote/fs_face.jpg",
    "webhook": null,
    "useWalletBalance": false
}'
```

{% endtab %}
{% endtabs %}

### Пример ответа

```json
{
	"id": "65819c485337280001a609e7",
	"parentId": null,
	"object": "task",
	"type": "@FaceSwap",
	"percent": 0,
	"status": "idle",
	"error": null,
	"usage": {
		"prompt_tokens": 0,
		"completion_tokens": 1,
		"total_tokens": 1,
		"prompt_cost": 0,
		"completion_cost": 15,
		"total_cost": 15
	}
}
```

Результат будет получен через webhook, который был указан в запросе, или через метод /result. Информацию о методе /result можно найти на следующей странице.


---

# Agent Instructions: 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:

```
GET https://docs.gptunnel.ru/faceswap/create.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
