Skip to main content

API authentication

Every DialerAI API request is authenticated with a bearer token. Tokens are issued by the Token API in exchange for the username and password of a user in your organization, and they carry that user's organization and role.

This is the first page to read before API overview, the Contacts API, the CDR API, or the Flows API.

There is no "generate API key" screen

DialerAI has no page in the UI that issues a token, and no API-key feature. Tokens exist only as the result of the Token API exchange below. What you create in the UI is the user whose credentials are exchanged, so if you are looking for a key to copy, you are looking for something that does not exist.

If the API returns 404 on every path, API features may be disabled on your deployment. Ask your administrator.

The three endpoints​

The Token API lives below /api_router/v1/token and provides three operations:

EndpointPurpose
POST /token/pairExchange a username and password for an access token and a refresh token.
POST /token/refreshExchange a valid refresh token for a new access token.
POST /token/verifyCheck whether a token is still valid.

Create a user for the integration​

Do not use a person's own sign-in for a running integration. When that person changes their password or leaves, the integration stops.

  1. Open Settings → Organization & Users. Only an Owner can create users.

  2. Select Create a New User and give it a recognizable name, such as svc-warehouse-sync.

  3. Set a long, randomly generated password.

  4. Choose the smallest role that lets the integration do its work:

    RoleCan do
    OwnerEverything, including managing users and organization settings.
    EditorCreate and edit flows, campaigns, contacts, and other resources.
    ViewerRead-only access.
    ReporterReports and dashboards only.

    A read-only export job should use Reporter or Viewer. Only a job that creates contacts, flows, or campaigns needs Editor.

  5. Store the password in your secret manager, not in the integration's source code.

Organization scope

A token is scoped to the organization of the user that requested it. It cannot read or write another organization's contacts, campaigns, or call records. To integrate with several organizations, create one user per organization and hold one token for each.

Obtain a token​

POST /token/pair takes a username and password and returns an access token, a refresh token, and the username.

import requests

HOST = "https://your-dialerai-host"

response = requests.post(
f"{HOST}/api_router/v1/token/token/pair",
json={"username": "svc-warehouse-sync", "password": "..."},
timeout=30,
)
response.raise_for_status()
tokens = response.json()

access_token = tokens["access"]
refresh_token = tokens["refresh"]

The response looks like this:

{
"username": "svc-warehouse-sync",
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

The token endpoint accepts 20 requests a minute from one IP address; past that it returns 429, so wait a minute before trying again. A user whose organization is deactivated or archived is refused with 401, and the tokens already issued to it stop working at once.

Bad credentials return 401 with a body naming the reason:

{
"detail": "No active account found with the given credentials",
"code": "authentication_failed"
}

Note the doubled token in the path: the Token API is mounted at /api_router/v1/token/ and its own routes sit below token/. A request to /api_router/v1/token/pair returns 404, not 401, so a 404 here means the path is wrong rather than the credentials.

Use the token​

Send the access token in the Authorization header as a bearer token. This is the BASE_URL and HEADERS setup that the other API pages assume:

BASE_URL = f"{HOST}/api_router/v1/core"
HEADERS = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
}

response = requests.get(f"{BASE_URL}/contact-list/list", headers=HEADERS)
response.raise_for_status()

An expired or invalid token returns 401. Treat a 401 as "refresh and retry once", and a 403 as "this user's role does not allow this call"; retrying a 403 will never succeed.

Token lifetime and refresh​

TokenLifetimeUse
Access24 hoursSent on every API request.
Refresh7 daysExchanged for a new access token.

Refresh tokens are not rotated: POST /token/refresh returns a new access token and the same refresh token remains valid until it expires. A long-running integration therefore needs to sign in again with the username and password at least once every 7 days.

def refresh_access_token(refresh_token):
response = requests.post(
f"{HOST}/api_router/v1/token/token/refresh",
json={"refresh": refresh_token},
timeout=30,
)
if response.status_code == 401:
return None # refresh token expired, sign in again with /token/pair
response.raise_for_status()
return response.json()["access"]

A practical pattern is to refresh on demand rather than on a timer: make the call, and if it returns 401, refresh once and retry. If the refresh also fails, fall back to /token/pair.

Use POST /token/verify with {"token": "..."} when you want to check a token without making a business request. It returns 200 for a valid token and 401 for an invalid or expired one.

Rotate a token​

There is no "revoke this token" button: tokens are self-contained and stay valid until they expire. Rotation is therefore done by changing the integration user's password.

  1. Set a new password for the integration user under Settings → Organization & Users.
  2. Update the password in your secret manager.
  3. Call /token/pair with the new password and deploy the new tokens.

Tokens issued before the change keep working until they expire, so plan rotation ahead of a deadline rather than treating it as instant.

If a token is exposed​

A leaked access token grants that user's access to your organization for up to 24 hours, and a leaked refresh token for up to 7 days.

  1. Change the integration user's password immediately. This stops new tokens being issued with the old credentials.
  2. If the exposure is serious, delete the integration user under Settings → Organization & Users. Deleting the user invalidates its tokens outright, which is the only way to cut off an already-issued token before it expires.
  3. Create a replacement user, issue fresh tokens, and redeploy.
  4. Review call reports, message reports, and your contact lists for activity you do not recognize during the exposure window.
Keep tokens server-side

Tokens belong in a server-side integration or a secret manager. Never commit one to source control, never place one in browser JavaScript or a mobile app, and never paste one into a support ticket. Anyone holding the token has the integration user's access to your organization.