Skip to main content

Programmatic Auth

We use API keys for server-to-server interaction with AI DIAL 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 settings, you can get familiar with the description of the configuration parameters. Refer to configuration file to view the full example.

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

API keys must be associated with roles. Such roles are used to manage access to system resources and restrict the number of requests that can be sent to them.

Refer to Roles to learn more how to use roles.

Roles used by API keys must be declared in the roles section.

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.

Optionally, we can configure limits for this role, or leave them empty to apply an unlimited access. In this example, we grant an unlimited access for the default role to the chat-gpt-35-turbo model. You can refer to Roles & Access Control to learn how to define access limits for API keys.

Note, that it is mandatory to define at least one role and assign it for an API key, but you can leave limits empty (as shown in the previous example) to apply the default value - unlimited.

Refer to configuration file to view the full example.

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