Complete API documentation for integrating with the Continuity Engine programmatically.
Authentication
All API endpoints require authentication. Include your session token in the request headers. Workspace-scoped endpoints also require workspace membership.
Retrieves the current context state for a conversation, including the rolling summary, pinned memory, and metadata.
GET /api/context?conversationId={conversationId}{
"success": true,
"context": {
"rollingSummary": {
"goals": ["Build a REST API for user management"],
"decisions": [
{
"id": "dec_1",
"decision": "Use PostgreSQL",
"reason": "Need strong consistency",
"timestamp": "2024-01-15T10:30:00Z"
}
],
"requirements": ["Support 10k concurrent users"],
"currentPlan": ["Design schema", "Implement endpoints"],
"openQuestions": ["Caching strategy?"],
"definitions": {
"user": "A registered customer with verified email"
},
"importantReferences": [
{ "type": "file", "value": "schema.prisma", "label": "DB Schema" }
],
"stylePreferences": {},
"lastUpdated": "2024-01-15T10:30:00Z",
"version": 3
},
"pinnedMemory": [
{
"id": "pin_1",
"messageId": "msg_123",
"content": "API must use JWT authentication",
"category": "requirement",
"pinnedAt": "2024-01-15T09:00:00Z"
}
],
"metadata": {
"totalTokens": 15000,
"compressedTokens": 12000,
"preservationRatio": 80,
"lastCompactionAt": "2024-01-15T10:30:00Z",
"recentMessageCount": 20
}
}
}Retrieves just the rolling summary without pinned memory or metadata.
GET /api/context/summary?conversationId={conversationId}{
"success": true,
"summary": {
"goals": [...],
"decisions": [...],
"requirements": [...],
"currentPlan": [...],
"openQuestions": [...],
"definitions": {...},
"importantReferences": [...],
"stylePreferences": {...},
"lastUpdated": "2024-01-15T10:30:00Z",
"version": 3
}
}Triggers a manual compaction of the conversation context.
POST /api/context/compact
Content-Type: application/json
{
"conversationId": "conv_123",
"level": "light" // "light" | "deep" | "aggressive"
}{
"success": true,
"result": {
"success": true,
"previousTokenCount": 15000,
"newTokenCount": 10000,
"tokensRemoved": 5000,
"summaryUpdated": true
}
}Pins a message to preserve it in the context.
POST /api/context/pin/{conversationId}
Content-Type: application/json
{
"messageId": "msg_123",
"category": "decision" // optional: "decision" | "requirement" | "reference" | "other"
}{
"success": true,
"pinnedItem": {
"id": "pin_abc",
"messageId": "msg_123",
"content": "We decided to use PostgreSQL...",
"category": "decision",
"pinnedAt": "2024-01-15T11:00:00Z"
}
}Removes a pin from a message.
DELETE /api/context/pin/{conversationId}?messageId={messageId}{
"success": true
}Marks a message to be excluded from (or included in) the rolling summary.
PATCH /api/context/exclude/{conversationId}/{messageId}
Content-Type: application/json
{
"exclude": true // true to exclude, false to include
}{
"success": true
}Retrieves all user memory items, optionally filtered by type.
GET /api/memory?workspaceId={workspaceId}&type={type}
// type is optional: "preference" | "fact" | "constraint" | "definition"{
"success": true,
"memories": [
{
"id": "mem_1",
"type": "preference",
"key": "coding_style",
"content": "I prefer functional programming patterns"
},
{
"id": "mem_2",
"type": "fact",
"key": "project_stack",
"content": "Next.js 14 with TypeScript and Tailwind"
}
]
}Creates a new user memory item.
POST /api/memory
Content-Type: application/json
{
"type": "preference",
"key": "coding_style",
"content": "I prefer functional programming patterns with TypeScript",
"workspaceId": "ws_123" // optional
}{
"success": true,
"memory": {
"id": "mem_abc",
"type": "preference",
"key": "coding_style",
"content": "I prefer functional programming patterns with TypeScript"
}
}Updates an existing user memory item.
PATCH /api/memory/{memoryId}
Content-Type: application/json
{
"content": "Updated content here",
"isActive": true // optional: deactivate without deleting
}{
"success": true,
"memory": {
"id": "mem_abc",
"type": "preference",
"key": "coding_style",
"content": "Updated content here"
}
}Permanently deletes a user memory item.
DELETE /api/memory/{memoryId}{
"success": true
}For client-side integration, use the useConversationContext hook:
import { useConversationContext } from "@/lib/continuity-engine/client";
function ChatInterface({ conversationId, workspaceId }) {
const context = useConversationContext({
conversationId,
workspaceId,
enabled: true,
});
// Access state
const { summary, pinnedMemory, metadata, isLoading, error } = context;
// UI controls
const { isDrawerOpen, openDrawer, closeDrawer } = context;
// Actions
const handlePin = async (messageId: string) => {
await context.pinMessage(messageId, "decision");
};
const handleUnpin = async (messageId: string) => {
await context.unpinMessage(messageId);
};
const handleExclude = async (messageId: string, exclude: boolean) => {
await context.excludeMessage(messageId, exclude);
};
const handleCompact = async () => {
await context.compact("light");
};
return (
<>
<ContextIndicator
metadata={metadata}
pinnedCount={pinnedMemory.length}
onClick={openDrawer}
/>
<SummaryDrawer
isOpen={isDrawerOpen}
onClose={closeDrawer}
summary={summary}
pinnedMemory={pinnedMemory}
metadata={metadata}
onCompact={handleCompact}
onUnpin={handleUnpin}
isCompacting={context.isCompacting}
/>
</>
);
}interface UseConversationContextReturn {
// State
summary: RollingSummary | null;
pinnedMemory: PinnedMemoryItem[];
metadata: ContextMetadata | null;
isLoading: boolean;
error: Error | null;
isCompacting: boolean;
// UI Controls
isDrawerOpen: boolean;
openDrawer: () => void;
closeDrawer: () => void;
// Actions
refresh: () => Promise<void>;
pinMessage: (messageId: string, category?: PinnedMemoryCategory) => Promise<boolean>;
unpinMessage: (messageId: string) => Promise<boolean>;
excludeMessage: (messageId: string, exclude: boolean) => Promise<boolean>;
compact: (level?: CompactionLevel) => Promise<boolean>;
}All types are exported from @/lib/continuity-engine/client:
// Core types
export type {
RollingSummary,
Decision,
Reference,
StylePreferences,
PinnedMemoryItem,
PinnedMemoryCategory,
UserMemoryItem,
MemoryType,
ContextMetadata,
ContextPack,
CompactionLevel,
CompactionResult,
} from "./types";
// Hook
export { useConversationContext } from "./useConversationContext";
// Constants
export { CONTINUITY_CONFIG, FEATURE_FLAGS } from "./constants";All endpoints return a consistent error format:
{
"success": false,
"error": "Descriptive error message"
}
// HTTP Status Codes:
// 400 - Bad Request (invalid parameters)
// 401 - Unauthorized (missing/invalid auth)
// 403 - Forbidden (no workspace access)
// 404 - Not Found (conversation/message doesn't exist)
// 500 - Internal Server ErrorRate Limiting
API endpoints are rate-limited. The compact endpoint has stricter limits due to its computational cost. Expect 429 responses if limits are exceeded.