Connect Your AgentPHP SDK

PHP SDK

Official SDK for PHP 7.4+.

The Composer package is coming soon. For now, use the REST API directly with cURL — see the cURL / REST docs.

Install (coming soon)

composer require aigodfather/aigodfather-php

Requirements

  • PHP >= 7.4
  • ext-curl
  • ext-json

Initialize

Pass configuration as an associative array. Same options as Node.js SDK: apiKey, debug, timeout, maxRetries, defaultTags, defaultMetadata, onBlock, onApprovalRequired.

Methods

Same API surface as the Node.js and Python SDKs. All methods return associative arrays.

MethodDescription
$ai->info(msg, meta)Info-level event
$ai->warning(msg, meta)Warning event
$ai->error(msg, meta)Error event
$ai->critical(msg, meta)Critical event
$ai->action(name, opts)Action (rule engine)
$ai->waitForApproval(id)Poll until resolved
$ai->ping()Test connection
php
<?php
require_once class="tk-str">'vendor/autoload.php';

use AIGodfather\AIGodfather;
use AIGodfather\BlockedError;

$ai = new AIGodfather([
    class="tk-str">'apiKey' => getenv(class="tk-str">'AIGODFATHER_API_KEY'),
    class="tk-str">'debug' => true,
]);

class=class="tk-str">"tk-cmt">// Track events
$ai->info(class="tk-str">'Server started', [class="tk-str">'version' => class="tk-str">'1.0.0']);
$ai->error(class="tk-str">'Payment failed', [class="tk-str">'orderId' => class="tk-str">'ord_123']);

class=class="tk-str">"tk-cmt">// Action with approval
$result = $ai->action(class="tk-str">'large_payment', [
    class="tk-str">'resource' => class="tk-str">'stripe',
    class="tk-str">'severity' => class="tk-str">'high',
    class="tk-str">'amount' => 5000,
    class="tk-str">'currency' => class="tk-str">'USD',
    class="tk-str">'requiresApproval' => true,
]);

if ($result[class="tk-str">'status'] === class="tk-str">'pending_approval') {
    $decision = $ai->waitForApproval(
        $result[class="tk-str">'approval_id']
    );
    echo class="tk-str">"Decision: " . $decision[class="tk-str">'status'];
}

class=class="tk-str">"tk-cmt">// Error handling
try {
    $ai->action(class="tk-str">'delete_all', [class="tk-str">'severity' => class="tk-str">'critical']);
} catch (BlockedError $e) {
    echo class="tk-str">"Blocked: " . $e->getMessage();
}