PHPackages                             memra/sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. memra/sdk

ActiveLibrary[API Development](/categories/api)

memra/sdk
=========

Official PHP SDK for Memra - Memory API for AI agents

4.5.0(1mo ago)00MITPHPPHP ^8.2

Since Jul 4Pushed 1mo agoCompare

[ Source](https://github.com/usememra/sdk-php)[ Packagist](https://packagist.org/packages/memra/sdk)[ Docs](https://github.com/usememra/sdk-php)[ RSS](/packages/memra-sdk/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Memra PHP SDK
=============

[](#memra-php-sdk)

Official PHP SDK for the Memra Memory API -- persistent, searchable memory for AI agents and LLM applications. Privacy-first and EU-native.

> Since 4.5.0 the SDK version tracks the Memra platform version.

What's New in 4.5.0
-------------------

[](#whats-new-in-450)

- **Read-your-writes:** every write response includes a `revision` token; pass it to `recall(waitForRevision:)` to guarantee the write is indexed before recall runs.
- **Conflicts on write:** create responses include `conflicts` -- memories the new fact contradicts (when contradiction detection is enabled).
- **Token-budget recall:** `recall(maxTokens:)` trims results to fit a token budget.
- **Recall filters:** `notTags`, `since`, `until` for tag-exclusion and time-window recall.
- **Feedback loop:** report which recalled memories were actually used via `memories()->feedback()` or inline with `recall(usedIds:)` -- boosts future scoring.
- **Entity graph API:** `entities()->list()` and `entities()->memories()` make the entity graph queryable.
- **Read-only scoped keys:** the API now supports read-only scoped API keys -- use one with this SDK for recall-only integrations (write calls will be rejected by the server).

Requirements
------------

[](#requirements)

- PHP 8.1+
- Guzzle 7.5+ (ships with Laravel)

Installation
------------

[](#installation)

```
composer require memra/sdk
```

Configuration (Laravel)
-----------------------

[](#configuration-laravel)

The SDK auto-discovers via Laravel's package discovery -- no manual registration needed.

Set your API key in `.env`:

```
MEMRA_API_KEY=memra_live_your_key_here
MEMRA_PROJECT_ID=my-project
```

Optionally publish the config file:

```
php artisan vendor:publish --tag=memra-config
```

This creates `config/memra-sdk.php` where you can customize `base_url`, `timeout`, and `project_id`.

> **Using `config:cache`?** Publishing the config file is recommended -- it guarantees the SDK's settings are part of your cached configuration. Remember to re-run `php artisan config:cache` after installing or updating the SDK.

Quick Start (Laravel) -- 5 Minutes
----------------------------------

[](#quick-start-laravel----5-minutes)

### 1. Install

[](#1-install)

```
composer require memra/sdk
```

### 2. Configure

[](#2-configure)

Add to your `.env`:

```
MEMRA_API_KEY=memra_live_your_key_here
MEMRA_PROJECT_ID=my-project
```

### 3. Store a Memory

[](#3-store-a-memory)

```
use Memra\Sdk\Facades\Memra;

$memory = Memra::add(
    content: 'User prefers dark mode and TypeScript',
    tenantId: 'user_123',
    projectId: 'my-project',
    type: 'preference',
    importance: 8,
    tags: ['ui', 'language'],
);

echo $memory->id; // mem_01HXYZ...
```

### 4. Recall Memories

[](#4-recall-memories)

```
$results = Memra::recall(
    query: 'What does the user prefer?',
    tenantId: 'user_123',
    projectId: 'my-project',
    limit: 5,
);

foreach ($results->data as $memory) {
    echo "{$memory->content} (score: {$memory->score})\n";
}
```

### 5. Delete a Memory

[](#5-delete-a-memory)

```
Memra::delete('mem_01HXYZ');
```

Quick Start (Plain PHP)
-----------------------

[](#quick-start-plain-php)

```
use Memra\Sdk\MemraClient;

$client = new MemraClient(apiKey: 'memra_live_your_key_here');

// Store a memory
$memory = $client->memories()->add(
    content: 'User prefers dark mode',
    tenantId: 'user_123',
    projectId: 'my-project',
    type: 'preference',
    importance: 8,
);

// Recall memories
$results = $client->memories()->recall(
    query: 'What does the user prefer?',
    tenantId: 'user_123',
    projectId: 'my-project',
);

// List memories
$list = $client->memories()->list(
    tenantId: 'user_123',
    projectId: 'my-project',
);

// Delete a memory
$client->memories()->delete($memory->id);
```

API Reference
-------------

[](#api-reference)

### Memories

[](#memories)

```
// Via Facade (Laravel)
Memra::add(content, tenantId, projectId, type?, importance?, tags?, source?, metadata?);
Memra::recall(query, tenantId, projectId, limit?, types?, tags?, minImportance?, minScore?, includeRecency?, rerank?, waitForRevision?, maxTokens?, notTags?, since?, until?, usedIds?);
Memra::list(tenantId, projectId, type?, tags?, minImportance?, limit?, offset?);
Memra::delete(id);

// Via Client (Plain PHP or Laravel)
$client->memories()->add(...);
$client->memories()->recall(...);
$client->memories()->list(...);
$client->memories()->get(id);
$client->memories()->update(id, content?, importance?, tags?, metadata?);
$client->memories()->delete(id);
$client->memories()->bulkDelete(tenantId, projectId?);
$client->memories()->batch(memories);          // Up to 100 per call
$client->memories()->supersede(id, content, metadata?);
$client->memories()->chain(id);                // Get supersession chain
$client->memories()->promote(id, targetNamespace?, promotedBy?);  // -> PromotionResult
$client->memories()->refresh(id);              // Reset staleness -> HealthStatus
$client->memories()->feedback(tenantId, projectId, memoryIds);  // -> ['updated' => int]
```

#### Write responses (v4.5)

[](#write-responses-v45)

Every write returns a `Memory` DTO with:

- `revision` (int) -- read-your-writes token; pass to `recall(waitForRevision:)`
- `embeddingStatus` (string) -- embeddings are async: `'pending'` until indexed
- `conflicts` (array) -- on create, memories the new fact contradicts (empty unless contradiction detection is enabled)

```
$memory = $client->memories()->add(
    content: 'User switched to PostgreSQL',
    tenantId: 'user_123',
    projectId: 'my-project',
);

// Read-your-writes: this recall is guaranteed to see the write above
$results = $client->memories()->recall(
    query: 'What database does the user run?',
    tenantId: 'user_123',
    projectId: 'my-project',
    waitForRevision: $memory->revision,
);
```

#### Recall options (v4.5)

[](#recall-options-v45)

```
$results = $client->memories()->recall(
    query: 'deployment preferences',
    tenantId: 'user_123',
    projectId: 'my-project',
    maxTokens: 2000,                    // token-budget recall
    notTags: ['archived'],              // exclude by tag
    since: '2026-01-01T00:00:00Z',      // time window
    until: '2026-06-30T23:59:59Z',
    usedIds: ['mem_01ABC'],             // feedback from previous recall
);
```

#### Feedback loop (v4.5)

[](#feedback-loop-v45)

Report which recalled memories were actually useful -- they get a scoring boost on future recalls:

```
$result = $client->memories()->feedback(
    tenantId: 'user_123',
    projectId: 'my-project',
    memoryIds: ['mem_01ABC', 'mem_02DEF'],
);
echo $result['updated']; // 2
```

Or save a round trip by passing `usedIds` on the next `recall()` call.

### Projects

[](#projects)

```
$client->projects()->create(name, description?);
$client->projects()->list(limit?, offset?);
$client->projects()->get(id);
$client->projects()->delete(id);
```

### Webhooks

[](#webhooks)

```
$client->webhooks()->create(url, events, secret?);
$client->webhooks()->list();
$client->webhooks()->delete(id);
```

### Bootstrap

[](#bootstrap)

```
$client->bootstrap()->get(agentId, tenantId?, projectId?, maxTokens?, includeTypes?, excludeTypes?, recencyDays?);
$client->bootstrap()->configure(agentId, config);
$client->bootstrap()->showConfig(agentId);
```

### Health

[](#health)

```
$client->health()->memory(id);       // Single memory health status
$client->health()->refresh(id, note?); // Reset staleness score
$client->health()->namespace(tenantId?, projectId?); // Namespace-level health
```

### Audit

[](#audit)

```
$client->audit()->list(filters?);
$client->audit()->export(format?, filters?);  // CSV or JSON
```

### Erasure

[](#erasure)

```
$client->erasure()->create(tenantId, reason?); // Erasure request
$client->erasure()->show(id);
```

### Export

[](#export)

```
$client->export()->account(format?);           // Full account export
$client->export()->namespace(tenantId, projectId?, format?);
```

### Entities (v4.5)

[](#entities-v45)

Query the entity graph built by the intelligence pipeline:

```
// List entities for a namespace (most-mentioned first)
$entities = $client->entities()->list(
    tenantId: 'user_123',
    projectId: 'my-project',
    entityType: 'person',  // optional filter
    limit: 50,             // optional (max 200)
);

foreach ($entities as $entity) {
    echo "{$entity->name} ({$entity->type}): {$entity->memoryCount} memories\n";
}

// List memories mentioning an entity (metadata only, no content)
$result = $client->entities()->memories(
    name: 'Jane Doe',
    tenantId: 'user_123',
    projectId: 'my-project',
);
// $result = ['entity' => 'Jane Doe', 'memories' => [...], 'total' => 3]
```

PII entities appear under their stable IDs, never raw values.

### Usage

[](#usage)

```
$client->usage()->get();
```

Privacy &amp; Data Protection
-----------------------------

[](#privacy--data-protection)

Memra is privacy-first. The PHP SDK provides access to data export and erasure endpoints.

### Data Export

[](#data-export)

```
// Export all account data
$data = $client->export()->account();
echo $data->exported_at;

// Export namespace data (per-tenant)
$data = $client->export()->namespace('tenant_123');

// Export namespace data filtered by project
$data = $client->export()->namespace('tenant_123', projectId: 'proj_1');
```

### Data Erasure

[](#data-erasure)

```
// Request erasure of a memory
$request = $client->erasure()->create('mem_abc123');
echo $request->status; // 'pending'

// Check erasure status
$status = $client->erasure()->show('mem_abc123');
echo $status->status; // 'completed'
```

Erasure is thorough: flat files, database index rows, Redis cache entries, and audit log entries are all purged. The erasure request is tracked with a scheduled deletion date and completion status.

Memory Types
------------

[](#memory-types)

TypeDescription`fact`Factual knowledge (e.g., "User works at Acme Corp")`event`Time-bound occurrences (e.g., "User deployed v2.0 on March 15")`pattern`Behavioral patterns (e.g., "User always reviews PRs before merging")`working`Short-term context, auto-expires after 24 hours`decision`Decisions with supersession chains (e.g., "Switched from MySQL to PostgreSQL")`preference`User preferences (e.g., "Prefers dark mode")`context`Contextual information (e.g., "Currently working on Project X")`entity`Entity references (e.g., "User's manager is Jane Doe")Error Handling
--------------

[](#error-handling)

All API errors throw typed exceptions:

```
use Memra\Sdk\Exceptions\MemraAuthException;
use Memra\Sdk\Exceptions\MemraNotFoundException;
use Memra\Sdk\Exceptions\MemraValidationException;
use Memra\Sdk\Exceptions\MemraQuotaException;
use Memra\Sdk\Exceptions\MemraServerException;
use Memra\Sdk\Exceptions\MemraTimeoutException;

try {
    $memory = Memra::add(
        content: 'Important fact',
        tenantId: 'user_123',
        projectId: 'my-project',
    );
} catch (MemraAuthException $e) {
    // 401 -- invalid or missing API key
    echo "Auth error: {$e->getMessage()}";
} catch (MemraValidationException $e) {
    // 422 -- validation errors with per-field details
    foreach ($e->errors as $field => $messages) {
        echo "{$field}: " . implode(', ', $messages) . "\n";
    }
} catch (MemraQuotaException $e) {
    // 429 -- rate limited
    echo "Rate limited. Retry after {$e->retryAfter} seconds.";
    echo "Remaining: {$e->remaining}";
} catch (MemraNotFoundException $e) {
    // 404 -- resource not found
    echo "Not found: {$e->getMessage()}";
} catch (MemraServerException $e) {
    // 500/502/503 -- server error
    echo "Server error ({$e->statusCode}): {$e->getMessage()}";
} catch (MemraTimeoutException $e) {
    // Connection timeout
    echo "Request timed out: {$e->getMessage()}";
}
```

All exceptions extend `MemraException` and include `statusCode` and `responseBody` properties.

Testing
-------

[](#testing)

Use `Memra::fake()` in your tests to avoid making real API calls:

```
use Memra\Sdk\Facades\Memra;

test('it stores a user preference', function () {
    $fake = Memra::fake();

    // Your application code that calls Memra::add()
    storeUserPreference('user_123', 'dark mode');

    // Assert the memory was stored
    $fake->assertAdded();

    // Assert with specific criteria
    $fake->assertAdded(fn (array $args) =>
        $args['content'] === 'User prefers dark mode'
        && $args['type'] === 'preference'
    );
});

test('it recalls memories during conversation', function () {
    $fake = Memra::fake();

    getRelevantContext('user_123', 'What do I prefer?');

    $fake->assertRecalled();
});

test('it handles empty state', function () {
    $fake = Memra::fake();

    // Nothing should happen in this test path
    $fake->assertNothingSent();
});
```

### Available Assertions

[](#available-assertions)

MethodDescription`$fake->assertAdded(?callable)`Assert `add()` was called, optionally matching a callback`$fake->assertRecalled(?callable)`Assert `recall()` was called, optionally matching a callback`$fake->assertDeleted(?string $id)`Assert `delete()` was called, optionally for a specific ID`$fake->assertNothingSent()`Assert no calls were madeLicense
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2546754?v=4)[vonsensey](/maintainers/vonsensey)[@vonsensey](https://github.com/vonsensey)

---

Top Contributors

[![vonsensey](https://avatars.githubusercontent.com/u/2546754?v=4)](https://github.com/vonsensey "vonsensey (1 commits)")

---

Tags

sdkaimemoryagentsllmmemra

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/memra-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/memra-sdk/health.svg)](https://phpackages.com/packages/memra-sdk)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.3M49](/packages/tencentcloud-tencentcloud-sdk-php)[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

76364.8k1](/packages/mozex-anthropic-laravel)[files.com/files-php-sdk

Files.com PHP SDK

2482.9k](/packages/filescom-files-php-sdk)[jdcloud-api/jdcloud-sdk-php

JDCloud SDK for PHP

115.2k](/packages/jdcloud-api-jdcloud-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
