{
    "openapi": "3.1.0",
    "info": {
        "title": "fotbot API",
        "version": "1.0.0",
        "description": "HTTP-API сервиса fotbot: обработка изображений по готовым сценариям (убрать фон, улучшить качество, превратить в рисунок, подготовить фото для объявлений).\n\nОбработка всегда асинхронная: `POST /api/v1/images` создаёт задачу и возвращает `202` с `poll_url`. Результат забирается опросом `GET /api/v1/tasks/{id}`. Один запрос — одно изображение.\n\nПеред началом получите ключ в личном кабинете (раздел «API»). Ключ с префиксом `test_` — песочница: те же адреса и поля, но изображения не списываются, а исход задачи задаётся полем `sandbox`.",
        "contact": {
            "name": "Поддержка fotbot",
            "url": "https://fotbot.ru"
        }
    },
    "servers": [
        {
            "url": "https://fotbot.ru/api/v1",
            "description": "Боевой сервер"
        }
    ],
    "tags": [
        {
            "name": "Сервис",
            "description": "Проверка доступности сервиса."
        },
        {
            "name": "Модели",
            "description": "Каталог моделей: что можно сделать с изображением."
        },
        {
            "name": "Обработка",
            "description": "Создание задачи обработки и получение результата."
        },
        {
            "name": "Аккаунт",
            "description": "Остаток изображений, лимиты и расход изображений."
        },
        {
            "name": "Ключи API",
            "description": "Выпуск, изменение, отзыв ключей и их статистика."
        }
    ],
    "paths": {
        "/account": {
            "get": {
                "tags": [
                    "Аккаунт"
                ],
                "summary": "Аккаунт и остаток изображений",
                "description": "Отвечает на вопросы: сколько изображений доступно (`balance.generations`), сколько ключей уже выпущено (`keys`) и как расходуются запросы (`usage_24h`, `generations_used_24h`, `generations_used_30d`).\n\n`limits` — действующие ограничения аккаунта: запросы в минуту и в час на ключ, а также потолок размера исходного изображения в байтах. Это актуальные значения: ориентируйтесь на них, а не на числа из документации.\n\nРасход раздельный. `usage_24h` и `generations_used_*` считают только боевой трафик, запросы тестовым ключом видны отдельно в `sandbox.requests_24h`. Остаток при этом общий: `balance.generations` не делится на боевой и тестовый.\n\nПочта приходит с маской (`email_masked`): этого хватает, чтобы опознать свой аккаунт, и при этом адрес остаётся защищён — в ответах API он не раскрывается целиком.",
                "operationId": "account",
                "responses": {
                    "200": {
                        "description": "Состояние аккаунта.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "object",
                                        "id",
                                        "email_masked",
                                        "balance",
                                        "keys",
                                        "limits",
                                        "usage_24h",
                                        "generations_used_24h",
                                        "generations_used_30d",
                                        "sandbox"
                                    ],
                                    "properties": {
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "account"
                                            ]
                                        },
                                        "id": {
                                            "type": "string",
                                            "description": "Идентификатор аккаунта с префиксом `usr_`."
                                        },
                                        "email_masked": {
                                            "type": "string",
                                            "description": "Почта с маской вместо локальной части — для опознания своего аккаунта."
                                        },
                                        "balance": {
                                            "type": "object",
                                            "required": [
                                                "generations"
                                            ],
                                            "properties": {
                                                "generations": {
                                                    "type": "integer",
                                                    "description": "Сколько изображений доступно."
                                                }
                                            }
                                        },
                                        "keys": {
                                            "type": "object",
                                            "required": [
                                                "active",
                                                "test_active",
                                                "limit"
                                            ],
                                            "properties": {
                                                "active": {
                                                    "type": "integer",
                                                    "description": "Активных боевых ключей."
                                                },
                                                "test_active": {
                                                    "type": "integer",
                                                    "description": "Активных тестовых ключей."
                                                },
                                                "limit": {
                                                    "type": "integer",
                                                    "description": "Максимум активных ключей на аккаунт."
                                                }
                                            }
                                        },
                                        "limits": {
                                            "type": "object",
                                            "required": [
                                                "rate_per_minute",
                                                "rate_per_hour",
                                                "max_image_bytes"
                                            ],
                                            "properties": {
                                                "rate_per_minute": {
                                                    "type": "integer",
                                                    "description": "Запросов в минуту на ключ."
                                                },
                                                "rate_per_hour": {
                                                    "type": "integer",
                                                    "description": "Запросов в час на ключ."
                                                },
                                                "max_image_bytes": {
                                                    "type": "integer",
                                                    "description": "Потолок размера исходного изображения."
                                                }
                                            }
                                        },
                                        "usage_24h": {
                                            "type": "object",
                                            "required": [
                                                "total",
                                                "succeeded",
                                                "failed"
                                            ],
                                            "description": "Запросы к `/images` за сутки. Только боевые.",
                                            "properties": {
                                                "total": {
                                                    "type": "integer"
                                                },
                                                "succeeded": {
                                                    "type": "integer"
                                                },
                                                "failed": {
                                                    "type": "integer"
                                                }
                                            }
                                        },
                                        "generations_used_24h": {
                                            "type": "integer",
                                            "description": "Списано изображений за сутки."
                                        },
                                        "generations_used_30d": {
                                            "type": "integer",
                                            "description": "Списано изображений за 30 дней."
                                        },
                                        "sandbox": {
                                            "type": "object",
                                            "required": [
                                                "requests_24h"
                                            ],
                                            "description": "Тестовый трафик — отдельно от боевого.",
                                            "properties": {
                                                "requests_24h": {
                                                    "type": "integer",
                                                    "description": "Запросов тестовым ключом за сутки."
                                                }
                                            }
                                        }
                                    }
                                },
                                "example": {
                                    "object": "account",
                                    "id": "usr_10231",
                                    "email_masked": "c***@yandex.ru",
                                    "balance": {
                                        "generations": 42
                                    },
                                    "keys": {
                                        "active": 2,
                                        "test_active": 1,
                                        "limit": 10
                                    },
                                    "limits": {
                                        "rate_per_minute": 30,
                                        "rate_per_hour": 300,
                                        "max_image_bytes": 10485760
                                    },
                                    "usage_24h": {
                                        "total": 12,
                                        "succeeded": 11,
                                        "failed": 1
                                    },
                                    "generations_used_24h": 11,
                                    "generations_used_30d": 184,
                                    "sandbox": {
                                        "requests_24h": 27
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },
        "/health": {
            "get": {
                "tags": [
                    "Сервис"
                ],
                "summary": "Проверка доступности",
                "description": "Отвечает без ключа и не расходует лимит запросов.\n\n`status: ok` — сервис принимает задачи и обрабатывает их в обычном режиме. `status: degraded` — задачи принимаются, но обработка временно задерживается.\n\nОтвет приходит с HTTP-статусом `200` в обоих случаях: это отчёт о состоянии, а не ошибка запроса. Ориентируйтесь на поле `status`.",
                "operationId": "health",
                "responses": {
                    "200": {
                        "description": "Состояние сервиса.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "status",
                                        "version",
                                        "time"
                                    ],
                                    "properties": {
                                        "status": {
                                            "type": "string",
                                            "enum": [
                                                "ok",
                                                "degraded"
                                            ],
                                            "description": "`ok` — сервис работает штатно; `degraded` — обработка задач временно задерживается."
                                        },
                                        "version": {
                                            "type": "string",
                                            "description": "Версия API.",
                                            "examples": [
                                                "v1"
                                            ]
                                        },
                                        "time": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Время ответа в UTC."
                                        }
                                    }
                                },
                                "example": {
                                    "status": "ok",
                                    "version": "v1",
                                    "time": "2026-11-02T10:15:00Z"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/images": {
            "post": {
                "tags": [
                    "Обработка"
                ],
                "summary": "Создать задачу обработки",
                "description": "Принимает запрос на обработку изображения и сразу возвращает `202` с объектом задачи. Синхронного режима нет: результат забирают опросом `GET /tasks/{id}` по полю `poll_url`. Один запрос — одно изображение.\n\nКакие поля модель принимает, перечислено в её `input` из `GET /models`. Если модели нужен промпт и его нет — `422 prompt_required`; если нужен исходник и его нет — `422 image_required`.\n\nИсходник — только в поле `image`: файл в `multipart/form-data` или строка-ссылка в JSON. Форматы — JPEG, PNG, WebP, не больше 10 МБ, стороны не меньше 32 пикселей.\n\nЕсли модель не принимает картинку, поле `image` игнорируется: файл не сохраняется, ссылка не скачивается. Если модель не принимает промпт, поле `prompt` игнорируется так же — ни в заказ, ни в проверки оно не попадает.\n\nЗаголовок `Idempotency-Key` защищает от двойного списания при повторе: тот же ключ и то же тело в течение 24 часов вернут ту же задачу, другое тело — `409 idempotency_conflict`.\n\nПоле `sandbox` принимает только тестовый ключ (префикс `test_`): оно задаёт исход и время ожидания демонстрационной задачи, изображения при этом не списываются. Боевой ключ с этим полем получит `422 sandbox_not_allowed`.\n\nПоле `async` принимается ради совместимости и игнорируется: задача всегда асинхронная.",
                "operationId": "imagesCreate",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Ключ идемпотентности (8–64 символа: A-Z, a-z, 0-9, -, _). Защищает от случайных дублей при сетевых сбоях: Повтор запроса с тем же ключом и телом вернёт результат первой задачи. Если тело запроса отличается, сервер вернёт ошибку 409 idempotency_conflict. Ключ хранится 24 часа.",
                        "schema": {
                            "type": "string",
                            "pattern": "^[A-Za-z0-9_\\-]{8,64}$"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "model"
                                ],
                                "properties": {
                                    "model": {
                                        "type": "string",
                                        "maxLength": 64,
                                        "description": "Идентификатор модели из `GET /models`, вида `<раздел>:<код>`.",
                                        "examples": [
                                            "main:upscale"
                                        ]
                                    },
                                    "prompt": {
                                        "type": "string",
                                        "maxLength": 4096,
                                        "description": "Что нужно сделать. Нужен моделям с `input.prompt: required`; для остальных игнорируется."
                                    },
                                    "image": {
                                        "description": "Исходник для моделей с `input.image: required`: файл в `multipart/form-data` или ссылка строкой в JSON. Для остальных игнорируется.",
                                        "oneOf": [
                                            {
                                                "type": "string",
                                                "format": "binary"
                                            },
                                            {
                                                "type": "string",
                                                "format": "uri",
                                                "maxLength": 2048
                                            }
                                        ]
                                    },
                                    "async": {
                                        "type": "boolean",
                                        "description": "Игнорируется: задача всегда асинхронная."
                                    },
                                    "sandbox": {
                                        "type": "object",
                                        "description": "Управление песочницей. Только для тестового ключа, иначе `422 sandbox_not_allowed`.",
                                        "additionalProperties": false,
                                        "properties": {
                                            "outcome": {
                                                "type": "string",
                                                "enum": [
                                                    "succeeded",
                                                    "failed",
                                                    "content_policy_violation"
                                                ],
                                                "default": "succeeded",
                                                "description": "Исход задачи. `succeeded` — задача завершится в `succeeded`, результат — демонстрационный PNG 512×512. `failed` — задача в `failed`, `error.code = generation_failed`. `content_policy_violation` — задача в `failed`, `error.code = content_policy_violation`."
                                            },
                                            "delay_seconds": {
                                                "type": "integer",
                                                "minimum": 0,
                                                "maximum": 10,
                                                "default": 2,
                                                "description": "Через сколько секунд задача завершится."
                                            }
                                        }
                                    }
                                }
                            },
                            "example": {
                                "model": "main:upscale",
                                "prompt": "Сделай карточку товара крупнее и убери шум",
                                "image": "https://example.com/photo.jpg"
                            }
                        },
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "model"
                                ],
                                "properties": {
                                    "model": {
                                        "type": "string",
                                        "maxLength": 64,
                                        "description": "Идентификатор модели из `GET /models`, вида `<раздел>:<код>`.",
                                        "examples": [
                                            "main:upscale"
                                        ]
                                    },
                                    "prompt": {
                                        "type": "string",
                                        "maxLength": 4096,
                                        "description": "Что нужно сделать. Нужен моделям с `input.prompt: required`; для остальных игнорируется."
                                    },
                                    "image": {
                                        "description": "Исходник для моделей с `input.image: required`: файл в `multipart/form-data` или ссылка строкой в JSON. Для остальных игнорируется.",
                                        "oneOf": [
                                            {
                                                "type": "string",
                                                "format": "binary"
                                            },
                                            {
                                                "type": "string",
                                                "format": "uri",
                                                "maxLength": 2048
                                            }
                                        ]
                                    },
                                    "async": {
                                        "type": "boolean",
                                        "description": "Игнорируется: задача всегда асинхронная."
                                    },
                                    "sandbox": {
                                        "type": "object",
                                        "description": "Управление песочницей. Только для тестового ключа, иначе `422 sandbox_not_allowed`.",
                                        "additionalProperties": false,
                                        "properties": {
                                            "outcome": {
                                                "type": "string",
                                                "enum": [
                                                    "succeeded",
                                                    "failed",
                                                    "content_policy_violation"
                                                ],
                                                "default": "succeeded",
                                                "description": "Исход задачи. `succeeded` — задача завершится в `succeeded`, результат — демонстрационный PNG 512×512. `failed` — задача в `failed`, `error.code = generation_failed`. `content_policy_violation` — задача в `failed`, `error.code = content_policy_violation`."
                                            },
                                            "delay_seconds": {
                                                "type": "integer",
                                                "minimum": 0,
                                                "maximum": 10,
                                                "default": 2,
                                                "description": "Через сколько секунд задача завершится."
                                            }
                                        }
                                    }
                                }
                            },
                            "example": {
                                "model": "main:upscale",
                                "prompt": "Сделай карточку товара крупнее и убери шум",
                                "image": "https://example.com/photo.jpg"
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "Задача принята и обрабатывается.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "id",
                                        "object",
                                        "status",
                                        "model",
                                        "created",
                                        "poll_url",
                                        "request_id"
                                    ],
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "description": "Идентификатор задачи (`req_…`). Это не номер заказа: опрашивайте по нему."
                                        },
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "image.generation"
                                            ]
                                        },
                                        "status": {
                                            "type": "string",
                                            "enum": [
                                                "queued",
                                                "processing",
                                                "succeeded",
                                                "failed"
                                            ],
                                            "description": "Текущее состояние. `queued` и `processing` — опрашивайте дальше."
                                        },
                                        "model": {
                                            "type": "string",
                                            "description": "Идентификатор модели, с которой создана задача."
                                        },
                                        "created": {
                                            "type": "integer",
                                            "description": "Время создания задачи, Unix-время в секундах."
                                        },
                                        "started_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда задача ушла в работу. Нет у задач со статусом `queued`."
                                        },
                                        "completed_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда получен результат. Только у `succeeded`."
                                        },
                                        "failed_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда задача упала. Только у `failed`."
                                        },
                                        "estimated_seconds": {
                                            "type": "integer",
                                            "description": "Оценка ожидания в секундах. Есть только у `queued` и `processing`."
                                        },
                                        "data": {
                                            "type": "array",
                                            "description": "Готовые изображения. Всегда ровно один элемент. Только у `succeeded`.",
                                            "items": {
                                                "$ref": "#/components/schemas/ImageResult"
                                            }
                                        },
                                        "error": {
                                            "type": "object",
                                            "description": "Причина неудачи. Только у `failed`.",
                                            "required": [
                                                "message",
                                                "type",
                                                "code"
                                            ],
                                            "properties": {
                                                "message": {
                                                    "type": "string",
                                                    "description": "Что произошло."
                                                },
                                                "type": {
                                                    "type": "string",
                                                    "description": "Категория ошибки."
                                                },
                                                "code": {
                                                    "type": "string",
                                                    "description": "Код ошибки — тот же справочник, что и в конверте ошибки."
                                                }
                                            }
                                        },
                                        "usage": {
                                            "type": "object",
                                            "description": "Списание изображений. Только у `succeeded` и `failed`.",
                                            "required": [
                                                "generations",
                                                "balance_remaining"
                                            ],
                                            "properties": {
                                                "generations": {
                                                    "type": "integer",
                                                    "description": "Списано за задачу: `1` при успехе и `0` при ошибке (списание возвращается)."
                                                },
                                                "balance_remaining": {
                                                    "type": "integer",
                                                    "description": "Остаток изображений на аккаунте после списания."
                                                }
                                            }
                                        },
                                        "poll_url": {
                                            "type": "string",
                                            "format": "uri",
                                            "description": "Полный адрес для опроса статуса. Требует тот же ключ."
                                        },
                                        "request_id": {
                                            "type": "string",
                                            "description": "Идентификатор запроса, создавшего задачу. Совпадает с `X-Request-Id`."
                                        }
                                    }
                                },
                                "example": {
                                    "id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A",
                                    "object": "image.generation",
                                    "status": "queued",
                                    "model": "main:upscale",
                                    "created": 1793577600,
                                    "estimated_seconds": 12,
                                    "poll_url": "https://fotbot.ru/api/v1/tasks/req_01HZY4K7M9XQ2V8B3N6T0R5S1A",
                                    "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "402": {
                        "description": "На аккаунте не хватает изображений.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "insufficient_balance": {
                                        "summary": "insufficient_balance",
                                        "value": {
                                            "error": {
                                                "message": "Not enough generations on the account.",
                                                "type": "insufficient_quota",
                                                "param": null,
                                                "code": "insufficient_balance"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "key_limit_reached": {
                                        "summary": "key_limit_reached",
                                        "value": {
                                            "error": {
                                                "message": "The request limit for this API key has been reached.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "key_limit_reached"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "sandbox_scope_violation": {
                                        "summary": "sandbox_scope_violation",
                                        "value": {
                                            "error": {
                                                "message": "This API key cannot access this resource.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "sandbox_scope_violation"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "model_not_found": {
                                        "summary": "model_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested model does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "model_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "Повтор с тем же `Idempotency-Key`, но другим телом.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "idempotency_conflict": {
                                        "summary": "idempotency_conflict",
                                        "value": {
                                            "error": {
                                                "message": "A request with this Idempotency-Key was already sent with different parameters.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "idempotency_conflict"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "413": {
                        "description": "Исходное изображение больше допустимого размера.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "image_too_large": {
                                        "summary": "image_too_large",
                                        "value": {
                                            "error": {
                                                "message": "The image is too large.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "image_too_large"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "415": {
                        "description": "Формат изображения не поддерживается.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "unsupported_image_format": {
                                        "summary": "unsupported_image_format",
                                        "value": {
                                            "error": {
                                                "message": "Unsupported image format.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "unsupported_image_format"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Запрос не прошёл проверку полей.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "sandbox_not_allowed": {
                                        "summary": "sandbox_not_allowed",
                                        "value": {
                                            "error": {
                                                "message": "This operation is not available with a test key.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "sandbox_not_allowed"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "invalid_idempotency_key": {
                                        "summary": "invalid_idempotency_key",
                                        "value": {
                                            "error": {
                                                "message": "The Idempotency-Key header is invalid.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "invalid_idempotency_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "image_required": {
                                        "summary": "image_required",
                                        "value": {
                                            "error": {
                                                "message": "This model requires a source image.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "image_required"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "image_too_small": {
                                        "summary": "image_too_small",
                                        "value": {
                                            "error": {
                                                "message": "The image is too small.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "image_too_small"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "invalid_image_url": {
                                        "summary": "invalid_image_url",
                                        "value": {
                                            "error": {
                                                "message": "The image URL cannot be fetched.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "invalid_image_url"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "prompt_required": {
                                        "summary": "prompt_required",
                                        "value": {
                                            "error": {
                                                "message": "This model requires a prompt.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "prompt_required"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "content_policy_violation": {
                                        "summary": "content_policy_violation",
                                        "value": {
                                            "error": {
                                                "message": "The request was rejected by the content policy.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "content_policy_violation"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },
        "/keys": {
            "get": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Список ключей",
                "description": "Возвращает ключи аккаунта постранично, от новых к старым. Курсор следующей страницы — `id` последнего элемента в `data`: передайте его в `after`. Флаг `has_more` говорит, есть ли ещё записи.\n\nПолного ключа в списке нет — только `key_prefix` и `key_last4`, чтобы опознать строку. Сам ключ показывается ровно один раз, в ответе на создание.\n\nПо умолчанию в список попадают и отозванные ключи: их история нужна, чтобы понять, откуда взялись старые запросы. Отключить — `include_revoked=false`.\n\nБоевой ключ видит все ключи аккаунта. Тестовый — только тестовые: `mode` для него принудительно равен `test`, даже если фильтр не передан.",
                "operationId": "keysIndex",
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Размер страницы, от 1 до 100. По умолчанию 20.",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 100,
                            "default": 20
                        }
                    },
                    {
                        "name": "after",
                        "in": "query",
                        "required": false,
                        "description": "Вернуть записи с `id` больше указанного. Курсор берётся из `id` последнего элемента предыдущей страницы.",
                        "schema": {
                            "type": "integer",
                            "minimum": 1
                        }
                    },
                    {
                        "name": "include_revoked",
                        "in": "query",
                        "required": false,
                        "description": "Включать в список отозванные ключи. По умолчанию `true`.",
                        "schema": {
                            "type": "boolean",
                            "default": true
                        }
                    },
                    {
                        "name": "mode",
                        "in": "query",
                        "required": false,
                        "description": "Показать только боевые (`live`) или только тестовые (`test`) ключи. Тестовый ключ всегда видит только тестовые.",
                        "schema": {
                            "type": "string",
                            "enum": [
                                "live",
                                "test"
                            ]
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Страница ключей.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "object",
                                        "data",
                                        "has_more"
                                    ],
                                    "properties": {
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "list"
                                            ]
                                        },
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/ApiKey"
                                            }
                                        },
                                        "has_more": {
                                            "type": "boolean",
                                            "description": "Есть ли ещё записи за пределами этой страницы. Курсор для следующей — `id` последнего элемента."
                                        }
                                    }
                                },
                                "example": {
                                    "object": "list",
                                    "data": [
                                        {
                                            "id": 17,
                                            "object": "api_key",
                                            "name": "Скрипт выгрузки",
                                            "mode": "live",
                                            "key_prefix": "k7Hq2LmN9pRt",
                                            "key_last4": "X4bZ",
                                            "requests_limit": 5000,
                                            "requests_used": 127,
                                            "requests_remaining": 4873,
                                            "status": "active",
                                            "expires_at": null,
                                            "created_at": "2026-10-14T09:20:11+00:00",
                                            "last_used_at": "2026-11-02T10:14:58+00:00",
                                            "revoked_at": null
                                        }
                                    ],
                                    "has_more": false
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            },
            "post": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Создать ключ",
                "description": "Выпускает новый ключ и возвращает его полное значение в поле `key`. Это единственный момент, когда ключ виден целиком: сохраните его сразу, восстановить не получится — только выпустить новый.\n\nРежим задаётся полем `mode`. Если не передавать, ключ наследует режим вызывающего: боевой создаёт боевой, тестовый — тестовый. Тестовому ключу боевой режим запрещён (`403 sandbox_scope_violation`).\n\n`requests_limit` — потолок запросов для этого ключа. Без него лимита по количеству нет, действует только ограничение частоты. `expires_at` задаёт срок жизни; без него ключ бессрочный.\n\nАктивных ключей на аккаунт ограниченное число. Когда потолок достигнут, вернётся `422 too_many_keys` — сначала отзовите ненужные через `DELETE /keys/{id}`.",
                "operationId": "keysCreate",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "name"
                                ],
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "maxLength": 64,
                                        "description": "Название ключа — чтобы отличать его в списке.",
                                        "examples": [
                                            "Скрипт выгрузки"
                                        ]
                                    },
                                    "mode": {
                                        "type": "string",
                                        "enum": [
                                            "live",
                                            "test"
                                        ],
                                        "description": "Режим ключа. По умолчанию — режим вызывающего ключа."
                                    },
                                    "requests_limit": {
                                        "type": [
                                            "integer",
                                            "null"
                                        ],
                                        "minimum": 1,
                                        "maximum": 1000000,
                                        "description": "Потолок запросов. `null` или отсутствие — без ограничения."
                                    },
                                    "expires_at": {
                                        "type": [
                                            "string",
                                            "null"
                                        ],
                                        "format": "date-time",
                                        "description": "Срок жизни ключа. Должен быть в будущем. `null` — бессрочный."
                                    }
                                }
                            },
                            "example": {
                                "name": "Скрипт выгрузки",
                                "mode": "live",
                                "requests_limit": 5000
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Ключ создан. Поле `key` показывается только здесь.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "allOf": [
                                        {
                                            "$ref": "#/components/schemas/ApiKey"
                                        },
                                        {
                                            "type": "object",
                                            "required": [
                                                "key"
                                            ],
                                            "properties": {
                                                "key": {
                                                    "type": "string",
                                                    "description": "Полное значение ключа. Сохраните его: повторно не показывается."
                                                }
                                            }
                                        }
                                    ]
                                },
                                "example": {
                                    "key": "k7Hq2LmN9pRtV4wX6yZ8aB1cD3eF5gH7iJ9kL0mN",
                                    "id": 17,
                                    "object": "api_key",
                                    "name": "Скрипт выгрузки",
                                    "mode": "live",
                                    "key_prefix": "k7Hq2LmN9pRt",
                                    "key_last4": "X4bZ",
                                    "requests_limit": 5000,
                                    "requests_used": 127,
                                    "requests_remaining": 4873,
                                    "status": "active",
                                    "expires_at": null,
                                    "created_at": "2026-10-14T09:20:11+00:00",
                                    "last_used_at": "2026-11-02T10:14:58+00:00",
                                    "revoked_at": null
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "sandbox_scope_violation": {
                                        "summary": "sandbox_scope_violation",
                                        "value": {
                                            "error": {
                                                "message": "This API key cannot access this resource.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "sandbox_scope_violation"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Запрос не прошёл проверку полей.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "too_many_keys": {
                                        "summary": "too_many_keys",
                                        "value": {
                                            "error": {
                                                "message": "Too many active API keys.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "too_many_keys"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },
        "/keys/{id}": {
            "get": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Один ключ",
                "description": "Возвращает ключ по числовому `id` из списка. Полезно, когда нужно проверить, не исчерпан ли лимит (`requests_remaining`) и не истёк ли срок (`status`), не получая всю страницу.\n\nНедоступный ключ и несуществующий неотличимы: оба дают `404 api_key_not_found`. Ответ не раскрывает, существует ли такой ключ. Тестовому ключу так же недоступны боевые ключи аккаунта.\n\nПолного значения ключа в ответе нет и не будет: после создания виден только префикс и последние четыре символа.",
                "operationId": "keysShow",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Числовой идентификатор ключа из `GET /keys`.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Ключ.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "id",
                                        "object",
                                        "name",
                                        "mode",
                                        "key_prefix",
                                        "key_last4",
                                        "requests_limit",
                                        "requests_used",
                                        "requests_remaining",
                                        "status",
                                        "expires_at",
                                        "created_at",
                                        "last_used_at",
                                        "revoked_at"
                                    ],
                                    "properties": {
                                        "id": {
                                            "type": "integer",
                                            "description": "Числовой идентификатор ключа."
                                        },
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "api_key"
                                            ]
                                        },
                                        "name": {
                                            "type": "string",
                                            "description": "Название, заданное при выпуске."
                                        },
                                        "mode": {
                                            "type": "string",
                                            "enum": [
                                                "live",
                                                "test"
                                            ],
                                            "description": "`live` — боевой ключ, `test` — ключ песочницы."
                                        },
                                        "key_prefix": {
                                            "type": "string",
                                            "description": "Первые символы ключа — чтобы опознать его среди других."
                                        },
                                        "key_last4": {
                                            "type": "string",
                                            "description": "Последние четыре символа ключа."
                                        },
                                        "requests_limit": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Потолок запросов для этого ключа. `null` — без ограничения."
                                        },
                                        "requests_used": {
                                            "type": "integer",
                                            "description": "Сколько запросов уже израсходовано."
                                        },
                                        "requests_remaining": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Сколько запросов осталось. `null`, если лимита нет."
                                        },
                                        "status": {
                                            "type": "string",
                                            "enum": [
                                                "active",
                                                "limit_reached",
                                                "expired",
                                                "revoked"
                                            ],
                                            "description": "Состояние ключа на момент ответа."
                                        },
                                        "expires_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Когда ключ перестанет работать. `null` — бессрочный."
                                        },
                                        "created_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time"
                                        },
                                        "last_used_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Последний запрос этим ключом. `null`, если ключ ещё не использовали."
                                        },
                                        "revoked_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Когда ключ отозван. `null` для действующего."
                                        }
                                    }
                                },
                                "example": {
                                    "id": 17,
                                    "object": "api_key",
                                    "name": "Скрипт выгрузки",
                                    "mode": "live",
                                    "key_prefix": "k7Hq2LmN9pRt",
                                    "key_last4": "X4bZ",
                                    "requests_limit": 5000,
                                    "requests_used": 127,
                                    "requests_remaining": 4873,
                                    "status": "active",
                                    "expires_at": null,
                                    "created_at": "2026-10-14T09:20:11+00:00",
                                    "last_used_at": "2026-11-02T10:14:58+00:00",
                                    "revoked_at": null
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_key_not_found": {
                                        "summary": "api_key_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested API key does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "api_key_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            },
            "patch": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Изменить ключ",
                "description": "Меняет у ключа название, потолок запросов или срок жизни. Передавайте только те поля, которые нужно изменить: отсутствующие остаются как были.\n\n`requests_limit` можно как поставить, так и снять, передав `null`. Понизить лимит ниже уже израсходованного количества нельзя — вернётся `422 limit_below_used`.\n\n`expires_at` принимает дату в будущем; `null` делает ключ бессрочным. Прошедшая дата не принимается.\n\nРежим (`live` или `test`) менять нельзя — в теле такого поля нет. Нужен ключ другого режима — выпустите новый и отзовите старый.",
                "operationId": "keysUpdate",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Числовой идентификатор ключа из `GET /keys`.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "maxLength": 64,
                                        "description": "Новое название ключа."
                                    },
                                    "requests_limit": {
                                        "type": [
                                            "integer",
                                            "null"
                                        ],
                                        "minimum": 1,
                                        "maximum": 1000000,
                                        "description": "Новый потолок запросов. `null` снимает ограничение по количеству."
                                    },
                                    "expires_at": {
                                        "type": [
                                            "string",
                                            "null"
                                        ],
                                        "format": "date-time",
                                        "description": "Новый срок жизни. `null` делает ключ бессрочным."
                                    }
                                }
                            },
                            "example": {
                                "name": "Скрипт выгрузки, v2",
                                "requests_limit": 10000
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Обновлённый ключ.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "id",
                                        "object",
                                        "name",
                                        "mode",
                                        "key_prefix",
                                        "key_last4",
                                        "requests_limit",
                                        "requests_used",
                                        "requests_remaining",
                                        "status",
                                        "expires_at",
                                        "created_at",
                                        "last_used_at",
                                        "revoked_at"
                                    ],
                                    "properties": {
                                        "id": {
                                            "type": "integer",
                                            "description": "Числовой идентификатор ключа."
                                        },
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "api_key"
                                            ]
                                        },
                                        "name": {
                                            "type": "string",
                                            "description": "Название, заданное при выпуске."
                                        },
                                        "mode": {
                                            "type": "string",
                                            "enum": [
                                                "live",
                                                "test"
                                            ],
                                            "description": "`live` — боевой ключ, `test` — ключ песочницы."
                                        },
                                        "key_prefix": {
                                            "type": "string",
                                            "description": "Первые символы ключа — чтобы опознать его среди других."
                                        },
                                        "key_last4": {
                                            "type": "string",
                                            "description": "Последние четыре символа ключа."
                                        },
                                        "requests_limit": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Потолок запросов для этого ключа. `null` — без ограничения."
                                        },
                                        "requests_used": {
                                            "type": "integer",
                                            "description": "Сколько запросов уже израсходовано."
                                        },
                                        "requests_remaining": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Сколько запросов осталось. `null`, если лимита нет."
                                        },
                                        "status": {
                                            "type": "string",
                                            "enum": [
                                                "active",
                                                "limit_reached",
                                                "expired",
                                                "revoked"
                                            ],
                                            "description": "Состояние ключа на момент ответа."
                                        },
                                        "expires_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Когда ключ перестанет работать. `null` — бессрочный."
                                        },
                                        "created_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time"
                                        },
                                        "last_used_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Последний запрос этим ключом. `null`, если ключ ещё не использовали."
                                        },
                                        "revoked_at": {
                                            "type": [
                                                "string",
                                                "null"
                                            ],
                                            "format": "date-time",
                                            "description": "Когда ключ отозван. `null` для действующего."
                                        }
                                    }
                                },
                                "example": {
                                    "name": "Скрипт выгрузки, v2",
                                    "requests_limit": 10000,
                                    "requests_remaining": 9873,
                                    "id": 17,
                                    "object": "api_key",
                                    "mode": "live",
                                    "key_prefix": "k7Hq2LmN9pRt",
                                    "key_last4": "X4bZ",
                                    "requests_used": 127,
                                    "status": "active",
                                    "expires_at": null,
                                    "created_at": "2026-10-14T09:20:11+00:00",
                                    "last_used_at": "2026-11-02T10:14:58+00:00",
                                    "revoked_at": null
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_key_not_found": {
                                        "summary": "api_key_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested API key does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "api_key_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Запрос не прошёл проверку полей.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "limit_below_used": {
                                        "summary": "limit_below_used",
                                        "value": {
                                            "error": {
                                                "message": "The new limit is below the number of requests already used.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "limit_below_used"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            },
            "delete": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Отозвать ключ",
                "description": "Отзывает ключ: с этого момента запросы с ним получают `401 key_revoked`. Действие необратимо — восстанавливать отозванный ключ нельзя, только выпускать новый.\n\nОтвет — `204 No Content` без тела. Запись о ключе остаётся в списке с `status: revoked` и заполненным `revoked_at`: видно, что ключ действительно отзывали, а не потеряли.\n\nСразу после отзыва освобождается слот в лимите активных ключей аккаунта: дальше `POST /keys` снова проходит.",
                "operationId": "keysDelete",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Числовой идентификатор ключа из `GET /keys`.",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "204": {
                        "description": "Ключ отозван. Тела в ответе нет."
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_key_not_found": {
                                        "summary": "api_key_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested API key does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "api_key_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },
        "/keys/{id}/usage": {
            "get": {
                "tags": [
                    "Ключи API"
                ],
                "summary": "Статистика ключа",
                "description": "Считает запросы ключа за период: сколько всего, сколько успешных и неудачных, а также разбивки по дням, моделям и кодам ошибок. Без параметров — последние 30 дней.\n\nПериод задаётся `from` и `to` в ISO 8601. Максимум 90 дней за запрос: более длинный интервал вернёт `422` с ошибкой по полю `to`. За более длинной историей обращайтесь несколькими запросами.\n\nВ разбивках только те дни и модели, где были запросы: пустых строк нет, нули не подставляются. Это упрощает построение графиков — не нужно фильтровать.\n\n`requests_used_total` и `requests_remaining` относятся к лимиту ключа за всё время жизни и не зависят от периода; всё, что внутри `period_stats`, — только за запрошенный интервал. Запросы песочницы в статистику не входят.",
                "operationId": "keysUsage",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Числовой идентификатор ключа из `GET /keys`.",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "required": false,
                        "description": "Начало периода в формате ISO 8601 (`2026-10-01` или `2026-10-01T00:00:00Z`). По умолчанию — 30 дней назад.",
                        "schema": {
                            "type": "string",
                            "format": "date-time"
                        }
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "required": false,
                        "description": "Конец периода в формате ISO 8601. По умолчанию — текущий момент. Период не может быть длиннее 90 дней.",
                        "schema": {
                            "type": "string",
                            "format": "date-time"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Статистика ключа за период.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "object",
                                        "key_id",
                                        "period",
                                        "requests_limit",
                                        "requests_used_total",
                                        "requests_remaining",
                                        "period_stats"
                                    ],
                                    "properties": {
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "api_key.usage"
                                            ]
                                        },
                                        "key_id": {
                                            "type": "integer",
                                            "description": "Ключ, к которому относится статистика."
                                        },
                                        "period": {
                                            "type": "object",
                                            "required": [
                                                "from",
                                                "to"
                                            ],
                                            "description": "Фактически применённый период. Если параметры не переданы — последние 30 дней.",
                                            "properties": {
                                                "from": {
                                                    "type": "string",
                                                    "format": "date-time"
                                                },
                                                "to": {
                                                    "type": "string",
                                                    "format": "date-time"
                                                }
                                            }
                                        },
                                        "requests_limit": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Потолок запросов ключа. `null` — без ограничения."
                                        },
                                        "requests_used_total": {
                                            "type": "integer",
                                            "description": "Всего израсходовано за всё время жизни ключа."
                                        },
                                        "requests_remaining": {
                                            "type": [
                                                "integer",
                                                "null"
                                            ],
                                            "description": "Остаток запросов. `null`, если лимита нет."
                                        },
                                        "period_stats": {
                                            "type": "object",
                                            "required": [
                                                "total",
                                                "succeeded",
                                                "failed",
                                                "by_day",
                                                "by_model",
                                                "by_error"
                                            ],
                                            "properties": {
                                                "total": {
                                                    "type": "integer",
                                                    "description": "Запросов за период."
                                                },
                                                "succeeded": {
                                                    "type": "integer",
                                                    "description": "Успешных за период."
                                                },
                                                "failed": {
                                                    "type": "integer",
                                                    "description": "Неудачных за период."
                                                },
                                                "by_day": {
                                                    "type": "array",
                                                    "description": "Разбивка по дням — только дни, в которые были запросы.",
                                                    "items": {
                                                        "type": "object",
                                                        "required": [
                                                            "date",
                                                            "total",
                                                            "succeeded",
                                                            "failed"
                                                        ],
                                                        "properties": {
                                                            "date": {
                                                                "type": "string",
                                                                "format": "date"
                                                            },
                                                            "total": {
                                                                "type": "integer"
                                                            },
                                                            "succeeded": {
                                                                "type": "integer"
                                                            },
                                                            "failed": {
                                                                "type": "integer"
                                                            }
                                                        }
                                                    }
                                                },
                                                "by_model": {
                                                    "type": "array",
                                                    "description": "Разбивка по моделям.",
                                                    "items": {
                                                        "type": "object",
                                                        "required": [
                                                            "model",
                                                            "total",
                                                            "succeeded",
                                                            "failed"
                                                        ],
                                                        "properties": {
                                                            "model": {
                                                                "type": "string",
                                                                "description": "Идентификатор модели."
                                                            },
                                                            "total": {
                                                                "type": "integer"
                                                            },
                                                            "succeeded": {
                                                                "type": "integer"
                                                            },
                                                            "failed": {
                                                                "type": "integer"
                                                            }
                                                        }
                                                    }
                                                },
                                                "by_error": {
                                                    "type": "array",
                                                    "description": "Разбивка по кодам ошибок.",
                                                    "items": {
                                                        "type": "object",
                                                        "required": [
                                                            "code",
                                                            "total"
                                                        ],
                                                        "properties": {
                                                            "code": {
                                                                "type": "string",
                                                                "description": "Код из справочника ошибок."
                                                            },
                                                            "total": {
                                                                "type": "integer"
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                },
                                "example": {
                                    "object": "api_key.usage",
                                    "key_id": 17,
                                    "period": {
                                        "from": "2026-10-03T10:20:00+00:00",
                                        "to": "2026-11-02T10:20:00+00:00"
                                    },
                                    "requests_limit": 5000,
                                    "requests_used_total": 127,
                                    "requests_remaining": 4873,
                                    "period_stats": {
                                        "total": 127,
                                        "succeeded": 121,
                                        "failed": 6,
                                        "by_day": [
                                            {
                                                "date": "2026-11-01",
                                                "total": 64,
                                                "succeeded": 61,
                                                "failed": 3
                                            },
                                            {
                                                "date": "2026-11-02",
                                                "total": 63,
                                                "succeeded": 60,
                                                "failed": 3
                                            }
                                        ],
                                        "by_model": [
                                            {
                                                "model": "main:upscale",
                                                "total": 98,
                                                "succeeded": 95,
                                                "failed": 3
                                            },
                                            {
                                                "model": "remove-bg:transparent",
                                                "total": 29,
                                                "succeeded": 26,
                                                "failed": 3
                                            }
                                        ],
                                        "by_error": [
                                            {
                                                "code": "content_policy_violation",
                                                "total": 6
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_key_not_found": {
                                        "summary": "api_key_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested API key does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "api_key_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        },
        "/models": {
            "get": {
                "tags": [
                    "Модели"
                ],
                "summary": "Каталог моделей",
                "description": "Возвращает каталог сценариев обработки: `id` подставляется в поле `model` запроса `POST /images`. Каталог одинаков для боевых и тестовых ключей.\n\nВ `input` перечислены только поля, которые модель принимает, со значением `required`. Поле, которого нет в `input`, модель игнорирует. Если `input` — пустой объект `{}`, модель работает без исходника и без промпта.\n\nКаталог меняется редко, поэтому ответ можно кэшировать на клиенте и обновлять, когда поменялось поле `created`.\n\nЧеловекочитаемый `label` совпадает с названием пункта в боте: таблица соответствия «модель API — пункт меню бота» есть на этой странице.",
                "operationId": "models",
                "responses": {
                    "200": {
                        "description": "Список моделей.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "object",
                                        "data"
                                    ],
                                    "properties": {
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "list"
                                            ]
                                        },
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/ApiModel"
                                            }
                                        }
                                    }
                                },
                                "example": {
                                    "object": "list",
                                    "data": [
                                        {
                                            "id": "main:upscale",
                                            "object": "model",
                                            "created": 1793664000,
                                            "owned_by": "fotbot",
                                            "label": "Улучшить качество",
                                            "input": {
                                                "image": "required"
                                            }
                                        },
                                        {
                                            "id": "main:text-to-image",
                                            "object": "model",
                                            "created": 1793664000,
                                            "owned_by": "fotbot",
                                            "label": "Новое изображение по описанию",
                                            "input": {
                                                "prompt": "required"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/tasks/{id}": {
            "get": {
                "tags": [
                    "Обработка"
                ],
                "summary": "Статус задачи",
                "description": "Возвращает информацию о задаче по `id`, полученному в ответе на `/images`.\n\n**Когда использовать:** повторяйте запросы, пока `status` равен `\"queued\"` или `\"processing\"`. Ориентируйтесь по полю `estimated_seconds`: оно показывает примерное время ожидания. Рекомендуемый интервал — 1–2 секунды.\n\n**Результат:** готовый файл появится в массиве `data[]`. При сбоях причина указана в объекте `error`.\n\n**Важно помнить:**\n\n* Опрос бесплатный и не влияет на лимиты вашего ключа.\n\n* Чужая задача недоступна (ошибка `404 task_not_found`).\n\n* В «песочнице» задачи удаляются спустя сутки вместе с результатом.\n\n* Публичная ссылка из поля `data[].url` доступна не менее 24 часов.",
                "operationId": "tasksShow",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "description": "Идентификатор задачи из ответа на `POST /images` — поле `id` (`req_…`).",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Текущее состояние задачи.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": [
                                        "id",
                                        "object",
                                        "status",
                                        "model",
                                        "created",
                                        "poll_url",
                                        "request_id"
                                    ],
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "description": "Идентификатор задачи (`req_…`). Это не номер заказа: опрашивайте по нему."
                                        },
                                        "object": {
                                            "type": "string",
                                            "enum": [
                                                "image.generation"
                                            ]
                                        },
                                        "status": {
                                            "type": "string",
                                            "enum": [
                                                "queued",
                                                "processing",
                                                "succeeded",
                                                "failed"
                                            ],
                                            "description": "Текущее состояние. `queued` и `processing` — опрашивайте дальше."
                                        },
                                        "model": {
                                            "type": "string",
                                            "description": "Идентификатор модели, с которой создана задача."
                                        },
                                        "created": {
                                            "type": "integer",
                                            "description": "Время создания задачи, Unix-время в секундах."
                                        },
                                        "started_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда задача ушла в работу. Нет у задач со статусом `queued`."
                                        },
                                        "completed_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда получен результат. Только у `succeeded`."
                                        },
                                        "failed_at": {
                                            "type": "string",
                                            "format": "date-time",
                                            "description": "Когда задача упала. Только у `failed`."
                                        },
                                        "estimated_seconds": {
                                            "type": "integer",
                                            "description": "Оценка ожидания в секундах. Есть только у `queued` и `processing`."
                                        },
                                        "data": {
                                            "type": "array",
                                            "description": "Готовые изображения. Всегда ровно один элемент. Только у `succeeded`.",
                                            "items": {
                                                "$ref": "#/components/schemas/ImageResult"
                                            }
                                        },
                                        "error": {
                                            "type": "object",
                                            "description": "Причина неудачи. Только у `failed`.",
                                            "required": [
                                                "message",
                                                "type",
                                                "code"
                                            ],
                                            "properties": {
                                                "message": {
                                                    "type": "string",
                                                    "description": "Что произошло."
                                                },
                                                "type": {
                                                    "type": "string",
                                                    "description": "Категория ошибки."
                                                },
                                                "code": {
                                                    "type": "string",
                                                    "description": "Код ошибки — тот же справочник, что и в конверте ошибки."
                                                }
                                            }
                                        },
                                        "usage": {
                                            "type": "object",
                                            "description": "Списание изображений. Только у `succeeded` и `failed`.",
                                            "required": [
                                                "generations",
                                                "balance_remaining"
                                            ],
                                            "properties": {
                                                "generations": {
                                                    "type": "integer",
                                                    "description": "Списано за задачу: `1` при успехе и `0` при ошибке (списание возвращается)."
                                                },
                                                "balance_remaining": {
                                                    "type": "integer",
                                                    "description": "Остаток изображений на аккаунте после списания."
                                                }
                                            }
                                        },
                                        "poll_url": {
                                            "type": "string",
                                            "format": "uri",
                                            "description": "Полный адрес для опроса статуса. Требует тот же ключ."
                                        },
                                        "request_id": {
                                            "type": "string",
                                            "description": "Идентификатор запроса, создавшего задачу. Совпадает с `X-Request-Id`."
                                        }
                                    }
                                },
                                "example": {
                                    "id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A",
                                    "object": "image.generation",
                                    "status": "succeeded",
                                    "model": "main:upscale",
                                    "created": 1793577600,
                                    "started_at": "2026-11-02T10:15:04+00:00",
                                    "completed_at": "2026-11-02T10:15:16+00:00",
                                    "data": [
                                        {
                                            "url": "https://fotbot.ru/storage/results/10231/5512_result_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6.jpg",
                                            "content_type": "image/jpeg",
                                            "width": 1024,
                                            "height": 1024,
                                            "bytes": 184320
                                        }
                                    ],
                                    "usage": {
                                        "generations": 1,
                                        "balance_remaining": 41
                                    },
                                    "poll_url": "https://fotbot.ru/api/v1/tasks/req_01HZY4K7M9XQ2V8B3N6T0R5S1A",
                                    "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Ключ не передан, отозван или просрочен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "invalid_api_key": {
                                        "summary": "invalid_api_key",
                                        "value": {
                                            "error": {
                                                "message": "Invalid API key.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "invalid_api_key"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_revoked": {
                                        "summary": "key_revoked",
                                        "value": {
                                            "error": {
                                                "message": "This API key has been revoked.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_revoked"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    },
                                    "key_expired": {
                                        "summary": "key_expired",
                                        "value": {
                                            "error": {
                                                "message": "This API key has expired.",
                                                "type": "authentication_error",
                                                "param": null,
                                                "code": "key_expired"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "Действие запрещено ключом: лимит запросов, объединение аккаунтов или режим песочницы.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "account_merged": {
                                        "summary": "account_merged",
                                        "value": {
                                            "error": {
                                                "message": "The account was merged into another one; use the keys of the target account.",
                                                "type": "permission_error",
                                                "param": null,
                                                "code": "account_merged"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Запрошенного объекта нет.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "task_not_found": {
                                        "summary": "task_not_found",
                                        "value": {
                                            "error": {
                                                "message": "The requested task does not exist.",
                                                "type": "invalid_request_error",
                                                "param": null,
                                                "code": "task_not_found"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "Превышен лимит частоты. Время ожидания — в заголовке `Retry-After`.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "rate_limit_exceeded": {
                                        "summary": "rate_limit_exceeded",
                                        "value": {
                                            "error": {
                                                "message": "Rate limit exceeded.",
                                                "type": "rate_limit_error",
                                                "param": null,
                                                "code": "rate_limit_exceeded"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "503": {
                        "description": "Приём запросов к API временно приостановлен.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                },
                                "examples": {
                                    "api_disabled": {
                                        "summary": "api_disabled",
                                        "value": {
                                            "error": {
                                                "message": "The API is temporarily unavailable.",
                                                "type": "server_error",
                                                "param": null,
                                                "code": "api_disabled"
                                            },
                                            "request_id": "req_01HZY4K7M9XQ2V8B3N6T0R5S1A"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "security": [
                    {
                        "bearerAuth": []
                    }
                ]
            }
        }
    },
    "components": {
        "schemas": {
            "ApiModel": {
                "type": "object",
                "required": [
                    "id",
                    "object",
                    "created",
                    "owned_by",
                    "label",
                    "input"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "description": "Идентификатор модели вида `<раздел>:<код>`. Именно его принимает `POST /images` в поле `model`.",
                        "examples": [
                            "main:upscale"
                        ]
                    },
                    "object": {
                        "type": "string",
                        "enum": [
                            "model"
                        ]
                    },
                    "created": {
                        "type": "integer",
                        "description": "Версия каталога: статичная метка, одинаковая для всех моделей."
                    },
                    "owned_by": {
                        "type": "string",
                        "description": "Владелец модели в терминах OpenAI-совместимых API."
                    },
                    "label": {
                        "type": "string",
                        "description": "Название сценария по-русски — как в интерфейсе бота."
                    },
                    "input": {
                        "type": "object",
                        "description": "Поля, которые модель принимает. Значение всегда `required`. Поле, которого нет в объекте, модель игнорирует.",
                        "properties": {
                            "image": {
                                "type": "string",
                                "enum": [
                                    "required"
                                ],
                                "description": "Модель принимает исходный файл или ссылку."
                            },
                            "prompt": {
                                "type": "string",
                                "enum": [
                                    "required"
                                ],
                                "description": "Модель принимает текст."
                            }
                        }
                    }
                }
            },
            "ImageTask": {
                "type": "object",
                "required": [
                    "id",
                    "object",
                    "status",
                    "model",
                    "created",
                    "poll_url",
                    "request_id"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "description": "Идентификатор задачи (`req_…`). Это не номер заказа: опрашивайте по нему."
                    },
                    "object": {
                        "type": "string",
                        "enum": [
                            "image.generation"
                        ]
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "queued",
                            "processing",
                            "succeeded",
                            "failed"
                        ],
                        "description": "Текущее состояние. `queued` и `processing` — опрашивайте дальше."
                    },
                    "model": {
                        "type": "string",
                        "description": "Идентификатор модели, с которой создана задача."
                    },
                    "created": {
                        "type": "integer",
                        "description": "Время создания задачи, Unix-время в секундах."
                    },
                    "started_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Когда задача ушла в работу. Нет у задач со статусом `queued`."
                    },
                    "completed_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Когда получен результат. Только у `succeeded`."
                    },
                    "failed_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Когда задача упала. Только у `failed`."
                    },
                    "estimated_seconds": {
                        "type": "integer",
                        "description": "Оценка ожидания в секундах. Есть только у `queued` и `processing`."
                    },
                    "data": {
                        "type": "array",
                        "description": "Готовые изображения. Всегда ровно один элемент. Только у `succeeded`.",
                        "items": {
                            "$ref": "#/components/schemas/ImageResult"
                        }
                    },
                    "error": {
                        "type": "object",
                        "description": "Причина неудачи. Только у `failed`.",
                        "required": [
                            "message",
                            "type",
                            "code"
                        ],
                        "properties": {
                            "message": {
                                "type": "string",
                                "description": "Что произошло."
                            },
                            "type": {
                                "type": "string",
                                "description": "Категория ошибки."
                            },
                            "code": {
                                "type": "string",
                                "description": "Код ошибки — тот же справочник, что и в конверте ошибки."
                            }
                        }
                    },
                    "usage": {
                        "type": "object",
                        "description": "Списание изображений. Только у `succeeded` и `failed`.",
                        "required": [
                            "generations",
                            "balance_remaining"
                        ],
                        "properties": {
                            "generations": {
                                "type": "integer",
                                "description": "Списано за задачу: `1` при успехе и `0` при ошибке (списание возвращается)."
                            },
                            "balance_remaining": {
                                "type": "integer",
                                "description": "Остаток изображений на аккаунте после списания."
                            }
                        }
                    },
                    "poll_url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Полный адрес для опроса статуса. Требует тот же ключ."
                    },
                    "request_id": {
                        "type": "string",
                        "description": "Идентификатор запроса, создавшего задачу. Совпадает с `X-Request-Id`."
                    }
                }
            },
            "ImageResult": {
                "type": "object",
                "required": [
                    "url",
                    "content_type",
                    "width",
                    "height",
                    "bytes"
                ],
                "properties": {
                    "url": {
                        "type": "string",
                        "format": "uri",
                        "description": "Прямая ссылка на файл. Доступна не менее 24 часов и не требует `Authorization`."
                    },
                    "content_type": {
                        "type": "string",
                        "description": "MIME-тип результата.",
                        "examples": [
                            "image/jpeg"
                        ]
                    },
                    "width": {
                        "type": "integer",
                        "description": "Ширина в пикселях."
                    },
                    "height": {
                        "type": "integer",
                        "description": "Высота в пикселях."
                    },
                    "bytes": {
                        "type": "integer",
                        "description": "Размер файла в байтах."
                    }
                }
            },
            "ApiKey": {
                "type": "object",
                "required": [
                    "id",
                    "object",
                    "name",
                    "mode",
                    "key_prefix",
                    "key_last4",
                    "requests_limit",
                    "requests_used",
                    "requests_remaining",
                    "status",
                    "expires_at",
                    "created_at",
                    "last_used_at",
                    "revoked_at"
                ],
                "properties": {
                    "id": {
                        "type": "integer",
                        "description": "Числовой идентификатор ключа."
                    },
                    "object": {
                        "type": "string",
                        "enum": [
                            "api_key"
                        ]
                    },
                    "name": {
                        "type": "string",
                        "description": "Название, заданное при выпуске."
                    },
                    "mode": {
                        "type": "string",
                        "enum": [
                            "live",
                            "test"
                        ],
                        "description": "`live` — боевой ключ, `test` — ключ песочницы."
                    },
                    "key_prefix": {
                        "type": "string",
                        "description": "Первые символы ключа — чтобы опознать его среди других."
                    },
                    "key_last4": {
                        "type": "string",
                        "description": "Последние четыре символа ключа."
                    },
                    "requests_limit": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "Потолок запросов для этого ключа. `null` — без ограничения."
                    },
                    "requests_used": {
                        "type": "integer",
                        "description": "Сколько запросов уже израсходовано."
                    },
                    "requests_remaining": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "Сколько запросов осталось. `null`, если лимита нет."
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "active",
                            "limit_reached",
                            "expired",
                            "revoked"
                        ],
                        "description": "Состояние ключа на момент ответа."
                    },
                    "expires_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time",
                        "description": "Когда ключ перестанет работать. `null` — бессрочный."
                    },
                    "created_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    },
                    "last_used_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time",
                        "description": "Последний запрос этим ключом. `null`, если ключ ещё не использовали."
                    },
                    "revoked_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time",
                        "description": "Когда ключ отозван. `null` для действующего."
                    }
                }
            },
            "ApiKeyUsage": {
                "type": "object",
                "required": [
                    "object",
                    "key_id",
                    "period",
                    "requests_limit",
                    "requests_used_total",
                    "requests_remaining",
                    "period_stats"
                ],
                "properties": {
                    "object": {
                        "type": "string",
                        "enum": [
                            "api_key.usage"
                        ]
                    },
                    "key_id": {
                        "type": "integer",
                        "description": "Ключ, к которому относится статистика."
                    },
                    "period": {
                        "type": "object",
                        "required": [
                            "from",
                            "to"
                        ],
                        "description": "Фактически применённый период. Если параметры не переданы — последние 30 дней.",
                        "properties": {
                            "from": {
                                "type": "string",
                                "format": "date-time"
                            },
                            "to": {
                                "type": "string",
                                "format": "date-time"
                            }
                        }
                    },
                    "requests_limit": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "Потолок запросов ключа. `null` — без ограничения."
                    },
                    "requests_used_total": {
                        "type": "integer",
                        "description": "Всего израсходовано за всё время жизни ключа."
                    },
                    "requests_remaining": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "Остаток запросов. `null`, если лимита нет."
                    },
                    "period_stats": {
                        "type": "object",
                        "required": [
                            "total",
                            "succeeded",
                            "failed",
                            "by_day",
                            "by_model",
                            "by_error"
                        ],
                        "properties": {
                            "total": {
                                "type": "integer",
                                "description": "Запросов за период."
                            },
                            "succeeded": {
                                "type": "integer",
                                "description": "Успешных за период."
                            },
                            "failed": {
                                "type": "integer",
                                "description": "Неудачных за период."
                            },
                            "by_day": {
                                "type": "array",
                                "description": "Разбивка по дням — только дни, в которые были запросы.",
                                "items": {
                                    "type": "object",
                                    "required": [
                                        "date",
                                        "total",
                                        "succeeded",
                                        "failed"
                                    ],
                                    "properties": {
                                        "date": {
                                            "type": "string",
                                            "format": "date"
                                        },
                                        "total": {
                                            "type": "integer"
                                        },
                                        "succeeded": {
                                            "type": "integer"
                                        },
                                        "failed": {
                                            "type": "integer"
                                        }
                                    }
                                }
                            },
                            "by_model": {
                                "type": "array",
                                "description": "Разбивка по моделям.",
                                "items": {
                                    "type": "object",
                                    "required": [
                                        "model",
                                        "total",
                                        "succeeded",
                                        "failed"
                                    ],
                                    "properties": {
                                        "model": {
                                            "type": "string",
                                            "description": "Идентификатор модели."
                                        },
                                        "total": {
                                            "type": "integer"
                                        },
                                        "succeeded": {
                                            "type": "integer"
                                        },
                                        "failed": {
                                            "type": "integer"
                                        }
                                    }
                                }
                            },
                            "by_error": {
                                "type": "array",
                                "description": "Разбивка по кодам ошибок.",
                                "items": {
                                    "type": "object",
                                    "required": [
                                        "code",
                                        "total"
                                    ],
                                    "properties": {
                                        "code": {
                                            "type": "string",
                                            "description": "Код из справочника ошибок."
                                        },
                                        "total": {
                                            "type": "integer"
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "Account": {
                "type": "object",
                "required": [
                    "object",
                    "id",
                    "email_masked",
                    "balance",
                    "keys",
                    "limits",
                    "usage_24h",
                    "generations_used_24h",
                    "generations_used_30d",
                    "sandbox"
                ],
                "properties": {
                    "object": {
                        "type": "string",
                        "enum": [
                            "account"
                        ]
                    },
                    "id": {
                        "type": "string",
                        "description": "Идентификатор аккаунта с префиксом `usr_`."
                    },
                    "email_masked": {
                        "type": "string",
                        "description": "Почта с маской вместо локальной части — для опознания своего аккаунта."
                    },
                    "balance": {
                        "type": "object",
                        "required": [
                            "generations"
                        ],
                        "properties": {
                            "generations": {
                                "type": "integer",
                                "description": "Сколько изображений доступно."
                            }
                        }
                    },
                    "keys": {
                        "type": "object",
                        "required": [
                            "active",
                            "test_active",
                            "limit"
                        ],
                        "properties": {
                            "active": {
                                "type": "integer",
                                "description": "Активных боевых ключей."
                            },
                            "test_active": {
                                "type": "integer",
                                "description": "Активных тестовых ключей."
                            },
                            "limit": {
                                "type": "integer",
                                "description": "Максимум активных ключей на аккаунт."
                            }
                        }
                    },
                    "limits": {
                        "type": "object",
                        "required": [
                            "rate_per_minute",
                            "rate_per_hour",
                            "max_image_bytes"
                        ],
                        "properties": {
                            "rate_per_minute": {
                                "type": "integer",
                                "description": "Запросов в минуту на ключ."
                            },
                            "rate_per_hour": {
                                "type": "integer",
                                "description": "Запросов в час на ключ."
                            },
                            "max_image_bytes": {
                                "type": "integer",
                                "description": "Потолок размера исходного изображения."
                            }
                        }
                    },
                    "usage_24h": {
                        "type": "object",
                        "required": [
                            "total",
                            "succeeded",
                            "failed"
                        ],
                        "description": "Запросы к `/images` за сутки. Только боевые.",
                        "properties": {
                            "total": {
                                "type": "integer"
                            },
                            "succeeded": {
                                "type": "integer"
                            },
                            "failed": {
                                "type": "integer"
                            }
                        }
                    },
                    "generations_used_24h": {
                        "type": "integer",
                        "description": "Списано изображений за сутки."
                    },
                    "generations_used_30d": {
                        "type": "integer",
                        "description": "Списано изображений за 30 дней."
                    },
                    "sandbox": {
                        "type": "object",
                        "required": [
                            "requests_24h"
                        ],
                        "description": "Тестовый трафик — отдельно от боевого.",
                        "properties": {
                            "requests_24h": {
                                "type": "integer",
                                "description": "Запросов тестовым ключом за сутки."
                            }
                        }
                    }
                }
            },
            "Health": {
                "type": "object",
                "required": [
                    "status",
                    "version",
                    "time"
                ],
                "properties": {
                    "status": {
                        "type": "string",
                        "enum": [
                            "ok",
                            "degraded"
                        ],
                        "description": "`ok` — сервис работает штатно; `degraded` — обработка задач временно задерживается."
                    },
                    "version": {
                        "type": "string",
                        "description": "Версия API.",
                        "examples": [
                            "v1"
                        ]
                    },
                    "time": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Время ответа в UTC."
                    }
                }
            },
            "Error": {
                "type": "object",
                "required": [
                    "error",
                    "request_id"
                ],
                "description": "Ошибка. HTTP-статус совпадает с `error.status`, если он указан в описании эндпоинта.",
                "properties": {
                    "error": {
                        "type": "object",
                        "required": [
                            "message",
                            "type",
                            "param",
                            "code"
                        ],
                        "properties": {
                            "message": {
                                "type": "string",
                                "description": "Что произошло. Текст на английском, его можно показывать разработчику."
                            },
                            "type": {
                                "type": "string",
                                "description": "Категория ошибки — удобно для ветвления в клиенте.",
                                "enum": [
                                    "authentication_error",
                                    "insufficient_quota",
                                    "permission_error",
                                    "invalid_request_error",
                                    "rate_limit_error",
                                    "server_error"
                                ]
                            },
                            "param": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": "Имя поля или параметра, из-за которого запрос отклонён. `null`, если ошибка не связана с конкретным полем."
                            },
                            "code": {
                                "type": "string",
                                "description": "Машиночитаемый код. Полный список — в разделе «Ошибки».",
                                "enum": [
                                    "invalid_api_key",
                                    "key_revoked",
                                    "key_expired",
                                    "insufficient_balance",
                                    "key_limit_reached",
                                    "account_merged",
                                    "sandbox_scope_violation",
                                    "model_not_found",
                                    "task_not_found",
                                    "api_key_not_found",
                                    "idempotency_conflict",
                                    "image_too_large",
                                    "unsupported_image_format",
                                    "image_required",
                                    "image_too_small",
                                    "invalid_image_url",
                                    "prompt_required",
                                    "content_policy_violation",
                                    "too_many_keys",
                                    "limit_below_used",
                                    "invalid_idempotency_key",
                                    "sandbox_not_allowed",
                                    "rate_limit_exceeded",
                                    "generation_failed",
                                    "provider_blocked",
                                    "api_disabled"
                                ]
                            }
                        }
                    },
                    "request_id": {
                        "type": "string",
                        "description": "Идентификатор запроса. Совпадает с заголовком `X-Request-Id`."
                    }
                }
            }
        },
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "Ключ API из личного кабинета. Префикс `test_` — песочница."
            }
        }
    }
}