# Set team model limits

Source: [Set team model limits](<https://docs.gptunnel.ru/en/access/team-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="simulates-on-the-model-for-the-team"></a>
 
<a id="per-model-spending-limits-for-teams"></a>
## Per-model spending limits for teams

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

Set daily or monthly spending limits per model for teams. Send up to 25 `{ teamId, models }` entries. Each entry is processed independently. If a team ID repeats, only its first entry is used.

To find a `teamId` as an owner, admin, or manager, see [read team settings](<https://docs.gptunnel.ru/en/access/read-settings/#teams>). Get each `model` ID from [`GET /v1/models`](<https://docs.gptunnel.ru/en/api/models/>).

> **Tip: 0 means unlimited**
>
> Use whole rubles (RUB). `0` means no limit. Supply at least one of `dailyLimit` and `monthlyLimit`; omitted fields keep their current values. The model access permission (allow/forbid) is independent of its limits.

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

> **Caution: Who can change team settings?**
>
> Use a business organization’s key. Owners and admins can update any team in the organization. Managers can only tighten restrictions for teams they manage. They cannot raise or remove a limit. An invalid change returns `forbidden` for the affected team. A personal account key or a key whose creator has the member role receives HTTP `403` for the entire request.

### Request headers

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

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `items` (required) | `object[]` | Array of 1 to 25 entries. Each contains { teamId, models }. |
| `items[].teamId` (required) | `string` | Team ID from POST /api/v1/employees/getTeams. |
| `items[].models` (required) | `object[]` | List of 1–100 items of the form { model, dailyLimit?, monthlyLimit? }. Set at least one limit per item. Limits use whole rubles (RUB). A fractional value returns HTTP 400. Use 0 for no limit |

The response counts successful updates in `updated` and failures in `failed`. Each entry in `failedTeams` identifies the team and explains the failure. For `model_not_found`, `unknownModels` lists the unknown model IDs. No changes are applied to that team.

Error reasons in `failedTeams`:

### Error reasons

| Parameter | Type | Description |
| --- | --- | --- |
| `not_found` | `string` | No team in the organization has this ID |
| `model_not_found` | `string` | unknownModels lists the unrecognized model IDs. No limits were applied to the team. |
| `forbidden` | `string` | The team is outside the manager’s scope or the change weakens the organization’s restrictions. |
| `error` | `string` | Unexpected error processing this team |

<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": [
    {
      "teamId": "664f0a1b2c3d4e5f60718293",
      "models": [
        {
          "model": "claude-5.5-haiku",
          "dailyLimit": 500,
          "monthlyLimit": 10000
        },
        {
          "model": "gpt-6-luna",
          "dailyLimit": 0
        }
      ]
    }
  ]
}
request = Request(
    "https://gptunnel.ru/api/v1/access/setTeamModelLimits",
    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/setTeamModelLimits' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "items": [
    {
      "teamId": "664f0a1b2c3d4e5f60718293",
      "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": [
    {
      "teamId": "664f0a1b2c3d4e5f60718293",
      "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/setTeamModelLimits", {
  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,
  "failedTeams": []
}
```

<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>
**500 Server error**

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