@rikaido/sdk
The SDK
One class, three doors, zero dependencies. It is fetch with the right headers and the right types.
Install
npm
npm install @rikaido/sdkThe package is compiled TypeScript with no dependencies, under Apache-2.0. It runs wherever fetch exists: Node 18+, Bun, Deno, a browser, a worker.
One key, three doors
TypeScript
import { Rikaido } from "@rikaido/sdk";
const rikaido = new Rikaido({ apiKey: process.env.RIKAIDO_KEY! });
// The harness: eight checks, twenty codes, one lock.
const verdict = await rikaido.harness.validate(recipe, { allergies: ["peanut"] });
if (!verdict.safe) throw new Error(verdict.issues[0].message);
// The graph: what an ingredient is made of, and what replaces it.
const peanut = await rikaido.graph.ingredient("peanut butter");
peanut.facts.allergens; // ["peanut"]
// The cast: the kawaii drawing and the 3D toy.
const tomato = await rikaido.art.portrait("tomato");
tomato.kawaiiSvg; // "<svg …"
tomato.toyUrl; // "https://api.rikaido.app/v1/art/ingredients/tomato/toy.webp"What every answer carries
Every answer is the API's object, plus usage.op — the operation that was counted, read off the Rikaido-Usage-Op header. A call that was not counted (a 400, a 404) has none.
usage
const v = await rikaido.harness.validate(recipe);
v.usage.op; // "validate"Errors
Anything that is not a 2xx throws a RikaidoError with status, code when the API gives one, and the API's sentence as message.
errors
import { RikaidoError } from "@rikaido/sdk";
try {
await rikaido.harness.read("https://example.com/recipe");
} catch (err) {
if (err instanceof RikaidoError && err.code === "payment-required") {
// the month's free calls are used
}
}The methods
harness.validate(recipe, constraints?, titleHint?)Verdictharness.read(source, locale?)ReadResultgraph.ingredient(name, { neighbours? })GraphIngredientgraph.search(q, { limit?, locale? }){ matches }art.list(){ count, ingredients }art.portrait(name)Portraitart.toy(name) · art.kawaii(name){ bytes, contentType }The files themselves.
Without the SDK
The SDK has nothing the API does not. Every reference page shows the call in curl; the key travels in Authorization: Bearer, the body as JSON.