---
title: POST /api/v1/auth/agent-token
description: Mint Agent Token
locale: ru
version: 0.2.0
canonical: https://enterium-developer-docs.pages.dev/developers/ru/api/auth/post-auth-agent-token/
---

> Documentation index: https://enterium-developer-docs.pages.dev/developers/llms.txt — every page of this portal has a Markdown twin at <route>.md; the frozen API contract is at https://enterium-developer-docs.pages.dev/developers/api/openapi.json.

:::note
Сгенерировано из OpenAPI-контракта — не редактировать руками. Сводки операций и описания полей приводятся на английском (дословно из контракта). Интерактивный обозреватель с полными схемами: [https://entherium.duckdns.org:8443/reference](https://entherium.duckdns.org:8443/reference); замороженная спецификация этой сборки: [openapi.json](/developers/api/openapi.json). Группа: [auth](../).
:::

Mint Agent Token

mint (or rotate) a scoped AGENT token + its contract grants.

Superuser-only. Creates (or reuses) the agent identity and REPLACES its grant pool
with `body.grants` (default-deny — a contract not listed is inaccessible). Changing
the pool or capabilities later is a grant edit, no re-mint needed. `publish` is granted only when listed
explicitly: withhold on prod contracts by default).

**Авторизация:** нужен `Authorization: Bearer <token>`

## Запрос

```sh
curl -sS -X POST "https://entherium.duckdns.org:8443/api/v1/auth/agent-token" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{"email":"agent@entherium.dev","expires_days":90,"full_name":"Partner agent","grants":[{"capabilities":["submit","launch","cancel","edit_config"],"salescontract":40}],"revoke_prior":true}'
```

## Ответ `200`

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiJ9.<payload>.<signature>",
  "api_scope": "agent",
  "email": "agent@entherium.dev",
  "expires_in": 7776000,
  "token_type": "bearer",
  "user_guid": 5
}
```

## Возвращает

`ServiceTokenResponse` — Successful Response

| Поле | Тип | Описание |
| --- | --- | --- |
| `access_token` | `string` |  |
| `api_scope` | `string` |  |
| `email` | `string` |  |
| `expires_in` | `integer` |  |
| `token_type` | `string` (opt.) |  |
| `user_guid` | `integer` |  |

## Параметры

| Параметр | Где | Обязателен | Тип | По умолчанию | Ограничения | Описание |
| --- | --- | --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | нет | `string` | — | uuid | Optional. |

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

| Поле | Тип | Обязательно | Описание |
| --- | --- | --- | --- |
| `email` | `string` | нет |  |
| `expires_days` | `integer` | нет |  |
| `full_name` | `string \| null` | нет |  |
| `grants` | `массив AgentGrantSpec` | да |  |
| `revoke_prior` | `boolean` | нет |  |

_Пример:_

```json
{
  "email": "agent@entherium.dev",
  "expires_days": 90,
  "full_name": "Partner agent",
  "grants": [
    {
      "capabilities": [
        "submit",
        "launch",
        "cancel",
        "edit_config"
      ],
      "salescontract": 40
    }
  ],
  "revoke_prior": true
}
```

## Ошибки

| Код | Смысл | Тело |
| --- | --- | --- |
| `401` | Missing or invalid authentication credentials | `ErrorResponse` |
| `409` | The e-mail belongs to a non-agent user; refusing to convert | `ErrorResponse` |
| `422` | Validation Error | `HTTPValidationError` |

Тело любой ошибки — `{detail, code?, request_id, doc_url}`: `request_id` — что цитировать, `doc_url` ведёт в [Справочник ошибок](../../../reference/errors/).
