Patterns
Patterns capture reusable coding conventions, best practices, and architectural patterns. They can be scoped globally or to specific projects, and adopted across your project portfolio.
Create Pattern
POST /v1/patterns
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
title | string | Yes | Pattern title (1-500 characters) |
description | string | Yes | Full description with rationale (1-50,000 characters) |
scope | string | No | global (all projects, default) or project (specific projects only) |
category | string | No | Category (e.g. validation, error-handling, auth, testing, max 100 characters) |
tags | array | No | Tags for categorization (max 20 tags, each max 100 characters) |
example_code | string | No | Code snippet demonstrating the pattern (max 50,000 characters) |
source_project | string | No | Slug of the project where this pattern originated |
metadata | object | No | Custom metadata (max 10KB) |
Response 201 Created
{
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas before processing. This ensures type safety and provides clear error messages to clients.",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod", "typescript"],
"example_code": "const schema = z.object({\n name: z.string().min(1).max(255),\n email: z.string().email(),\n});\n\nexport async function POST(req: Request) {\n const body = schema.parse(await req.json());\n // ...\n}",
"source_project_id": null,
"source_project_slug": "northrelay",
"metadata": {},
"adoption_count": 0,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
}
curl
curl -X POST https://api.memoryrelay.net/v1/patterns \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas before processing.",
"category": "validation",
"tags": ["api", "validation", "zod"],
"source_project": "northrelay",
"example_code": "const schema = z.object({\n name: z.string().min(1).max(255)\n});"
}'
Python SDK
from memoryrelay import MemoryRelay
client = MemoryRelay(api_key="mem_prod_...")
pattern = client.patterns.create(
title="Zod validation at API boundaries",
description="All API route handlers validate input with Zod schemas before processing.",
category="validation",
tags=["api", "validation", "zod"],
source_project="northrelay",
)
print(pattern.id)
Search Patterns
POST /v1/patterns/search
Semantic search across patterns. Useful for finding relevant patterns when starting work on a new feature.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Natural language search query |
limit | integer | No | Number of results (default: 10) |
category | string | No | Filter by category |
Response
{
"data": [
{
"pattern": {
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas...",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod"],
"adoption_count": 3,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
},
"score": 0.92
}
],
"query": "How should I validate API request bodies?",
"total": 1
}
curl
curl -X POST https://api.memoryrelay.net/v1/patterns/search \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How should I validate API request bodies?",
"limit": 5
}'
Python SDK
results = client.patterns.search(
query="How should I validate API request bodies?",
limit=5,
)
for r in results.data:
print(f"[{r.score:.2f}] {r.pattern.title}")
List Patterns
GET /v1/patterns
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | integer | 20 | Results per page (1-100) |
offset | integer | 0 | Number of results to skip |
category | string | -- | Filter by category |
scope | string | -- | Filter by scope: global or project |
tag | string | -- | Filter by tag |
Response
{
"data": [
{
"id": "b1c2d3e4-f5a6-7890-bcde-f12345678901",
"title": "Zod validation at API boundaries",
"description": "All API route handlers validate input with Zod schemas...",
"scope": "global",
"category": "validation",
"tags": ["api", "validation", "zod"],
"adoption_count": 3,
"created_at": "2026-03-17T10:00:00Z",
"updated_at": "2026-03-17T10:00:00Z"
}
],
"next_cursor": null,
"has_more": false,
"total_count": 1
}
curl
curl "https://api.memoryrelay.net/v1/patterns?category=validation&limit=20" \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"
Python SDK
patterns = client.patterns.list(category="validation")
for p in patterns.data:
print(f"{p.title} (adopted by {p.adoption_count} projects)")
Get Pattern
GET /v1/patterns/{id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | Pattern ID |
Response
Returns a single pattern object including example_code if present.
curl
curl https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"
Python SDK
pattern = client.patterns.get("b1c2d3e4-f5a6-7890-bcde-f12345678901")
if pattern.example_code:
print(pattern.example_code)
Update Pattern
PATCH /v1/patterns/{id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | Pattern ID |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
title | string | No | Updated title (max 500 characters) |
description | string | No | Updated description (max 50,000 characters) |
scope | string | No | Updated scope: global or project |
category | string | No | Updated category |
tags | array | No | Updated tags |
example_code | string | No | Updated code snippet |
metadata | object | No | Updated metadata |
Response
Returns the updated pattern object.
curl
curl -X PATCH https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"tags": ["api", "validation", "zod", "best-practice"]
}'
Python SDK
updated = client.patterns.update(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
tags=["api", "validation", "zod", "best-practice"],
)
Delete Pattern
DELETE /v1/patterns/{id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | Pattern ID |
Response
Returns 204 No Content on success.
curl
curl -X DELETE https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901 \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"
Python SDK
client.patterns.delete("b1c2d3e4-f5a6-7890-bcde-f12345678901")
Adopt Pattern
POST /v1/patterns/{id}/adopt
Adopt a pattern for a specific project. This registers the project as using this pattern and increments the pattern's adoption_count.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | Pattern ID |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
project | string | Yes | Project slug to adopt this pattern for (1-100 characters) |
Response
Returns the updated pattern object with incremented adoption_count.
curl
curl -X POST https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901/adopt \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"project": "my-api"
}'
Python SDK
client.patterns.adopt(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
project="my-api",
)
Unadopt Pattern
DELETE /v1/patterns/{id}/adopt
Remove a pattern adoption for a specific project.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | UUID | Pattern ID |
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
project | string | Yes | Project slug to unadopt |
Response
Returns 204 No Content on success.
curl
curl -X DELETE "https://api.memoryrelay.net/v1/patterns/b1c2d3e4-f5a6-7890-bcde-f12345678901/adopt?project=my-api" \
-H "Authorization: Bearer $MEMORYRELAY_API_KEY"
Python SDK
client.patterns.unadopt(
"b1c2d3e4-f5a6-7890-bcde-f12345678901",
project="my-api",
)
When starting work on a new feature, call POST /v1/patterns/search with a description of what you are building. Your agent can then follow established patterns instead of inventing new approaches.