PHP code example of reliant / reliant-php

1. Go to this page and download the library: Download reliant/reliant-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/ */

    

reliant / reliant-php example snippets




eliant\Reliant;

$client = new Reliant([
    'api_key'  => 'rel_...',   // Dashboard → Configurações
    'user_id'  => 'seu-user-id', // Dashboard → Configurações
    'base_url' => 'https://reliant-production.up.railway.app',
]);

// Executar com validação garantida
$result = $client->execute([
    'prompt'    => 'Extraia os dados: João Silva, [email protected]',
    'schema_id' => 'id-do-seu-schema',
    'provider'  => 'anthropic',
    'model'     => 'claude-sonnet-4-20250514',
]);

echo $result['output']['name'];  // João Silva
echo $result['output']['email']; // [email protected]
echo $result['metadata']['attempts']; // 1

$result = $client->execute([
    'prompt'    => 'seu prompt',
    'schema_id' => 'sch_...',
    'provider'  => 'anthropic', // anthropic | openai | gemini | groq | mistral
    'model'     => 'claude-sonnet-4-20250514',
    'options'   => ['max_retries' => 3],
]);

// $result['success']  → bool
// $result['output']   → array com o output validado
// $result['status']   → 'success' | 'fallback' | 'failed'
// $result['metadata'] → execution_id, attempts, latency_ms, tokens_used

$schemas = $client->listSchemas();
foreach ($schemas['schemas'] as $schema) {
    echo $schema['name'] . ' — ' . $schema['id'];
}

$schema = $client->createSchema([
    'name'       => 'Extração de Contato',
    'slug'       => 'contact-extraction',
    'definition' => [
        'type'       => 'object',
        'null],
]);

$executions = $client->listExecutions([
    'limit'  => 20,
    'status' => 'failed',
]);

$metrics = $client->getMetrics(30);
echo $metrics['success_rate']; // 98.5
echo $metrics['total_executions']; // 1420
echo $metrics['estimated_cost_usd']; // 0.0842

$bySchema   = $client->getMetricsBySchema(30);
$byProvider = $client->getMetricsByProvider(30);

use Reliant\ReliantException;

try {
    $result = $client->execute([...]);
} catch (ReliantException $e) {
    echo 'Erro ' . $e->getCode() . ': ' . $e->getMessage();
}
bash
composer