On this page

TypeScript SDK

Typed generation, durable jobs, presets, keys, usage and cancellation.

The workspace package @shaderweave/sdk supports Node and browser clients. Keep bearer secrets on your server; the local web app uses the same-origin gateway.

Generate and cancel

import { ShaderWeave } from '@shaderweave/sdk';
const client = new ShaderWeave({ baseUrl: '/v1' });
const controller = new AbortController();
const response = await client.generate('marble-vein', {
  seed: 7, format: 'webp',
  size: { width: 800, height: 800, pixelRatio: 2 },
}, { signal: controller.signal });
const blob = await response.blob();
// controller.abort() cancels an in-flight request.

Every network method accepts a final { signal } option. generateBytes returns a Uint8Array in either environment. generateBuffer is Node-only.

Jobs

const job = await client.jobs.create({
  generator: 'shader-gradient',
  params: { loopSeconds: 6 },
  format: 'mp4',
  size: { width: 640, height: 360 },
});
const progress = await client.jobs.get(job.id);
const history = await client.jobs.list();
if (progress.resultReady) {
  const file = await client.jobs.result(job.id);
}
// await client.jobs.cancel(job.id);

Aborting a polling request stops that request. Use jobs.cancel to cancel the persisted export itself.

Presets and account

const saved = await client.presets.create({
  name: 'New study', generator: 'mesh-gradient', params: {}, seed: 42,
  size: { width: 1080, height: 1920, pixelRatio: 1 }, format: 'png',
});
await client.presets.update(saved.id, { name: 'Portrait study' });
const presets = await client.presets.list();
const preset = await client.presets.get(saved.id);
await client.presets.delete(saved.id);

const key = await client.keys.create('CI');
const keys = await client.keys.list();
await client.keys.revoke(key.id);
const usage = await client.usage();

Discovery and batches

client.health(), client.ready() and client.generators.list() expose system metadata. client.batch(items) returns per-item success, hash and byte count, or an error code.

Recipe URLs

client.recipeUrl(recipe, format, size) uses browser-safe UTF-8 base64url encoding. Obtain the engine version from discovery/health or import ENGINE_VERSION from the engine package.

Recipe image URLs require an authenticated same-origin gateway. For direct authenticated access, use client.renderRecipe(recipe, format, size) and display the returned blob.

Errors

Failures throw ShaderWeaveError with status, body and a readable message. Non-JSON error responses are retained as text without trying to consume the response twice.