@frayme/api
v0.1.2
Published
Frayme API client — zero-dependency, fetch-based, streaming generative-UI compose for Node, edge, Bun, Deno, and Workers.
Readme
@frayme/api
The official TypeScript client for the Frayme generative-UI API. Zero dependencies, fetch-based — runs on Node ≥ 20.19, Bun, Deno, Cloudflare Workers, and Vercel Edge.
npm i @frayme/apiimport Frayme from '@frayme/api';
const frayme = new Frayme({ apiKey: process.env.FRAYME_API_KEY });
const stream = frayme.compose.stream({ prompt: 'A pricing page with three tiers' });
stream.on('op', (op, snapshot) => render(snapshot)); // live spec snapshots
stream.on('restarted', () => clearRendered()); // attempt failed → discard & keep listening
const { spec, model } = await stream.finalSpec(); // validated final specRender spec with @frayme/runtime.
What you get
- Two streaming layers —
compose.stream()(handlers + async iteration + snapshot accumulation +finalSpec()+.abort()) orcompose.create({ stream: true })for a raw typed-event iterable. Non-streaming:compose.create({ stream: false }). compose.restartedhandled for you — Frayme validates every generation; when an attempt fails, the stream restarts with a stronger model in the same response. The SDK resets its snapshot and tells you to discard.- Retries that can't double-bill — 2 automatic retries (connection errors, 408/409/429/5xx) with jittered backoff and
Retry-Aftersupport; one auto-generatedIdempotency-Keyper logical call is reused across attempts, so a retried success replays instead of re-billing. - Typed errors —
RateLimitError(with.retryAfter),QuotaExceededError,PaymentRequiredError,CompositionFailedError, … all extendingFraymeErrorwith.status/.code/.requestId. - Browser-safe by design — constructing with a key in a browser throws. Use keyless proxy mode instead:
new Frayme({ apiKey: null, baseURL: '/api/your-proxy' }).
Agent tool (all frameworks, one definition)
import { composeToolDefinition, createComposeTool } from '@frayme/api/tools';
// Vercel AI SDK 6: tool({ ...createComposeTool(frayme) })
// Mastra: createTool({ ...createComposeTool(frayme) })
// OpenAI Agents SDK (JS): tool({ name, description, parameters: composeToolDefinition.inputSchema, execute })
// LangChain.js: tool(execute, { schema: composeToolDefinition.inputSchema, ... })The schema is Zod v4 (Standard Schema), so every major framework accepts it natively. Recipes: frayme.ai/examples.
API
frayme.compose.stream(req, opts?) · frayme.compose.create(req, opts?) · frayme.me() · frayme.health()
Full wire contract (for other languages): OpenAPI 3.1.
MIT © Orange Stack Ltd
