LogoLogo
Why Unitary?
  • Get started
    • 👋Step-by-step instructions
  • API References
    • ℹ️Features and requirements
    • ▶️API Authentication
    • ☑️Standard & Premium: Policy Classification endpoints
      • 🔃Add-on: synchronous endpoints
    • 🛂Virtual Moderator endpoint
    • #️⃣Items and Characteristics endpoints
      • *️⃣List of Item and Characteristics
    • ⏺️Detoxify endpoints
    • ↔️How to select thresholds
    • ↪️Integrating Webhooks
Powered by GitBook
On this page

Was this helpful?

  1. API References

API Authentication

PreviousFeatures and requirementsNextStandard & Premium: Policy Classification endpoints

Last updated 1 year ago

Was this helpful?

The first step to integrate with Unitary's API is setting up authentication. Unitary's API provides an authentication endpoint which uses your API key to generate a Bearer token that must be included in any subsequent API requests you wish to make.

The endpoint reference below gives more detail about how to use the authentication endpoint, how to use the returned Bearer token, and the expiration of tokens.

This API Authentication guide assumes you have your API key already set up. If this is not the case, please email at .

Endpoint reference

Example code

curl --location --request POST 'https://api.unitary.ai/v1/authenticate'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'key={API_KEY}' 
import requests
url = "https://api.unitary.ai/v1/authenticate"
API_KEY = "<api_key>"

payload = f"key={API_KEY}"
headers = { 'Content-Type': 'application/x-www-form-urlencoded' }
response = requests.request("POST", url, headers=headers, data=payload)

token = response.text["api_token"]
expiry = response.text["expiry"]

print(token, expiry)
const fetch = require('node-fetch'); // Make sure you have 'node-fetch' installed for this to work
const url = "https://api.unitary.ai/v1/authenticate";
const API_KEY = "<api_key>";
const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
const body = `key=${API_KEY}`;

fetch(url, { method: 'POST', headers: headers, body: body })
  .then(response => response.json())
  .then(json => {
    const token = json.api_token;
    const expiry = json.expiry;
    console.log(token, expiry);
  })
  .catch(error => console.error('error:', error));

▶️
support@unitary.ai
  • Endpoint reference
  • POSTAuthenticate with API Key to obtain an API token
  • Example code

Authenticate with API Key to obtain an API token

post

Clients wishing to interact with the Unitary API must first authenticate by calling this endpoint with a valid API Key in the request body.

The resulting api_token should be used in subsequent API requests by including a header with the format:

Authorization: Bearer {api_token}

The api_token will be valid for a period of time (default 24 hours) and should be used for all subsequent API requests until it expires, or is invalidated.

This endpoint is rate-limited and may return error codes if too many authentication requests are submitted within a short time frame. For this reason clients should avoid re-authenticating too often.

Body
keystring · passwordWrite-onlyRequired
Responses
200
Successful Response
application/json
422
Validation Error
application/json
post
POST /authenticate HTTP/1.1
Host: 
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 18

"key='password'"
{
  "api_token": "text",
  "expiry": "2025-05-15T13:20:33.063Z"
}