User-generated content is a powerful driver of engagement in modern applications. But where there are open text fields, there is always a risk of spam, offensive content, or unwanted advertising. Left unchecked, this can reduce user trust and harm your platform’s reputation.

The Kolas.ai Clean Talk API solves this challenge with machine learning. It classifies messages into categories such as Neutral, Spam, Insult, and more. For PHP developers, we provide an official client that makes integration seamless and fast.

This article will guide you step by step through connecting the PHP client, setting up authentication, sending classification requests, and processing results.

Creating a Clean Talk Project

Before starting with the integration, you need to create a new account and a new Clean Talk project in Kolas.ai.

If your PHP application should support asynchronous integration, you must add the application’s webhook in the project settings and obtain the secret for X-Signature.

Installation

Install the library using Composer (GitHub):

composer require kolasai/clean-talk-php-client

Once installed, the client is available via Composer’s autoloader.

Authentication

Kolas.ai uses OAuth2 Client Credentials Flow for secure access.

  1. Register at Kolas.ai.
  2. Create a new project in Clean Talk.
  3. Copy the client_id and client_secret from your project settings.

Then, request an access token:

use CleanTalk\KolasAiOAuthClient;

$oauthClient = new KolasAiOAuthClient();
$authResult = $oauthClient->auth(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET);

$accessToken = $authResult->getAccessToken();

⚠️ The token has a limited lifespan (expires_in). Be sure to refresh it before it expires.

Synchronous Classification

The simplest method is predict, which returns the classification result immediately.

    use CleanTalk\CleanTalkPredictionClient;
use CleanTalk\Message;
use CleanTalk\PredictRequest;

$client = new CleanTalkPredictionClient($authResult->getAccessToken());

$response = $client->predict(
new PredictRequest(
YOUR_PROJECT_ID,
[
new Message('11177c92-1266-1111-ace5-cda430481111', 'Hello world!'),
new Message('22277c92-1266-2222-ace5-cda430482222', 'Good buy world!'),
]
)
);

foreach ($response->getPredictions() as $prediction) {
echo "MessageId: {$prediction->getMessageId()}\n";
echo "Message: {$prediction->getMessage()}\n";
echo "Prediction: {$prediction->getPrediction()}\n";
echo "Probability: {$prediction->getProbability()}\n";
echo "Categories: " . implode(', ', $prediction->getCategories()) . "\n";

Example output:

    MessageId: 11177c92-1266-1111-ace5-cda430481111
Message: Hello world!
Prediction: Neutral
Probability: 0.9936153107882
Categories: Insult, Neutral, Spam

MessageId: 22277c92-1266-2222-ace5-cda430482222
Message: Good buy world!
Prediction: Neutral
Probability: 0.9952354613547
Categories: Insult, Neutral, Spam

Asynchronous Classification

For high-volume or high-performance applications, use the asynchronous method:

use CleanTalk\CleanTalkPredictionClient;
use CleanTalk\Message;
use CleanTalk\PredictRequest;

$client = new CleanTalkPredictionClient($accessToken);

$request = new PredictRequest(
YOUR_PROJECT_ID,
[
new Message('111', 'Hello world!'),
new Message('222', 'Buy our product now!'),
]
);

$client->asyncPredict($request);

In this case, results are not returned immediately. Instead, Kolas.ai sends the classification output to your service via a webhook (configurable in your project settings).

Language Support

Currently, the API supports:

  • English (en),
  • Russian (ru),
  • Ukrainian (uk).

Need another language? Contact info@kolas.ai — we can train and deploy models tailored to your project.

Conclusion

The Kolas.ai Clean Talk PHP client makes AI-powered moderation easy to integrate into any project:

  • installable via Composer,
  • secured with OAuth2,
  • supports synchronous and asynchronous workflows,
  • works across multiple languages.

You can try it today — sign up and create your first project for free.