# Create an assistant

Source: [Create an assistant](<https://docs.gptunnel.ru/en/api/assistants/create/>)

<a id="_top"></a>
Authenticate requests with your [API key](<https://docs.gptunnel.ru/en/#get-an-api-key>).

<a id="request"></a>
## Request

`POST https://gptunnel.ru/v1/assistant/create`

Creates an assistant owned by the user whose API key you supply. The same settings are available in the web interface.

Only `title` and `modelId` are required. Other fields have defaults.

### Request headers

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

### Request body

| Parameter | Type | Description |
| --- | --- | --- |
| `title` (required) | `string` | Display name, up to 16 characters. |
| `modelId` (required) | `string` | Text model ID from /v1/models. The API key must have access to the model. |
| `mention` | `string` | Assistant code used in its page URL and as assistantCode in chat. Use 3–16 letters, digits, hyphens, or underscores. The API generates a code if you omit this field. |
| `subtitle` | `string` | Subheading, up to 32 characters |
| `description` | `string` | Catalog description, up to 4096 characters. |
| `picture` | `string` | Avatar URL, up to 255 characters. |
| `instruction` | `string` | System instruction (prompt) |
| `temperature` | `number` | Generation temperature from 0 to 1. Defaults to 0.5. |
| `sqlStore` | `boolean` | Give the assistant its own empty SQLite database. This experimental feature requires a model that supports function calling. Defaults to false. |
| `access` | `object` | Privacy and catalog settings. See the access table below. |
| `database` | `object \| null` | RAG knowledge base settings. See the database table below. |
| `mcp` | `Array<object>` | MCP server settings. Supply at most one entry. |
| `apiFunctions` | `Array<object>` | External API functions. Supply at most 25 entries. |

### access

| Parameter | Type | Description |
| --- | --- | --- |
| `access.isPrivate` | `boolean` | Set to true to hide the assistant from the catalog. Defaults to false. |
| `access.isFree` | `boolean` | Whether installation is free. Paid installation is not supported. The only allowed value is true, which is the default. |
| `access.installPrice` | `number` | Installation price in rubles. The only supported value is 0, the default. |
| `access.hideSettings` | `boolean` | Set to true to hide the settings and system instructions from other users. Defaults to false. |
| `access.orgTeamId` | `string \| null` | Team ID within access.orgId. You must have permission to add the assistant to that team. |
| `access.orgId` | `string \| null` | Organization ID for an organization assistant. Only the organization associated with the API key is accepted. Personal keys ignore this field. Defaults to null for a personal assistant. |

### database

| Parameter | Type | Description |
| --- | --- | --- |
| `database.id` (required) | `string` | Knowledge base ID from /v1/database/list. The knowledge base must belong to the key owner |
| `database.requestFrequency` | `string` | When to query the database: everytime for every request, auto when the model decides, or first for the first message only. |
| `database.chunks` | `number` | Number of retrieved chunks to include in the model context. |

### mcp\[\]

| Parameter | Type | Description |
| --- | --- | --- |
| `mcp[].server` (required) | `string` | MCP server URL, up to 1024 characters. |
| `mcp[].clientId` | `string \| null` | OAuth client id |
| `mcp[].clientSecret` | `string \| null` | OAuth client secret |
| `mcp[].accessToken` | `string \| null` | Access token to use if authorization is already complete. |
| `mcp[].scope` | `string \| null` | OAuth scope |
| `mcp[].toolDisabled` | `string \| null` | Comma-separated names of MCP server tools to disable. |

### apiFunctions\[\]

| Parameter | Type | Description |
| --- | --- | --- |
| `apiFunctions[].name` (required) | `string` | Function name shown to the model. Use up to 64 Latin letters, digits, underscores (\_), or hyphens (-). Each name must be unique within the assistant. |
| `apiFunctions[].type` (required) | `string` | HTTP method: get or post |
| `apiFunctions[].endpoint` (required) | `string` | Absolute http(s) URL of the public endpoint to call. Use {param} placeholders in the path or query only. The host must be fixed. |
| `apiFunctions[].description` | `string` | Instructions telling the model when to call the function. |
| `apiFunctions[].headers` | `Array<object>` | Request headers as { key, value } pairs. |
| `apiFunctions[].parameters` | `Array<object>` | Parameter definitions: { name, type, description, required, value }. Supported type values: string, number, boolean. |

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

This example creates a private assistant. Save the returned `id` to [update](<https://docs.gptunnel.ru/en/api/assistants/update/>) or [delete](<https://docs.gptunnel.ru/en/api/assistants/delete/>) the assistant. Use its `mention` to [start a chat](<https://docs.gptunnel.ru/en/api/assistants/chat/>).

Store the API key in the `GPTUNNEL_API_KEY` environment variable.

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

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

body = {
  "title": "Помощник",
  "modelId": "gpt-6-luna",
  "instruction": "Отвечай кратко.",
  "access": {
    "isPrivate": True
  }
}
request = Request(
    'https://gptunnel.ru/v1/assistant/create',
    headers={
        'Authorization': os.environ['GPTUNNEL_API_KEY'],
        'Content-Type': 'application/json',
    },
    data=json.dumps(body).encode('utf-8'),
)
with urlopen(request, timeout=60) as response:
    print(json.load(response))
```

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

```bash
curl --request POST \
  --url 'https://gptunnel.ru/v1/assistant/create' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "Помощник",
  "modelId": "gpt-6-luna",
  "instruction": "Отвечай кратко.",
  "access": {
    "isPrivate": true
  }
}'
```

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

```javascript
const response = await fetch('https://gptunnel.ru/v1/assistant/create', {
  method: 'POST',
  headers: {
    Authorization: process.env.GPTUNNEL_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "title": "Помощник",
    "modelId": "gpt-6-luna",
    "instruction": "Отвечай кратко.",
    "access": {
      "isPrivate": true
    }
  }),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

<a id="minimum-request"></a>
### Minimum request

A request containing only `title` and `modelId` creates a public assistant. Set `access.isPrivate: true` to keep it out of the catalog. If you omit `mention`, the API generates the assistant code and returns it in the response.

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

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

The following excerpt shows an example assistant ID and code.

The response omits the MCP credentials `clientSecret` and `accessToken`.

```json
{
  "object": "assistant",
  "id": "68c9b2d1e4b0a2d3c4f5e6b8",
  "mention": "example-assistant",
  "title": "Помощник",
  "modelId": "gpt-6-luna",
  "access": {
    "isPrivate": true,
    "orgId": null,
    "orgTeamId": null
  }
}
```

<a id="tab-panel-1-1"></a>
**400 Bad Request**

```json
{
  "error": {
    "message": "title: String must contain at most 16 character(s)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}
```

<a id="tab-panel-1-2"></a>
**409 Conflict**

```json
{
  "error": {
    "message": "Mention 'tax-helper' is already taken",
    "type": "invalid_request_error",
    "param": null,
    "code": "mention_taken"
  }
}
```

<a id="tab-panel-1-3"></a>
**404 Not Found**

```json
{
  "error": {
    "message": "Model 'example-missing-model' not found or is not a text model",
    "type": "invalid_model_error",
    "param": null,
    "code": "model_not_found"
  }
}
```

> **Tip: Start a conversation**
>
> Pass the returned `mention` as `assistantCode` to [chat with the assistant](<https://docs.gptunnel.ru/en/api/assistants/chat/>).
