PHP SDK

Official PHP SDK for Anakin (anakin.io)

Official PHP SDK for the Anakin API. Wraps every documented endpoint with a single sync call, internal polling, and a typed exception hierarchy. Built on Guzzle 7.

StatusAlpha (v0.1.x)
LanguagePHP 8.1+ (with ext-curl and ext-json)
Packageanakin/sdk on Packagist
Sourcegithub.com/Anakin-Inc/anakin-php
LicenseApache 2.0

Install

composer require anakin/sdk

Quickstart

<?php
require 'vendor/autoload.php';

use Anakin\Client;

$client = new Client(['api_key' => 'ak-...']);  // or set ANAKIN_API_KEY env var

// Scrape a single URL — returns the final result, no polling required
$doc = $client->scrape('https://example.com');
echo $doc['markdown'];

// Discover URLs on a site
$sitemap = $client->map('https://example.com', ['limit' => 200]);
print_r($sitemap['links']);

// Crawl pages and get content for each
$crawl = $client->crawl('https://example.com', ['max_pages' => 20]);
foreach ($crawl['pages'] as $page) {
    echo $page['url'] . ': ' . strlen($page['markdown'] ?? '') . "\n";
}

What's in v0.1

MethodReturns
$client->scrape($url, $opts)array — the document
$client->map($url, $opts)array — discovered links
$client->crawl($url, $opts)array — crawled pages
$client->search($query, $opts)array — search results (synchronous API)
$client->agenticSearch($prompt, $opts)array — AI-synthesised answer
$client->wire($actionId, $params)array — Wire action result (run a Wire action)
$client->sessions()->list / create / save / update / deleteBrowser session CRUD

All response methods return associative arrays (the parsed JSON response). Strong typing via Psalm and PHPStan generics is on the v0.2 roadmap.

Configuration

$client = new Anakin\Client([
    'api_key'           => 'ak-...',                    // or ANAKIN_API_KEY env var
    'base_url'          => 'https://api.anakin.io/v1',
    'timeout'           => 60,                          // per-request HTTP timeout (seconds)
    'max_retries'       => 4,                           // retries on 429 / 5xx
    'poll_interval'     => 1.0,                         // initial polling delay
    'poll_max_interval' => 10.0,                        // cap on exponential backoff
    'poll_timeout'      => 300,                         // total wait before JobTimeoutException
    'http_client'       => $myGuzzleClient,             // optional — inject your own PSR-18 client
]);

Errors

use Anakin\Exception\{
    AnakinException,                // base for everything below
    AuthenticationException,        // bad/missing API key
    InsufficientCreditsException,   // 402 — exposes ->balance, ->required
    InvalidRequestException,        // 400
    JobFailedException,             // job came back with status="failed"
    JobTimeoutException,            // poll_timeout exceeded
    RateLimitException,             // 429 — exposes ->retryAfter
    ServerException,                // 5xx after retries
    NetworkException,               // DNS / connection / timeout
};

try {
    $doc = $client->scrape('https://example.com');
} catch (InsufficientCreditsException $e) {
    echo "out of credits: balance={$e->balance}, needed={$e->required}";
} catch (RateLimitException $e) {
    echo "rate limited; retry after {$e->retryAfter}s";
} catch (AnakinException $e) {
    echo "anakin error: {$e->getMessage()}";
}

Stability

v0.1.x is alpha. The public API may change between minor versions until v1.0. Pin a specific version in production:

{
    "require": {
        "anakin/sdk": "0.1.0"
    }
}

Raise issues on GitHub.