Limit concurrent generations
Concurrent generation limits protect the organization from bursts of requests, such as an integration starting hundreds of tasks by mistake. They correspond to the concurrent generation settings in the dashboard:
inflightCountLimitlimits the number of generations running at once.inflightRubLimitlimits their combined cost in rubles.maxCostLimitsets the maximum cost of one generation in rubles. More expensive generations are rejected.
Once a limit is reached, new generations are blocked until enough in-flight tasks finish. The employee sees the rejection without the limit values. Organization, team, and employee limits all apply at the same time. The strictest limit wins.
Who can make changes
Section titled “Who can make changes”Only keys whose creator is an owner or admin can change concurrent generation limits. A manager cannot change these limits for their own teams or team members. Each such item returns forbidden. An organization-level request from a manager returns HTTP 403. A personal account key or a key whose creator has the member role receives HTTP 403 for the entire request.
A key creator cannot change the limits on their own account or on an employee with a higher role. For example, an admin cannot change an owner’s limits.
Staff members
Section titled “Staff members”https://gptunnel.ru/api/v1/access/setInflightLimitsSend 1 to 25 employee entries in items. If a login appears more than once, only its first entry is applied. An error for one employee does not stop the request from processing the others.
Request headers
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | API key |
Request parameters
| Parameter | Type | Description |
|---|---|---|
items* | object[] | Array of 1–25 employees. Each item has this shape: { login, inflightCountLimit?, inflightRubLimit?, maxCostLimit? } |
items[].login* | string | Employee login. Matching is case-insensitive. |
items[].inflightCountLimit | number | Maximum number of concurrent generations. Use an integer from 0 to 1,000,000. Use 0 for no limit. |
items[].inflightRubLimit | number | Maximum combined cost of running generations, in whole rubles (RUB). Use 0 for no limit. |
items[].maxCostLimit | number | Maximum cost of a single generation, in whole rubles (RUB). Use 0 for no limit. |
The response counts successful employee updates in updated and failures in failed. Each entry in failedLogins identifies the login and explains the error.
Error reasons
| Parameter | Type | Description |
|---|---|---|
not_found | string | No employee in the organization has this login |
forbidden | string | The caller is a manager, the target is the key creator, or the employee has a higher role than the caller. |
error | string | Unexpected error processing this employee. Retry the request. |
Example request
Section titled “Example request”Set GPTUNNEL_API_KEY and replace the placeholders with values for your organization.
import jsonimport osfrom 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@company.com", "inflightCountLimit": 2, "inflightRubLimit": 500, "maxCostLimit": 150 }, { "login": "petrov@company.com", "maxCostLimit": 0 } ]}request = Request( "https://gptunnel.ru/api/v1/access/setInflightLimits", 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))curl --request POST \ --url 'https://gptunnel.ru/api/v1/access/setInflightLimits' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "items": [ { "login": "ivanov@company.com", "inflightCountLimit": 2, "inflightRubLimit": 500, "maxCostLimit": 150 }, { "login": "petrov@company.com", "maxCostLimit": 0 } ]}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "items": [ { "login": "ivanov@company.com", "inflightCountLimit": 2, "inflightRubLimit": 500, "maxCostLimit": 150 }, { "login": "petrov@company.com", "maxCostLimit": 0 } ]}const response = await fetch("https://gptunnel.ru/api/v1/access/setInflightLimits", { 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())Example response
Section titled “Example response”{ "code": 0, "updated": 1, "failed": 1, "failedLogins": [ { "login": "petrov@company.com", "reason": "not_found", "message": "Employee not found in the organization." } ]}{ "code": 3, "message": "Invalid input, check schema issues.", "details": [ { "code": "invalid_type", "expected": "integer", "received": "float", "message": "Limit must be a whole number", "path": ["items", 0, "inflightCountLimit"] } ]}{ "code": 7, "message": "Not allowed to perform this action for the organization."}https://gptunnel.ru/api/v1/access/setTeamInflightLimitsThe limits apply to the entire team. Send up to 25 entries in items, each with { teamId, inflightCountLimit?, inflightRubLimit?, maxCostLimit? }. Get teamId from POST /api/v1/employees/getTeams. The response counts successes and failures in updated and failed. Each entry in failedTeams has a reason: not_found for a team outside the organization, forbidden for a manager’s key, or error.
import jsonimport osfrom 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", "inflightCountLimit": 3, "inflightRubLimit": 1000 } ]}request = Request( "https://gptunnel.ru/api/v1/access/setTeamInflightLimits", 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))curl --request POST \ --url 'https://gptunnel.ru/api/v1/access/setTeamInflightLimits' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "items": [ { "teamId": "664f0a1b2c3d4e5f60718293", "inflightCountLimit": 3, "inflightRubLimit": 1000 } ]}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "items": [ { "teamId": "664f0a1b2c3d4e5f60718293", "inflightCountLimit": 3, "inflightRubLimit": 1000 } ]}const response = await fetch("https://gptunnel.ru/api/v1/access/setTeamInflightLimits", { 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()){ "code": 0, "updated": 1, "failed": 0, "failedTeams": []}Organizations
Section titled “Organizations”https://gptunnel.ru/api/v1/access/setOrgInflightLimitsSend a single object, { inflightCountLimit?, inflightRubLimit?, maxCostLimit? }, as the request body. A manager’s key receives HTTP 403.
import jsonimport osfrom urllib.request import Request, urlopen
key = os.environ.get("GPTUNNEL_API_KEY")if not key: raise SystemExit("Set GPTUNNEL_API_KEY")
body = { "maxCostLimit": 5000}request = Request( "https://gptunnel.ru/api/v1/access/setOrgInflightLimits", 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))curl --request POST \ --url 'https://gptunnel.ru/api/v1/access/setOrgInflightLimits' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "maxCostLimit": 5000}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "maxCostLimit": 5000}const response = await fetch("https://gptunnel.ru/api/v1/access/setOrgInflightLimits", { 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()){ "code": 0, "updated": true}Read the current values in the inflight object returned by the access settings methods.