PHP code example of humantone / humantone-php

1. Go to this page and download the library: Download humantone/humantone-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

humantone / humantone-php example snippets




umanTone\Client;

$client = new Client(apiKey: getenv('HUMANTONE_API_KEY'));

$result = $client->humanize(
    text: 'Your AI-generated draft goes here. At least 30 words for the API to accept it.',
);

echo $result->text;
echo "Credits used: {$result->creditsUsed}\n";

$client = new Client(); // reads HUMANTONE_API_KEY from env

$result = $client->humanize(
    text: '...',
    level: HumanizationLevel::Standard,
    customInstructions: 'Keep a formal corporate tone.',
);

$score = $client->detect(text: '...');
echo $score->aiScore;

$info = $client->account->get();
echo $info->plan->name;
echo $info->credits->total;
echo $info->plan->maxWords;
echo $info->subscription->active ? 'active' : 'inactive';
echo $info->subscription->expiresAt?->format('Y-m-d') ?? 'unknown';

$client = new Client(
    apiKey: 'ht_...',                             // or HUMANTONE_API_KEY env
    baseUrl: 'https://api.humantone.io',          // or HUMANTONE_BASE_URL env, default is api.humantone.io
    timeout: 120.0,                                // seconds
    maxRetries: 2,
    retryOnPost: false,                            // POST endpoints retry only when explicit
    userAgent: 'my-app/1.0',                       // appended to default UA after a single space
);

use HumanTone\Client;
use Symfony\Component\HttpClient\Psr18Client as SymfonyClient;

$client = new Client(
    apiKey: 'ht_...',
    httpClient: new SymfonyClient(),
);

use HumanTone\Client;
use HumanTone\Exceptions\HumanToneException;
use HumanTone\Exceptions\InsufficientCreditsException;
use HumanTone\Exceptions\DailyLimitExceededException;
use HumanTone\Exceptions\InvalidRequestException;
use HumanTone\Exceptions\AuthenticationException;
use HumanTone\Exceptions\RateLimitException;

$client = new Client();

try {
    $result = $client->humanize(text: '...');
} catch (InsufficientCreditsException) {
    echo "Buy more credits at https://app.humantone.io/settings/credits\n";
} catch (RateLimitException $e) {
    echo "Rate limited. Retry in {$e->getRetryAfterSeconds()}s.\n";
} catch (InvalidRequestException $e) {
    echo "Bad input: {$e->getMessage()}\n";
} catch (AuthenticationException) {
    echo "Check your API key.\n";
} catch (HumanToneException $e) {
    echo "HumanTone API error ({$e->getErrorCode()}): {$e->getMessage()}\n";
    if ($e->getRequestId()) {
        echo "Request ID: {$e->getRequestId()}\n";
    }
}
bash
composer