SDK

PHP SDK

Install the PHP SDK, create a client and call every endpoint from PHP 8.2 or later

The neurophic/neurophic package is a typed client for the REST API. It sends requests with Guzzle and needs PHP 8.2 or later. Using Laravel? See the Laravel package.

Install

composer
composer require neurophic/neurophic

Create a client

use Neurophic\Neurophic;

$client = new Neurophic(
    apiKey: getenv('NEUROPHIC_API_KEY'),
    baseUrl: 'https://api.neurophic.ai',
    timeout: 10,
);
  • apiKey: a project key. Falls back to the NEUROPHIC_API_KEY environment variable; if neither is set the constructor throws.
  • baseUrl: where requests go. Defaults to the production API.
  • timeout: seconds before the client stops waiting. Defaults to 30.
  • http: your own Guzzle client, for middleware or a proxy.
Note:Pass identifier as the first argument of every call. Keep keys server-side; see Get started > API keys.

Every date argument takes an ISO 8601 string or any DateTimeInterface.

Memory

Ingest

Stores a memory. The write is queued, not written on the spot.

use Neurophic\Enums\MemoryRole;

$receipt = $client->ingest(
    'user-123',
    'Prefers window seats on long flights.',
    name: 'Ada',
    occurredAt: '2026-08-12T09:12:00Z',
    role: MemoryRole::User,
);

$receipt->id;     // becomes the memory id once the write is processed
$receipt->status; // "queued"
  • occurredAt: when the content was said. Defaults to now; set it when backfilling history, oldest first.
  • role: who said it, MemoryRole::User by default. Store your agent's own replies as MemoryRole::Assistant; they never replace what the person said.

Learn more under API reference > Ingest.

Context

Fetches a short, ready-to-prompt summary for a query, as a string. It is empty when nothing is relevant.

use Neurophic\Enums\RerankMode;

$context = $client->context(
    'user-123',
    'Booking a flight to Lisbon next month',
    sources: true,
    rerank: RerankMode::Fast,
);
  • roles: whose words to include, the person's own by default. Add MemoryRole::Assistant for what your agent said.
  • sources: also return the original turns, each once: the turns behind the block, plus up to five that match the query directly.
  • rerank: a second ranking stage before the cut, RerankMode::Fast or RerankMode::Thorough. Off by default; a paid mode adds the reranking model's cost to the request.

Learn more under API reference > Context.

Retrieve

Searches memory. retrieve builds the call and nothing is sent until you choose the shape of the result: ->markdown() returns Markdown ready to drop into a prompt, ->structured() returns the same results as typed objects.

use Neurophic\Enums\MemoryRole;
use Neurophic\Enums\RerankMode;

$markdown = $client->retrieve('user-123', 'travel preferences')->markdown();

$result = $client->retrieve(
    'user-123',
    'travel preferences',
    goal: 'book a flight for the user',
    since: '2026-08-01T00:00:00Z',
    roles: [MemoryRole::User, MemoryRole::Assistant],
    limit: 10,
    referenceDate: '2026-08-19',
    sources: true,
    rerank: RerankMode::Fast,
)->structured();

foreach ($result->memories as $memory) {
    echo $memory->content;
}
  • since, until: only memories observed in that window.
  • roles: whose words to return, the person's own by default. Add MemoryRole::Assistant for what your agent said; patterns are always the person's.
  • sources: also return the original turns, each once, as $result->sources, with sourceId on each memory they were taken from.
  • rerank: a second ranking stage before the cut, RerankMode::Fast or RerankMode::Thorough. Off by default; a paid mode adds the reranking model's cost to the request, and limit still applies after it.
  • referenceDate: the day relative time in the query, such as "last week", is read from. Defaults to today.

The structured result holds memories, observations, patterns and sources, as lists of RetrievedMemory, RetrievedObservation, RetrievedPattern and RetrievedSource. Timestamps are DateTimeImmutable and each role is a MemoryRole. relevance is null when rerank was used; the order of the list is then the ranking.

Learn more under API reference > Retrieve.

List

Pages through every memory stored for an identifier, newest first.

$page = $client->memory->list('user-123', page: 2, perPage: 10);

$page->total;
$page->memories[0]->content;

Learn more under API reference > List.

Get

Fetches one memory by id.

$memory = $client->memory->get('5f1d2c3e-...', identifier: 'user-123');

Learn more under API reference > Get.

Delete

Deletes one memory by id.

$client->memory->delete('5f1d2c3e-...', identifier: 'user-123');

Pass restorePrevious: true to delete only this version and restore the one it superseded.

Learn more under API reference > Delete.

Errors

Any response outside the 2xx range is thrown as a Neurophic\Exceptions\NeurophicException carrying:

status
int
The HTTP status; 0 for timeouts and connection failures.
errorCode
string
The API error code, for example VALIDATION_ERROR; see API reference > Errors. UNKNOWN when the body is not the standard envelope, for example a plain-text 413 from the edge.
knownCode()
?ErrorCode
The same code as an ErrorCode enum case, or null for a code this version of the SDK does not know.
getMessage()
string
The API message.
details
list<ValidationDetail>
The field-level problems on a VALIDATION_ERROR, each with field and message.
body
mixed
The raw response body, decoded from JSON when possible. On INSUFFICIENT_CREDIT, balance and required are under body['error'].

Two subclasses cover failures that never reach the API:

  • NeurophicTimeoutException. The client stopped waiting; the API may still have handled the request.
  • NeurophicConnectionException. A network failure, with the cause as getPrevious().
Tip:The client never retries; add your own backoff if you need it.
use Neurophic\Enums\ErrorCode;
use Neurophic\Exceptions\NeurophicException;
use Neurophic\Exceptions\NeurophicTimeoutException;

try {
    $client->ingest('user-123', 'Prefers window seats.');
} catch (NeurophicTimeoutException $e) {
    error_log('No reply in time; the write may still go through.');
} catch (NeurophicException $e) {
    match ($e->knownCode()) {
        ErrorCode::ValidationError => error_log($e->getMessage().' '.json_encode($e->details)),
        ErrorCode::InsufficientCredit => error_log('Not enough credit. Top up the project.'),
        default => error_log("{$e->status} {$e->errorCode} {$e->getMessage()}"),
    };
}

Licence

The SDK is MIT-licensed; use of the API it calls is governed by the Terms of Use.