> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Редактирование изображений Grok Imagine 1.5

>  - Асинхронный режим обработки, возвращает идентификатор задачи для последующих запросов
- Высококачественное редактирование изображений на основе референсных изображений, поддерживает многоязычные промпты
- Ссылки на сгенерированные изображения действительны в течение 24 часов, своевременно сохраняйте их 

<Info>
  **Совместимость названий моделей**: данный интерфейс также поддерживает алиас `grok-imagine-1.5-edit-ext`, эквивалентный `grok-imagine-1.5-edit-apimart`; они взаимозаменяемы и дают одинаковый результат.
</Info>

<RequestExample>
  ```bash cURL theme={null}
  # model можно указать как "grok-imagine-1.5-edit-apimart", также поддерживается алиас "grok-imagine-1.5-edit-ext"
  curl --request POST \
    --url https://api.apimart.ai/v1/images/edits \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "grok-imagine-1.5-edit-apimart",
      "prompt": "Change the background to a starry sky, keep the main subject",
      "image_urls": ["https://example.com/original.png"],
      "n": 1
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.apimart.ai/v1/images/edits"

  payload = {
      "model": "grok-imagine-1.5-edit-apimart",
      "prompt": "Change the background to a starry sky, keep the main subject",
      "image_urls": ["https://example.com/original.png"],
      "n": 1
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://api.apimart.ai/v1/images/edits";

  const payload = {
    model: "grok-imagine-1.5-edit-apimart",
    prompt: "Change the background to a starry sky, keep the main subject",
    image_urls: ["https://example.com/original.png"],
    n: 1
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01JNXXXXXXXXXXXXXXXXXX"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "Invalid request parameters",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "Authentication failed, please check your API key",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "Insufficient balance, please top up and try again",
      "type": "payment_required"
    }
  }
  ```

  ```json 403 theme={null}
  {
    "error": {
      "code": 403,
      "message": "Access forbidden, you do not have permission to access this resource",
      "type": "permission_error"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "Too many requests, please try again later",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "Internal server error, please try again later",
      "type": "server_error"
    }
  }
  ```

  ```json 502 theme={null}
  {
    "error": {
      "code": 502,
      "message": "Bad gateway, server temporarily unavailable",
      "type": "bad_gateway"
    }
  }
  ```
</ResponseExample>

## Авторизация

<ParamField header="Authorization" type="string" required>
  Все API требуют аутентификации Bearer Token

  Получите API Key:

  Перейдите на [страницу управления API ключами](https://apimart.ai/keys), чтобы получить свой API Key

  Добавьте его в заголовок запроса:

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Тело запроса

<ParamField body="model" type="string" default="grok-imagine-1.5-edit-apimart" required>
  Название модели редактирования изображений

  Поддерживаемые модели:

  * `grok-imagine-1.5-edit-apimart` — редактирование изображений Grok (совместимый алиас `grok-imagine-1.5-edit-ext`)

  Пример: `"grok-imagine-1.5-edit-apimart"`

  <Note>
    Для совместимости со старыми вызовами алиас `grok-imagine-1.5-edit-ext` (соответствует `grok-imagine-1.5-edit-apimart`) по-прежнему доступен для использования.
  </Note>
</ParamField>

<ParamField body="prompt" type="string" required>
  Текстовое описание для редактирования изображения, поддерживает несколько языков
</ParamField>

<ParamField body="image_urls" type="string[]" required>
  Массив URL исходных изображений. Система использует первое изображение в массиве в качестве референса для редактирования.

  Поддерживаются ссылки `https://` или формат `data:image/...;base64,...`.
</ParamField>

<ParamField body="n" type="integer" default={1}>
  Количество генерируемых изображений

  Диапазон: 1–10 (минимум 1, максимум 10)
</ParamField>

## Ответ

<ResponseField name="code" type="integer">
  Код состояния ответа
</ResponseField>

<ResponseField name="data" type="array">
  Массив данных ответа

  <Expandable title="Свойства">
    <ResponseField name="status" type="string">
      Статус задачи

      * `submitted` — отправлено
    </ResponseField>

    <ResponseField name="task_id" type="string">
      Уникальный идентификатор задачи
    </ResponseField>
  </Expandable>
</ResponseField>

## Сценарии использования

### Сценарий 1: редактирование фона

```json theme={null}
{
  "model": "grok-imagine-1.5-edit-apimart",
  "prompt": "Change the background to a starry sky, keep the main subject",
  "image_urls": ["https://example.com/original.png"]
}
```

### Сценарий 2: перенос стиля

```json theme={null}
{
  "model": "grok-imagine-1.5-edit-apimart",
  "prompt": "Convert the image to cyberpunk style",
  "image_urls": ["https://example.com/original.png"],
  "n": 2
}
```
