Set model access
Set model access for employees
Section titled “Set model access for employees”https://gptunnel.ru/api/v1/access/setModelAccessAllow or deny access to specific models for each employee. Send up to 25 { login, models } entries. 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.
Values and models
Section titled “Values and models”Each models entry contains { model, permission }.
Fields in models[]
| Parameter | Type | Description |
|---|---|---|
model* | string | Model ID from GET /v1/models, for example claude-5.5-haiku. An unknown ID returns model_not_found for this login. |
permission* | string | Model access permission: allow, forbid, or default |
Permission values
| Parameter | Type | Description |
|---|---|---|
allow | string | Allow this employee to use the model |
forbid | string | Block this model for the employee |
default | string | Remove the employee-specific permission and use the default |
Who can make changes
Section titled “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
forbiddenfor that login. - Managers can update only members of their own teams. They can restrict access. Allowing a model blocked by the organization returns
forbiddenfor that login.
Request headers
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | API key |
Request parameters
| Parameter | Type | Description |
|---|---|---|
items* | object[] | Array of 1–25 items. Each item contains { login, models }. |
items[].login* | string | Employee login |
items[].models* | object[] | Array of 1 to 100 {model, permission} entries. |
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 access changes are applied for this login. |
error | string | An unexpected error occurred while processing this employee |
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", "models": [ { "model": "claude-5.5-haiku", "permission": "forbid" }, { "model": "gpt-6-luna", "permission": "allow" } ] }, { "login": "petrov", "models": [ { "model": "claude-5.5-haiku-typo", "permission": "default" } ] } ]}request = Request( "https://gptunnel.ru/api/v1/access/setModelAccess", 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/setModelAccess' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --header 'Content-Type: application/json' \ --data '{ "items": [ { "login": "ivanov", "models": [ { "model": "claude-5.5-haiku", "permission": "forbid" }, { "model": "gpt-6-luna", "permission": "allow" } ] }, { "login": "petrov", "models": [ { "model": "claude-5.5-haiku-typo", "permission": "default" } ] } ]}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error("Set GPTUNNEL_API_KEY")
const body = { "items": [ { "login": "ivanov", "models": [ { "model": "claude-5.5-haiku", "permission": "forbid" }, { "model": "gpt-6-luna", "permission": "allow" } ] }, { "login": "petrov", "models": [ { "model": "claude-5.5-haiku-typo", "permission": "default" } ] } ]}const response = await fetch("https://gptunnel.ru/api/v1/access/setModelAccess", { 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())The example includes an unknown model ID for petrov to demonstrate the error response.
Example response
Section titled “Example response”{ "code": 0, "updated": 1, "failed": 1, "failedLogins": [ { "login": "petrov", "reason": "model_not_found", "message": "Unknown model id(s) — see unknownModels. None of this login's models were applied. Use ids returned by GET /v1/models.", "unknownModels": ["claude-5.5-haiku-typo"] } ]}{ "code": 3, "message": "Invalid input, check schema issues.", "details": []}{ "error": { "message": "Unauthorized", "type": "unauthorized_request_error", "param": null, "code": null }}{ "code": 7, "message": "Not allowed to perform this action for the organization."}{ "code": 13, "message": "This section is not available from a personal account. Use a business organization API key."}{ "code": 1, "message": "Internal server error.", "trace_id": "66a346f64dcb57627c03d596"}