Quick setup examples

PHP (HTTP) Quickstart

Call the Unison brain from PHP using the built-in curl extension — no Composer packages required.

PHP's curl extension is available in every standard installation. The two functions below are copy-paste ready.

Prerequisites

export UNISON_TOKEN=usk_live_...

PHP 8.0 or later with the curl extension enabled.

Recall — fetch prompt-ready context

<?php

$base  = 'https://brain.unisonlabs.ai';
$token = getenv('UNISON_TOKEN');

function recall(string $query): string {
    global $base, $token;

    $params = http_build_query(['q' => $query, 'k' => 5, 'mode' => 'auto']);
    $ch = curl_init("{$base}/v1/brain/context?{$params}");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER     => ["Authorization: Bearer {$token}"],
    ]);

    $body = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($body, true);
    return $data['weakEvidence'] ? '' : $data['contextMd'];
}

$memory = recall('payment service architecture');
echo $memory;

Persist — write memory to the brain

<?php

function persist(): string {
    global $base, $token;

    $payload = json_encode([
        'items' => [
            [
                'type'  => 'conversation',
                'turns' => [
                    ['role' => 'user',      'content' => 'What queue library should we use?'],
                    ['role' => 'assistant', 'content' => 'Switched to pgmq — simpler ops than Redis.'],
                ],
                'sourceRef'  => 'session-1',
                'visibility' => 'private',
            ],
        ],
    ]);

    $ch = curl_init("{$base}/v1/brain/ingest");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $payload,
        CURLOPT_HTTPHEADER     => [
            "Authorization: Bearer {$token}",
            'Content-Type: application/json',
        ],
    ]);

    $body = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($body, true);
    return $data['items'][0]['jobId'];
}

$jobId = persist();
echo "jobId: {$jobId}\n";

On this page