Skip to main content

Programmatic Auth

Introduction

We use API keys for server-to-server interaction with DIAL Core API. To use an API key, it is necessary to create one.

Step 1: Define API Keys

In the keys section in the aidial.config.json configuration file, you can add API keys. An API Key should be a secure random key of at least 128 bit size.

In dynamic settings, you can get familiar with the description of the configuration parameters.

In the following example, "myApiKey" API key is created for a project "MyProject" with the "default" role:

//Example extract from aidial.config.json
"keys": {
"myApiKey": {
"project": "MyProject",
"role": "default"
}
}

Important: API keys must be associated with a project and role; otherwise a key is invalid.

Step 2: Assign Roles (Required)

To be valid, an API key must be associated with at least one role. Such roles are used to manage access to system resources, impose limits on token usage and sharing.

Refer to About Roles to learn more.

Roles used by API keys must be declared in the roles section in the DIAL Core dynamic settings.

In the previous example, we assigned the default role for myApiKey API key. On this step, we need to declare the default role in the roles section to make a valid configuration.

//Example extract from aidial.config.json
"keys": {
"myApiKey": {
"project": "MyProject",
"role": "default"
}
},
"roles": {
"default": {}
}

Step 3: Configure Limits (Optional)

You can define limits for roles in the roles section of the DIAL Core dynamic settings. This allows you to control access to system resources, impose restrictions on token usage or sharing of a specific resource.

Important: if limits are not defined, the access is unlimited.

In this example, we grant an unlimited access for the default role to the chat-gpt-35-turbo model.

//Example extract from aidial.config.json
"keys": {
"myApiKey": {
"project": "MyProject",
"role": "default"
}
},
"roles": {
"default": { //role name
"limits": {
"chat-gpt-35-turbo": //system resource
{}
}
}
}