MemorySync
API Reference

Compose Prompt

Build a prompt with memories available to the authenticated principal and selected project, within a requested token budget.

Endpoint and request fields

POST/memory/compose
200 OK
FieldTypeContract
prompt_template / promptTemplatestringRequired complete prompt; it is also used as the recall query.
recall_k / recallKintegerOptional number of memories to recall; REST defaults to 10.
max_tokens / maxTokensintegerOptional composition token budget; REST defaults to 2000.

Compose a prompt

import os
from memorysync import MemorySyncClient
client = MemorySyncClient(
api_key=os.environ["MEMORYSYNC_API_KEY"],
base_url="https://api.memorysync.io",
project_id=os.environ["MEMORYSYNC_PROJECT_ID"],
end_user_id="usr_7f3a9c2e",
)
result = client.compose(
"Answer this support question using relevant preferences: Which interface theme should we use?",
recall_k=5,
max_tokens=1200,
)

Result paths

MeaningPythonNode.jsREST
Promptresult.composed_promptresult.composedPromptcomposed_prompt
Memories usedresult.memories_usedresult.memoriesUsedmemories_used
Token countresult.token_countresult.tokenCounttoken_count
Budget truncationresult.truncatedresult.truncatedtruncated
200-response.json
{"composed_prompt":"Relevant context:
- The user prefers dark mode.
Answer this support question using relevant preferences: Which interface theme should we use?","memories_used":1,"token_count":29,"truncated":false}

Errors and next action

For 400 or 422, correct the template or numeric fields. Correct authentication and scope errors before trying again. For 429 or 5xx, continue without composed memory context or show a recoverable state according to your product.

Safety notes