Docs / SDKs / PHP
🐘

PHP SDK

Stable

The official TrueEntropy PHP client. PSR-18 compatible with Laravel service provider included, retry middleware, and full access to QuBitLang metadata.

Installation

Terminal
composer require trueentropy/sdk

Requires PHP 8.1+. Works with any PSR-18 HTTP client (Guzzle included by default).

Quick Start

quickstart.php
use TrueEntropy\Client; $client = new Client('te_live_YOUR_KEY'); // Generate quantum random integers $result = $client->integers(['count' => 10, 'min' => 1, 'max' => 100]); print_r($result->values); // [42, 87, 13, 65, 91, 28, 74, 3, 56, 49] // Access QuBitLang provenance metadata echo $result->metadata->qubitlang_circuit; // qrng_hadamard_v2.3 echo $result->metadata->quantum_backend; // ibm_fez echo $result->metadata->nist_verified; // true

Laravel Integration

config/services.php
// Add to config/services.php 'trueentropy' => [ 'key' => env('TRUEENTROPY_API_KEY'), 'sandbox' => env('TRUEENTROPY_SANDBOX', false), ],
app/Http/Controllers/RandomController.php
use TrueEntropy\Client; class RandomController extends Controller { public function generate(Client $entropy) { $result = $entropy->integers([ 'count' => 5, 'min' => 1, 'max' => 100, ]); return response()->json($result->values); } }

Configuration

config.php
use TrueEntropy\Client; $client = new Client('te_live_YOUR_KEY', [ 'base_url' => 'https://api.trueentropy.net', // default 'timeout' => 30, // seconds 'max_retries' => 3, // automatic retries 'sandbox' => false, // set true for sandbox ]);

Endpoint Methods

Integers

$result = $client->integers(['count' => 5, 'min' => 1, 'max' => 1000]); print_r($result->values); // [472, 829, 134, 567, 291]

Floats

$result = $client->floats(['count' => 5, 'precision' => 10]); print_r($result->values); // [0.4721937482, 0.8291053847, ...]

Bytes

$result = $client->bytes(['count' => 32, 'encoding' => 'hex']); echo $result->bytes; // "a7f2b9c4d8e1..."

UUID

$result = $client->uuid(['count' => 3]); foreach ($result->uuids as $uid) { echo $uid . "\n"; }

Bitstring

$result = $client->bitstring(['length' => 256]); echo $result->bits; // "10110100111010010110..."

Shuffle

$result = $client->shuffle(['items' => '1,2,3,4,5,6,7,8,9,10']); print_r($result->shuffled); // [7, 3, 9, 1, 5, 10, 2, 8, 4, 6]

Batch

$result = $client->batch([ 'type' => 'integers', 'count' => 100000, 'params' => ['min' => 1, 'max' => 1000000], ]); echo count($result->values); // 100000

Certificate

$cert = $client->certificate(['id' => 'cert_a7f2b9c4d8e1']); echo $cert->provenance->qubitlang_circuit; // qrng_hadamard_v2.3 echo $cert->verify_url;

Error Handling

errors.php
use TrueEntropy\Client; use TrueEntropy\Exceptions\AuthenticationException; use TrueEntropy\Exceptions\RateLimitException; use TrueEntropy\Exceptions\ValidationException; use TrueEntropy\Exceptions\TrueEntropyException; try { $result = $client->integers(['count' => 10]); } catch (AuthenticationException $e) { echo "Invalid API key: " . $e->getMessage(); } catch (RateLimitException $e) { echo "Rate limited. Retry after: " . $e->getRetryAfter(); } catch (ValidationException $e) { echo "Invalid params: " . $e->getCode(); } catch (TrueEntropyException $e) { echo "API error: " . $e->getStatusCode() . " - " . $e->getMessage(); }

Features

FeatureDetails
PHP 8.1+Uses enums, readonly properties, and named arguments
PSR-18Works with any PSR-18 HTTP client (Guzzle, Symfony, etc.)
LaravelService provider included - inject Client via DI container
RetriesMiddleware-based exponential backoff with configurable retries
SandboxSet 'sandbox' => true for testing without consuming quota
CertificatesBuilt-in $client->certificate() for provenance retrieval
QuBitLang metadataObject access to circuit, version, backend info on every response