4 providers. 8 cell kinds. 1 uniform interface.
AI as a first-class cell kind in Quilt. Every LLM call, embedding, image, translation, sentiment, and code generation is a reactive cell that propagates with the rest of your sheet.
flowchart LR
t["input.text"] --> e["ai.embed<br/>(BGE)"]
e --> v["vector.search<br/>(top-K)"]
v --> l["ai.llm<br/>(z.ai)"]
l --> a["answer"]
z["ai.zai<br/>(expensive)"] --> r["router"]
d["ai.deepseek<br/>(cheap)"] --> r
b["budget.over"] --> r
r --> a
classDef provider fill:#1b2a4a,stroke:#e8a54b,color:#f5ead6
class z,d provider
npm install @superinstance/quilt-aiimport { AIEngine, createEngine } from '@superinstance/quilt-ai';
// Option 1: read keys from environment
const ai = createEngine();
// Option 2: pass keys explicitly
const ai = new AIEngine({
zaiKey: process.env.ZAI_TOKEN,
kimiKey: process.env.KIMI_TOKEN,
deepseekKey: process.env.DEEPSEEK_TOKEN,
cloudflareKey: process.env.CLOUDFLARE_TOKEN,
cloudflareAccountId: process.env.CLOUDFLARE_ACCOUNT_ID,
});
// Use it directly
const answer = await ai.call({
id: 'answer',
kind: 'ai.llm',
provider: 'zai',
model: 'glm-4.5',
prompt: 'What is Quilt?',
});
console.log(answer);Or wire it into a Quilt sheet:
import { Quilt } from '@superinstance/quilt-core';
import { AIEngine } from '@superinstance/quilt-ai';
const sheet = new Quilt({ ai: new AIEngine() });
sheet.load({
cells: [
{ id: 'question', kind: 'value', value: 'What is Quilt?' },
{ id: 'answer', kind: 'ai.llm', provider: 'zai', model: 'glm-4.5', prompt: '{{question}}' },
],
});
await sheet.tick();
console.log(sheet.get('answer'));| Provider | Best for | Models | Cost |
|---|---|---|---|
| z.ai | Coding, reasoning | GLM 4.5, AirX, Flash, 9B | $0.001-$0.002 / 1k |
| Kimi | Long context (128k) | v1 8k/32k/128k, K2 | $0.0001-$0.001 / 1k |
| DeepSeek | Cheap parallel workers | V3 Flash, R1 Reasoner | $0.0001-$0.002 / 1k |
| Cloudflare | Free tier, on-edge | Llama 3.3, Mistral, BGE, SDXL | Free tier 10k neurons/day |
| Kind | Input | Output | Example |
|---|---|---|---|
ai.llm |
prompt | text | Chat completion |
ai.embed |
text | vector | Semantic search |
ai.image |
prompt | image URL | Text → image |
ai.translate |
text + target | text | Multi-language |
ai.sentiment |
text | {label, score} | Classify mood |
ai.summarize |
long text | short text | TL;DR |
ai.code |
description | code | Code gen |
ai.vision |
image + prompt | text | Caption an image |
- id: extract
kind: ai.llm
prompt: "Extract entities from: {{text}}"
- id: classify
kind: ai.llm
prompt: "Classify sentiment of: {{extract}}"- id: draft.zai: { kind: ai.llm, provider: zai, ... }
- id: draft.kimi: { kind: ai.llm, provider: kimi, ... }
- id: draft.deepseek: { kind: ai.llm, provider: deepseek, ... }
- id: best:
kind: ai.llm
prompt: "Pick best of: {{draft.zai}} {{draft.kimi}} {{draft.deepseek}}"- id: q.embed: { kind: ai.embed, input: question }
- id: matches: { kind: vectorize.search, vector: q.embed, top_k: 5 }
- id: answer: { kind: ai.llm, prompt: "Context: {{matches}}\nQ: {{question}}" }- id: thought: { kind: ai.llm, prompt: "What's next?" }
- id: action: { kind: router, when: thought }
- id: step.advance: { kind: listener, when: "step < 10" }- id: answer.premium: { kind: ai.llm, provider: zai, ... }
- id: answer.cheap: { kind: ai.llm, provider: deepseek, ... }
- id: answer:
kind: router
routes:
- when: "total.cost >= budget"
then: "answer.cheap"
- then: "answer.premium"Cells cache by input hash automatically. Re-setting a cell with the same value is a no-op.
const engine = new AIEngine({
zaiKey?: string,
kimiKey?: string,
deepseekKey?: string,
cloudflareKey?: string,
cloudflareAccountId?: string,
});
engine.registerProvider(name, provider, apiKey?);
engine.setKey(provider, apiKey);
const result = await engine.call(config, {
useCache?: boolean, // default: true
signal?: AbortSignal,
});
engine.getCost(); // total USD spent
engine.getTokens(); // { prompt, completion, total }
engine.getCacheStats();
engine.clearCache();Reads keys from process.env:
ZAI_TOKENKIMI_TOKENDEEPSEEK_TOKENCLOUDFLARE_TOKENCLOUDFLARE_ACCOUNT_ID
Never put API keys in YAML sheets. Sheets are typically committed to git. Quilt refuses to load sheets that contain keys.
The 3 layers:
- Browser (Quilt Live): Calls a proxy URL. Keys never reach the browser.
- Cloudflare Worker: Keys set as Wrangler secrets. Only the Worker has access.
- Server (TS / Rust): Keys read from environment variables.
See the examples/ directory for complete sheets:
01-basic-llm.yaml— single LLM call02-fanout-3models.yaml— 3 models in parallel03-rag.yaml— RAG over a vector store04-agent-loop.yaml— multi-step agent05-cost-control.yaml— budget-aware routing06-image-pipeline.yaml— text → enhanced prompt → image → caption
npm testThe test suite runs 7 unit tests. To run real API tests, set the env vars first.
@superinstance/quilt-ai is one of 13 packages in the Quilt ecosystem:
| Package | Language | Description |
|---|---|---|
| @superinstance/quilt-core | TS | Reactive engine |
| @superinstance/quilt-cli | TS | CLI + MCP server |
| quilt-rust | Rust | Sync + async engine |
| quilt-live | HTML | Single-file, offline |
| quilt-cloudflare | Workers | Edge-native with D1, Vectorize |
| @superinstance/quilt-ai (this) | TS | AI cells: 4 providers, 8 kinds |
| quilt-esp32 | Rust | Microcontroller |
| quilt-mesh | TS | CRDT peer-to-peer |
| quilt-agent | TS | LLM agent sheet |
| quilt-time | TS | Time travel |
| quilt-vault | TS | Encryption |
| quilt-vision | TS | Computer vision |
| quilt-zk | TS | Zero-knowledge proofs |
| quilt-flow | TS | Visual editor |
Quilt is an ecosystem of 15 repos, 5 deployment tiers, 3 languages. This repo is part of:
| Tier | Repo | What it is |
|---|---|---|
| Canonical | quilt | TypeScript core (this ecosystem's home base) |
| Compiled | quilt-rust | Rust port — single static binary, axum, crossterm |
| Browser | quilt-live | Single 70KB HTML file that runs anywhere |
| IoT | quilt-esp32 | no_std Rust for ESP32, sensors + actuators |
| Edge | quilt-cloudflare | Cloudflare Workers + D1 + Vectorize + R2 |
| Codespace | quilt-codespace | GitHub Codespace as a live Quilt runtime |
| AI | quilt-ai | LLM cells across 4 providers (z.ai, Kimi, DeepSeek, Cloudflare) |
| Evolution | quilt-evolve | Self-improvement loops, 4 components, 5 scopes |
| Mesh | quilt-mesh | CRDT-backed cross-tab / cross-device sync |
| Agent | quilt-agent | LLM agent as a sheet — memory, tools, reasoning |
| Time | quilt-time | Time-series cells with rolling windows |
| Vault | quilt-vault | Secrets cells with per-cell ACLs |
| Vision | quilt-vision | Computer-vision cells (camera → scene → caption) |
| ZK | quilt-zk | Zero-knowledge cell verification primitives |
| Flow | quilt-flow | Workflow cells — DAG execution, retry, rollback |
See the Federation landing page for the architecture and the Engineering Bar for what "done right" means across all 15 repos.
MIT