# Create an employee account

Source: [Create an employee account](<https://docs.gptunnel.ru/en/employees/create/>)

<a id="_top"></a>
> **Note: Organization API key**
>
> Use an API key for your organization with the Full dashboard access permission. The key must have been created by an owner or administrator. [Get an API key](<https://docs.gptunnel.ru/en/>).

<a id="create-an-employee"></a>
## Create an employee

`POST https://gptunnel.ru/api/v1/employees/createEmployee`

Creates an account with the member role in the organization associated with the API key. If you supply an `email`, the employee receives their sign-in details there.

If the login already belongs to a registered user outside your organization, the service sends them an invitation. The password, name, and phone number in the request do not change the existing account. Until the user accepts, only their login is visible in the [employee list](<https://docs.gptunnel.ru/en/employees/list/>). The response has the same structure as for a new account, but the returned `userId` does not identify the invited account.

If another organization created the account, the service returns the same response without sending an invitation. The account will not appear in your employee list.

> **Caution: Rate limits for creating individual accounts**
>
> `createEmployee` allows up to 10 requests per API key in 10 minutes and up to 20 requests per organization in an hour. Exceeding either limit returns HTTP `429` with code `43`. [Bulk import](<https://docs.gptunnel.ru/en/employees/import/>) has a separate quota.

### Request headers

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

### Request parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `login` (required) | `string` | Employee login (any string from 1 to 255 characters) |
| `password` (required) | `string` | Password (at least 5 characters) |
| `email` | `string` | Email address, unique within the organization |
| `firstName` | `string` | First name |
| `lastName` | `string` | Last name |
| `phone` | `string` | Phone number (any string) |
| `avatar` | `string` | Avatar |

<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 = {
  "login": "ivanov@example.com",
  "password": "secret123",
  "email": "ivanov@example.com",
  "firstName": "Иван",
  "lastName": "Иванов"
}
request = Request(
    "https://gptunnel.ru/api/v1/employees/createEmployee",
    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/employees/createEmployee' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "login": "ivanov@example.com",
  "password": "secret123",
  "email": "ivanov@example.com",
  "firstName": "Иван",
  "lastName": "Иванов"
}'
```

<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 = {
  "login": "ivanov@example.com",
  "password": "secret123",
  "email": "ivanov@example.com",
  "firstName": "Иван",
  "lastName": "Иванов"
}
const response = await fetch("https://gptunnel.ru/api/v1/employees/createEmployee", {
  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,
  "userId": "66a346f64dcb57627c03d596"
}
```

<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>
**409 Login in organization**

```json
{
  "code": 8,
  "message": "Employee with this login is already in the organization."
}
```

<a id="tab-panel-1-6"></a>
**409 Email in organization**

```json
{
  "code": 9,
  "message": "Employee with this email is already in the organization."
}
```

<a id="tab-panel-1-7"></a>
**429 Too many requests**

```json
{
  "code": 43,
  "message": "Too many employee creation requests, retry later."
}
```

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

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