# Set model limits

Source: [Set model limits](<https://docs.gptunnel.ru/en/access/model-limits/>)

<a id="_top"></a>
> **Note: Organization API key**
>
> Use an API key for your organization with the Full dashboard access permission. See the roles and restrictions below. [Get an API key](<https://docs.gptunnel.ru/en/>).

<a id="model-limits"></a>
## Model limits

`POST https://gptunnel.ru/api/v1/access/setModelLimits`

Set a daily or monthly spending limit on specific models for each employee. Send up to 25 `{ login, models }` entries. The server processes each employee independently. If the same login appears more than once, it applies only the first entry.

> **Note: Model limits and access permissions**
>
> This endpoint changes spending limits independently of the model’s allow/forbid permission. To change that permission, use [model access](<https://docs.gptunnel.ru/en/access/models/>).

<a id="limit-values"></a>
## Limit values

Each `models` entry contains `{ model, dailyLimit?, monthlyLimit? }`.

### Fields in models\[\]

| Parameter | Type | Description |
| --- | --- | --- |
| `model` (required) | `string` | Model ID from GET /v1/models, for example claude-5.5-haiku. An unknown ID returns model\_not\_found for this login. |
| `dailyLimit` | `number` | Daily limit in whole rubles (RUB). A fractional value returns HTTP 400. 0 = no limit |
| `monthlyLimit` | `number` | Monthly limit in whole rubles (RUB). A fractional value returns HTTP 400. 0 = no limit |

Supply at least one of `dailyLimit` and `monthlyLimit`. Only the fields you supply are updated.

> **Tip: 0 means unlimited**
>
> Set the limit to `0` to remove it.

<a id="who-can-make-changes"></a>
## Who can make changes

The API checks the key creator’s current role:

- The creator must be an **owner**, **admin**, or **manager**. Otherwise the entire request returns HTTP `403`.
- Owners and admins can update other employees whose role is equal to or below their own. Trying to update their own account or someone with a higher role returns `forbidden` for that login.
- Managers can update only members of their own teams. They can set or lower a limit. Raising or removing it returns `forbidden` for that login.

> **Caution: Business organizations only**
>
> Personal-account keys and keys whose creator has the member role receive HTTP `403`.

### Request headers

| Parameter | Type | Description |
| --- | --- | --- |
| `Authorization` (required) | `string` | API key |

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `items` (required) | `object[]` | Array of 1–25 items. Each item contains { login, models }. |
| `items[].login` (required) | `string` | Employee login |
| `items[].models` (required) | `object[]` | List of 1–100 items of the form { model, dailyLimit?, monthlyLimit? }. Set at least one limit per item |

The response counts successful updates in `updated` and failures in `failed`. Each entry in `failedLogins` identifies the login and explains the error. For `model_not_found`, `unknownModels` lists all unrecognized model IDs for that login. No model updates are applied to that employee.

Error reasons in `failedLogins`:

### Error reasons

| Parameter | Type | Description |
| --- | --- | --- |
| `not_found` | `string` | No employee in the organization has this login |
| `forbidden` | `string` | The employee has a higher role or is the key creator. For a manager, the employee is not a member of their teams or the change weakens the organization’s restrictions. |
| `model_not_found` | `string` | unknownModels lists all unrecognized model IDs. No model limits are applied for this login. |
| `error` | `string` | An unexpected error occurred while processing this employee |

<a id="example-request"></a>
### Example request

Set `GPTUNNEL_API_KEY` and replace the placeholders with values for your organization.

<a id="tab-panel-0-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

key = os.environ.get("GPTUNNEL_API_KEY")
if not key:
    raise SystemExit("Set GPTUNNEL_API_KEY")

body = {
  "items": [
    {
      "login": "ivanov",
      "models": [
        {
          "model": "claude-5.5-haiku",
          "dailyLimit": 500,
          "monthlyLimit": 10000
        },
        {
          "model": "gpt-6-luna",
          "dailyLimit": 0
        }
      ]
    }
  ]
}
request = Request(
    "https://gptunnel.ru/api/v1/access/setModelLimits",
    method="POST",
    headers={
        "Authorization": key,
        "Content-Type": "application/json",
    },
    data=json.dumps(body).encode("utf-8"),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --request POST \
  --url 'https://gptunnel.ru/api/v1/access/setModelLimits' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "items": [
    {
      "login": "ivanov",
      "models": [
        {
          "model": "claude-5.5-haiku",
          "dailyLimit": 500,
          "monthlyLimit": 10000
        },
        {
          "model": "gpt-6-luna",
          "dailyLimit": 0
        }
      ]
    }
  ]
}'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
const key = process.env.GPTUNNEL_API_KEY
if (!key) throw new Error("Set GPTUNNEL_API_KEY")

const body = {
  "items": [
    {
      "login": "ivanov",
      "models": [
        {
          "model": "claude-5.5-haiku",
          "dailyLimit": 500,
          "monthlyLimit": 10000
        },
        {
          "model": "gpt-6-luna",
          "dailyLimit": 0
        }
      ]
    }
  ]
}
const response = await fetch("https://gptunnel.ru/api/v1/access/setModelLimits", {
  method: "POST",
  headers: {
    Authorization: key,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(body),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="example-response"></a>
### Example response

<a id="tab-panel-1-0"></a>
**200 OK**

```json
{
  "code": 0,
  "updated": 1,
  "failed": 0,
  "failedLogins": []
}
```

<a id="tab-panel-1-1"></a>
**400 Invalid input**

```json
{
  "code": 3,
  "message": "Invalid input, check schema issues.",
  "details": []
}
```

<a id="tab-panel-1-2"></a>
**401 Unauthorized**

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

<a id="tab-panel-1-3"></a>
**403 Forbidden**

```json
{
  "code": 7,
  "message": "Not allowed to perform this action for the organization."
}
```

<a id="tab-panel-1-4"></a>
**403 Personal account**

```json
{
  "code": 13,
  "message": "This section is not available from a personal account. Use a business organization API key."
}
```

<a id="tab-panel-1-5"></a>
**500 Server error**

```json
{
  "code": 1,
  "message": "Internal server error.",
  "trace_id": "66a346f64dcb57627c03d596"
}
```
