API Documentation

Please use our our swagger documentation https://app.kolas.ai/api/documentation. For testing API use credentials (client ID and client secret) generated in your account settings https://app.kolas.ai/pages/account-setting

For generating your API clients you can use our

Here’s a step-by-step guide to using the Kolas.Ai API:

Step 1: Register and Obtain an OAuth2 Token

To use the API, you need to authenticate via OAuth2 and obtain an access token.

  1. Register for an account.

  2. Obtain the Client ID and Client Secret for your application.

  3. Use these credentials to request a token by sending a POST request to the token endpoint:

    Request:

    POST /oauth/token 
    Content-Type: application/x-www-form-urlencoded

    Request Body:

    grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
  4. In the response, you’ll receive an access_token that you’ll use to authenticate API requests.

Step 2: Make a Prediction for Messages

Once you have your access token, you can make a request to predict the category of your messages.

  1. Send a POST request to the /predictions/predict endpoint:

    Request:

    POST /predictions/predict 
    Authorization: Bearer YOUR_ACCESS_TOKEN
    Content-Type: application/json
  2. Request Body should include two required parameters:

    projectId: The ID of the project configured for predictions.messages: An array of messages for which you want to make a prediction.Example request body:

    {
    "projectId": 3457,
    "messages": [
    {
    "message": "What did you do yesterday?"
    },
    {
    "message": "Hello world!"
    }
    ]
    }
    NameTypeDescription
    projectIdintegerID of project
    messagesarraylist of messages for classification
    messages.messagestringmessage for classification
  3. Response will include the prediction for each message:

    {
    "predictions": [
    {
    "categories": [
    "Neutral",
    "Insult",
    "Spam"
    ],
    "prediction": "Neutral",
    "probability": "0.99808084964752",
    "message": "What did you do yesterday?"
    },
    {
    "categories": [
    "Neutral",
    "Insult",
    "Spam"
    ],
    "prediction": "Neutral",
    "probability": "0.8446232676506",
    "message": "Hello world!"
    }
    ]
    }
    NameTypeDescription
    predictionsarraylist of predictions
    predictions.categoriesarraylist of supported categories
    predictions.predictionstringpredicted category
    predictions.probabilitystringprobability of prdiction (max value 1)
    predictions.messagestringprocessed message

Step 3: Handle Errors

If your request fails, you’ll receive an error. The API provides several error codes:

401 Unauthorized: If the access token is missing or invalid. Example response:

{ 
"message": "Unauthenticated."
}

422 Validation Error: If there’s a validation issue with the request (e.g., missing required fields). Example response:j

{
"errors": ["Missing projectId field."],
"message": "Validation exception"
}

5XX Server Error: If an unexpected error occurs on the server. Example response:

{
"message": "Internal server error. Contact technical support."
}

Notes:

  • Ensure that the projectId exists and is properly configured in the Kolas.Ai system.
  • Before using the API in a production environment, it’s recommended to test requests using tools like Postman or cURL.

If you encounter any questions or issues, feel free to ask!

Error codes

  • PROJECT_NOT_FOUND – There is no project with the ID passed in the request. Check your project ID.
  • PROJECT_DATASET_NOT_CONFIGURED – No datasets are enabled in the project. Check your project settings.
  • PROJECT_NOT_ACTIVE – The project is disabled. Enable the project or pass another project ID.
  • ACCOUNT_BALANCE_EMPTY – You have used all your credits. Top up your account balance.