PHP code example of vaultic / sdk

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

    

vaultic / sdk example snippets




aultic\VaulticClient;

// Initialize the client with your API key
$client = new VaulticClient('vt_your_api_key_here');

// Get a prompt with variables
$prompt = $client->prompts->get('0sZNC8EC9D', [
    'variables' => [
        'user_name' => 'John',
        'issue' => 'Password reset'
    ]
]);

echo $prompt['system_content'];
echo $prompt['user_content'];

$client = new VaulticClient('vt_your_api_key_here', [
    'baseUrl' => 'https://app.vaultic.io/api/v1',   // Custom API URL
    'timeout' => 30,                                // Request timeout in seconds
    'enableLogging' => false,                       // Enable request/response logging
    'userAgent' => 'MyApp/1.0.0',                   // Custom User-Agent
]);

// Get a prompt by ID
$prompt = $client->prompts->get('prompt_id_here');

// Get a prompt with variables replaced
$prompt = $client->prompts->get('prompt_id_here', [
    'variables' => [
        'name' => 'John Doe',
        'email' => '[email protected]'
    ]
]);

$prompt = $client->prompts->getVersion('prompt_id_here', '1.0.0', [
    'variables' => ['name' => 'John']
]);

$prompts = $client->prompts->getProjectPrompts('project_id_here', [
    'page' => 1,
    'per_page' => 20,
    'variables' => [
        'name' => 'John',
        'email' => '[email protected]'
    ]
]);

$project = $client->projects->get('project_id_here');

$projects = $client->projects->list([
    'page' => 1,
    'per_page' => 20
]);

use Vaultic\Helpers\VariableReplacer;

$prompt = [
    'system_content' => 'Hello {{name}}',
    'user_content' => 'Email: {{email}}'
];

$result = VariableReplacer::replace($prompt, [
    'name' => 'John',
    'email' => '[email protected]'
]);

use Vaultic\Helpers\VariableExtractor;

$variables = VariableExtractor::extract($prompt);
// Returns: ['name', 'email']

use Vaultic\Helpers\VariableValidator;

$result = VariableValidator::validate($prompt, [
    'name' => 'John',
    'email' => '[email protected]'
]);

if ($result['valid']) {
    echo "All variables provided";
} else {
    echo "Missing: " . implode(', ', $result['missing']);
}

use Vaultic\Exceptions\UnauthorizedException;
use Vaultic\Exceptions\NotFoundException;
use Vaultic\Exceptions\RateLimitException;
use Vaultic\Exceptions\VaulticException;

try {
    $prompt = $client->prompts->get('invalid_id');
} catch (UnauthorizedException $e) {
    echo "Invalid API key";
} catch (NotFoundException $e) {
    echo "Prompt not found";
} catch (RateLimitException $e) {
    echo "Rate limit exceeded. Retry after: " . $e->getRetryAfter() . " seconds";
} catch (VaulticException $e) {
    echo "Error: " . $e->getMessage();
    echo "Status Code: " . $e->getStatusCode();
}
bash
composer analyse