Policy Rules

Guardrails организации: бюджет, доступ к моделям, контент, сеть, журнал и лимиты запросов. Концепция — в возможностях. Раздел кабинета и изменения — у владельца

GET
/api/organization/policy/rules
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Параметры query

limit?integer
offset?integer

Тело ответа

application/json

curl -X GET "https://example.com/api/organization/policy/rules"
{
  "items": [
    {
      "id": "string",
      "clientSubject": {
        "type": "organization",
        "id": "string"
      },
      "providerSlug": "string",
      "catalogModelId": "string",
      "note": "string",
      "status": "active",
      "access": {
        "allowedModels": [
          "string"
        ],
        "allowedProviders": [
          "string"
        ],
        "deniedModels": [
          "string"
        ],
        "deniedProviders": [
          "string"
        ]
      },
      "budget": {
        "scope": "organization",
        "limits": [
          {
            "limitRub": 1,
            "resetInterval": "string"
          }
        ],
        "limitRub": 1,
        "resetInterval": "string"
      },
      "content": {
        "mode": "enforce",
        "pii": {
          "enabled": true,
          "types": [
            "string"
          ],
          "action": "block",
          "allowList": [
            "string"
          ]
        },
        "content": {
          "enabled": true,
          "categories": [
            "string"
          ],
          "action": "block"
        },
        "customPatterns": [
          {
            "pattern": "string",
            "action": "block",
            "label": "string"
          }
        ],
        "promptInjection": {
          "enabled": true,
          "action": "block",
          "patterns": [
            "string"
          ]
        }
      },
      "network": {
        "allowedIPs": [
          "string"
        ]
      },
      "rateLimit": {
        "rpm": 1,
        "tpm": 1
      },
      "logging": {
        "enabled": true
      },
      "createdAt": "2019-08-24T14:15:22Z",
      "updatedAt": "2019-08-24T14:15:22Z",
      "createdByEmail": "string"
    }
  ],
  "total": 0,
  "limit": 0,
  "offset": 0
}
POST
/api/organization/policy/rules

Нужен clientSubject и хотя бы один модуль: access, budget, content, network, rateLimit, logging. Неизвестное поле — 400 с текстом «Некорректный JSON». Повтор того же клиента, провайдера и модели — 409.

АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело запроса

application/json

Тело ответа

application/json

application/json

application/json

curl -X POST "https://example.com/api/organization/policy/rules" \  -H "Content-Type: application/json" \  -d '{    "clientSubject": {      "type": "api_key",      "id": "key_001"    },    "status": "active",    "budget": {      "scope": "api_key",      "limits": [        {          "limitRub": 5000,          "resetInterval": "monthly"        }      ]    }  }'
{
  "id": "string",
  "clientSubject": {
    "type": "organization",
    "id": "string"
  },
  "providerSlug": "string",
  "catalogModelId": "string",
  "note": "string",
  "status": "active",
  "access": {
    "allowedModels": [
      "string"
    ],
    "allowedProviders": [
      "string"
    ],
    "deniedModels": [
      "string"
    ],
    "deniedProviders": [
      "string"
    ]
  },
  "budget": {
    "scope": "organization",
    "limits": [
      {
        "limitRub": 1,
        "resetInterval": "string"
      }
    ],
    "limitRub": 1,
    "resetInterval": "string"
  },
  "content": {
    "mode": "enforce",
    "pii": {
      "enabled": true,
      "types": [
        "string"
      ],
      "action": "block",
      "allowList": [
        "string"
      ]
    },
    "content": {
      "enabled": true,
      "categories": [
        "string"
      ],
      "action": "block"
    },
    "customPatterns": [
      {
        "pattern": "string",
        "action": "block",
        "label": "string"
      }
    ],
    "promptInjection": {
      "enabled": true,
      "action": "block",
      "patterns": [
        "string"
      ]
    }
  },
  "network": {
    "allowedIPs": [
      "string"
    ]
  },
  "rateLimit": {
    "rpm": 1,
    "tpm": 1
  },
  "logging": {
    "enabled": true
  },
  "createdAt": "2019-08-24T14:15:22Z",
  "updatedAt": "2019-08-24T14:15:22Z",
  "createdByEmail": "string"
}
{
  "error": "string"
}
{
  "error": "string"
}
PATCH
/api/organization/policy/rules/{ruleId}

Переданные модули заменяют прежние. Если в теле есть clientSubject, непереданные модули снимаются.

АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Параметры пути

ruleId*string

Тело запроса

application/json

Тело ответа

application/json

application/json

application/json

