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 — save a conversation to the brain
<?php
function persist(): string {
global $base, $token;
$payload = json_encode([
'dump' => [
'turns' => [
['role' => 'user', 'content' => 'What queue library should we use?'],
['role' => 'assistant', 'content' => 'Switched to pgmq — simpler ops than Redis.'],
],
],
'sourceRef' => 'session-1',
]);
$ch = curl_init("{$base}/v1/brain/remember");
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['jobId'];
}
$jobId = persist();
echo "jobId: {$jobId}\n";remember runs the save-or-skip curation pipeline (dedupe, curated notes, entity facts) as a background job — poll GET /v1/brain/jobs/{jobId} for status. To write a document directly instead, POST a { type: "document", content, ... } item to /v1/brain/ingest — see Ingest.