Stateful tools, zero infrastructure

Key-value storage, a relational database, file storage, message queues, and vector search. All built in, all accessible from your tool code via fold.

Key-Value

Fast key-value storage with optional TTL expiration. Store configuration, cache results, or manage session state.

await fold.kv.put('user:123', data);
const val = await fold.kv.get('user:123');

Database

SQL database per workspace. Run queries with parameterized bindings. Ideal for structured data that needs relational queries.

const rows = await fold.db
.prepare('SELECT * FROM logs')
.all();

Object Storage

File and blob storage with versioning. Upload images, PDFs, generated assets, or any binary data. Retrieve by key.

await fold.storage.put(
'report.pdf', pdfBuffer
);
const file = await fold.storage.get('report.pdf');

Queue

Asynchronous message processing. Send tasks to a queue and process them in the background. Supports delayed delivery.

await fold.queue.send({
type: 'email',
to: 'user@example.com'
});

Fold Memory

Vector search for semantic retrieval and RAG. Store embeddings and query by similarity. Give your tools long-term memory.

const results = await
fold.vectorize.query(embedding, {
topK: 5,
returnMetadata: true
});

No provisioning required

Storage bindings are attached automatically when you deploy. No databases to create, no buckets to configure, no connection strings to manage. Just use fold.kv, fold.db, fold.storage, fold.queue, or fold.vectorize and it works.

Full example: tool with persistent state

Combine multiple storage bindings in a single tool. This example stores notes in the database and makes them searchable via vector embeddings.

import { defineHandler } from '@fold-run/runtime';
 
export default defineHandler(async (fold: FoldContext) => {
const { action, text, query } = await fold.body<{ action: string; text?: string; query?: string }>();
 
if (action === 'save') {
// Store in DB + index for search
await fold.db.prepare('INSERT INTO notes (text) VALUES (?)').bind(text).run();
const embedding = await fold.ai.run('@fold/bge-base', { text });
await fold.vectorize.insert([{ id: crypto.randomUUID(), values: embedding }]);
}
 
if (action === 'search') {
const qEmbed = await fold.ai.run('@fold/bge-base', { text: query });
const matches = await fold.vectorize.query(qEmbed, { topK: 5 });
return fold.json(matches);
}
 
return fold.json({ ok: true });
});
← Safety & GuardrailsAI Code Generation →

Start building stateful tools

Free tier includes storage, database, and queue access. No credit card required.

Get Started