This guide will help you get started with the Panel API in the Pterodactyl PHP SDK.
- PHP 8.0 or higher
- Access to a Pterodactyl Panel installation
- Admin API key (for admin operations)
- Client API key (for client operations)
The Panel API is included in the main Pterodactyl PHP SDK package:
composer require mythicalsystems/pterodactyl-php-sdk<?php
require_once 'vendor/autoload.php';
use MythicalSystems\SDK\Pterodactyl\PterodactylSDK;
// Initialize full SDK with both Admin and Client APIs
$sdk = new PterodactylSDK(
'https://your-panel.com', // Panel URL
'ptlc_admin_xxxxxxxxxxxxx', // Admin API Key
'ptlc_client_xxxxxxxxxxxxx' // Client API Key
);<?php
use MythicalSystems\SDK\Pterodactyl\PterodactylSDK;
// Create Admin-only client
$admin = PterodactylSDK::adminOnly(
'https://your-panel.com',
'ptlc_admin_xxxxxxxxxxxxx'
);<?php
use MythicalSystems\SDK\Pterodactyl\PterodactylSDK;
// Create Client-only client
$client = PterodactylSDK::clientOnly(
'https://your-panel.com',
'ptlc_client_xxxxxxxxxxxxx'
);- Log into your Pterodactyl Panel as an administrator
- Navigate to Admin Panel → API Credentials
- Click Create New
- Fill in the required information:
- Description: A descriptive name for the key
- Allowed IPs: Leave empty for all IPs, or specify allowed IP addresses
- Click Create
- Copy the generated API key (it will only be shown once)
- Log into your Pterodactyl Panel as a user
- Navigate to Account Settings → API Credentials
- Click Create New
- Fill in the required information:
- Description: A descriptive name for the key
- Allowed IPs: Leave empty for all IPs, or specify allowed IPs
- Click Create
- Copy the generated API key (it will only be shown once)
<?php
try {
$servers = $sdk->admin()->servers()->listServers();
echo "✅ Admin API connection successful!";
echo "Found " . count($servers['data']) . " servers";
} catch (Exception $e) {
echo "❌ Admin API connection failed: " . $e->getMessage();
}<?php
try {
$account = $sdk->client()->getAccountDetails();
echo "✅ Client API connection successful!";
echo "Logged in as: " . $account['attributes']['email'];
} catch (Exception $e) {
echo "❌ Client API connection failed: " . $e->getMessage();
}<?php
try {
$servers = $sdk->admin()->servers()->listServers();
foreach ($servers['data'] as $server) {
echo "Server: " . $server['attributes']['name'] . "\n";
echo "Status: " . $server['attributes']['status'] . "\n";
echo "Owner: " . $server['attributes']['user'] . "\n";
echo "---\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}<?php
try {
$account = $sdk->client()->getAccountDetails();
echo "Email: " . $account['attributes']['email'] . "\n";
echo "Username: " . $account['attributes']['username'] . "\n";
echo "First Name: " . $account['attributes']['first_name'] . "\n";
echo "Last Name: " . $account['attributes']['last_name'] . "\n";
echo "Created: " . $account['attributes']['created_at'] . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}<?php
try {
$servers = $sdk->client()->servers()->listServers();
foreach ($servers['data'] as $server) {
echo "Server: " . $server['attributes']['name'] . "\n";
echo "Identifier: " . $server['attributes']['identifier'] . "\n";
echo "Status: " . $server['attributes']['status'] . "\n";
echo "---\n";
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}<?php
// Using environment variables
$sdk = new PterodactylSDK(
$_ENV['PTERODACTYL_PANEL_URL'],
$_ENV['PTERODACTYL_ADMIN_KEY'],
$_ENV['PTERODACTYL_CLIENT_KEY']
);<?php
// config.php
return [
'panel' => [
'url' => 'https://your-panel.com',
'admin_key' => 'ptlc_admin_xxxxxxxxxxxxx',
'client_key' => 'ptlc_client_xxxxxxxxxxxxx'
]
];
// Usage
$config = require 'config.php';
$sdk = new PterodactylSDK(
$config['panel']['url'],
$config['panel']['admin_key'],
$config['panel']['client_key']
);<?php
class PanelConfig {
private string $url;
private string $adminKey;
private string $clientKey;
public function __construct(string $url, string $adminKey, string $clientKey) {
$this->url = $url;
$this->adminKey = $adminKey;
$this->clientKey = $clientKey;
}
public function createSDK(): PterodactylSDK {
return new PterodactylSDK($this->url, $this->adminKey, $this->clientKey);
}
public function createAdminOnly(): PterodactylAdmin {
return PterodactylSDK::adminOnly($this->url, $this->adminKey);
}
public function createClientOnly(): PterodactylClient {
return PterodactylSDK::clientOnly($this->url, $this->clientKey);
}
}
// Usage
$config = new PanelConfig(
'https://your-panel.com',
'ptlc_admin_xxxxxxxxxxxxx',
'ptlc_client_xxxxxxxxxxxxx'
);
$sdk = $config->createSDK();<?php
use MythicalSystems\SDK\Pterodactyl\Exceptions\AuthenticationException;
use MythicalSystems\SDK\Pterodactyl\Exceptions\PermissionException;
use MythicalSystems\SDK\Pterodactyl\Exceptions\ResourceNotFoundException;
try {
$servers = $sdk->admin()->servers()->listServers();
} catch (AuthenticationException $e) {
echo "Authentication failed: " . $e->getMessage();
} catch (PermissionException $e) {
echo "Permission denied: " . $e->getMessage();
} catch (ResourceNotFoundException $e) {
echo "Resource not found: " . $e->getMessage();
} catch (Exception $e) {
echo "Unexpected error: " . $e->getMessage();
}<?php
// ❌ Don't hardcode API keys
$sdk = new PterodactylSDK('url', 'hardcoded-admin-key', 'hardcoded-client-key');
// ✅ Use environment variables
$sdk = new PterodactylSDK(
$_ENV['PTERODACTYL_PANEL_URL'],
$_ENV['PTERODACTYL_ADMIN_KEY'],
$_ENV['PTERODACTYL_CLIENT_KEY']
);<?php
// ✅ Always use HTTPS in production
$sdk = new PterodactylSDK(
'https://your-panel.com', // Use HTTPS
$adminKey,
$clientKey
);<?php
function validateApiKeys($sdk): array {
$result = [
'admin' => false,
'client' => false,
'errors' => []
];
try {
$sdk->admin()->servers()->listServers();
$result['admin'] = true;
} catch (Exception $e) {
$result['errors']['admin'] = $e->getMessage();
}
try {
$sdk->client()->getAccountDetails();
$result['client'] = true;
} catch (Exception $e) {
$result['errors']['client'] = $e->getMessage();
}
return $result;
}
// Usage
$validation = validateApiKeys($sdk);
if ($validation['admin'] && $validation['client']) {
echo "✅ Both API keys are valid";
} else {
echo "❌ API key validation failed";
foreach ($validation['errors'] as $api => $error) {
echo "$api API: $error\n";
}
}Now that you have the Panel API set up, explore:
- Authentication - Understanding Panel API authentication
- Admin API - Administrative operations
- Client API - User operations
- Error Handling - Comprehensive error management
- Examples - Real-world usage examples