curl -X PATCH "https://example.com/api/organization/policy/rules/string" \  -H "Content-Type: application/json" \  -d '{}'
{
  "id": "string",
  "clientSubject": {
    "type": "organization",
    "id": "string"
  },
  "providerSlug": "string",
  "catalogModelId": "string",
  "note": "string",
  "status": "active",
  "access": {
    "allowedModels": [
      "string"
    ],
    "allowedProviders": [
      "string"
    ],
    "deniedModels": [
      "string"
    ],
    "deniedProviders": [
      "string"
    ]
  },
  "budget": {
    "scope": "organization",
    "limits": [
      {
        "limitRub": 1,
        "resetInterval": "string"
      }
    ],
    "limitRub": 1,
    "resetInterval": "string"
  },
  "content": {
    "mode": "enforce",
    "pii": {
      "enabled": true,
      "types": [
        "string"
      ],
      "action": "block",
      "allowList": [
        "string"
      ]
    },
    "content": {
      "enabled": true,
      "categories": [
        "string"
      ],
      "action": "block"
    },
    "customPatterns": [
      {
        "pattern": "string",
        "action": "block",
        "label": "string"
      }
    ],
    "promptInjection": {
      "enabled": true,
      "action": "block",
      "patterns": [
        "string"
      ]
    }
  },
  "network": {
    "allowedIPs": [
      "string"
    ]
  },
  "rateLimit": {
    "rpm": 1,
    "tpm": 1
  },
  "logging": {
    "enabled": true
  },
  "createdAt": "2019-08-24T14:15:22Z",
  "updatedAt": "2019-08-24T14:15:22Z",
  "createdByEmail": "string"
}
{
  "error": "string"
}
{
  "error": "string"
}
DELETE
/api/organization/policy/rules/{ruleId}
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Параметры пути

ruleId*string

Тело ответа

curl -X DELETE "https://example.com/api/organization/policy/rules/string"
Пусто
GET
/api/organization/policy/form-options
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело ответа

application/json

curl -X GET "https://example.com/api/organization/policy/form-options"
{}
POST
/api/organization/policy/evaluate
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело запроса

application/json

Тело ответа

application/json

curl -X POST "https://example.com/api/organization/policy/evaluate" \  -H "Content-Type: application/json" \  -d '{}'
{}
POST
/api/organization/policy/preview
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело запроса

application/json

Тело ответа

application/json

curl -X POST "https://example.com/api/organization/policy/preview" \  -H "Content-Type: application/json" \  -d '{}'
{}
GET
/api/organization/virtual-groups
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело ответа

application/json

curl -X GET "https://example.com/api/organization/virtual-groups"
[
  {}
]
POST
/api/organization/virtual-groups
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело запроса

application/json

Тело ответа

application/json

curl -X POST "https://example.com/api/organization/virtual-groups" \  -H "Content-Type: application/json" \  -d '{    "slug": "string",    "name": "string"  }'
{}
PATCH
/api/organization/virtual-groups/{groupId}
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Параметры пути

groupId*string

Тело запроса

application/json

Тело ответа

application/json

curl -X PATCH "https://example.com/api/organization/virtual-groups/string" \  -H "Content-Type: application/json" \  -d '{}'
{}
DELETE
/api/organization/virtual-groups/{groupId}
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Параметры пути

groupId*string

Тело ответа

curl -X DELETE "https://example.com/api/organization/virtual-groups/string"
Пусто
GET
/api/organization/systems
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело ответа

application/json

curl -X GET "https://example.com/api/organization/systems"
[
  {}
]
POST
/api/organization/systems
АвторизацияBearer <token>

Токен сессии кабинета или ключ sk-mgmt-…. Не sk-… моделей.

Где: header

Тело запроса

application/json

Тело ответа

application/json

curl -X POST "https://example.com/api/organization/systems" \  -H "Content-Type: application/json" \  -d '{    "slug": "string",    "name": "string"  }'
{}

Правило вешается на клиента (clientSubject) и содержит хотя бы один модуль: access, budget, content, network, rateLimit или logging. Повтор того же клиента, провайдера и модели — 409. Для личного аккаунта clientSubject только organization и api_key. Виртуальные группы — только бизнес-организации.

Неизвестное имя поля на POST отклоняет весь запрос: 400 и текст «Некорректный JSON». Имя лишнего поля в ответе не пишется.

Бюджет на ключ

Кабинет сохраняет бюджет так: budget.scope равен типу клиента, сумма и период лежат в budget.limits. На ключ это выглядит так:

curl -s -X POST "https://www.llmmart.ru/api/organization/policy/rules" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "clientSubject": { "type": "api_key", "id": "key_001" },
    "status": "active",
    "budget": {
      "scope": "api_key",
      "limits": [
        { "limitRub": 5000, "resetInterval": "monthly" }
      ]
    }
  }'

TOKEN — токен сессии или ключ sk-mgmt-….

resetInterval: daily, weekly, monthly или свой период из целого числа и h / d (24h, 7d). Другое значение лимит отбрасывает. Если после этого в правиле не осталось ни одного модуля, ответ — «укажите хотя бы один модуль политики».

scope — по кому ведётся счётчик: organization, member, virtual_group, system или api_key. В кабинете он всегда совпадает с clientSubject.type; в API его нужно передать явно и тем же значением.

В ответе 201 сумма и период уже только в limits. Корневые budget.limitRub и budget.resetInterval можно передать как одну плоскую пару вместо массива — сервер свернёт их в limits и в сохранённом правиле не вернёт.

Список правил — объект { items, total, limit, offset }, не массив.

Что дальше

На этой странице