briqbriq
SDK

TypeScript SDK

@briq/sdk, a typed client generated from the OpenAPI spec.

@briq/sdk is generated from /v1/openapi.json with openapi-typescript and wrapped in a thin fetch client. Types match the API exactly, because both come from the same Zod schemas. A Python SDK generated from the same spec follows in v1.

Install

pnpm add @briq/sdk

Node 20+, or any runtime with fetch.

Run a recipe

import { Briq } from '@briq/sdk';

const briq = new Briq(process.env.BRIQ_API_KEY);

const db = await briq.run({ recipe: 'postgres', params: { version: '16' } });
console.log(db.outputs.DATABASE_URL);
console.log(db.costCentsSoFar, db.stopsAt);

await briq.destroy(db.id);

run waits for readiness by default (wait: true). Pass wait: false to get the creating briq back immediately and poll with status.

Run an image

const api = await briq.run({
  image: 'ghcr.io/acme/api:pr-412',
  stack: 'checkout',
  env: { DATABASE_URL: db.outputs.DATABASE_URL, NODE_ENV: 'test' },
  ports: [3000],
  size: 'small',
  ttlMinutes: 30,
});

const { url } = await briq.expose(api.id, { port: 3000, mode: 'token' });

Exec, logs, files

const result = await briq.exec(db.id, ['psql', '-U', 'postgres', '-c', 'select 1']);
// result.stdout, result.stderr, result.exitCode

for await (const line of briq.logs(db.id, { follow: true })) {
  process.stdout.write(line);
}

await briq.files.put(db.id, '/seed.sql', Buffer.from('insert into …'));
const file = await briq.files.get(db.id, '/var/log/postgresql/postgresql.log');

Lifecycle

await briq.stop(db.id);
await briq.start(db.id);
await briq.extend(db.id, { minutes: 30 });
await briq.destroy(db.id);

const running = await briq.list({ stack: 'checkout' });
const quota = await briq.quota(); // remaining spend, concurrency, allowed sizes
const recipes = await briq.recipes();

Errors

Every non-2xx response throws a BriqError with code, message, status and optional details, mirroring the REST error shape:

import { BriqError } from '@briq/sdk';

try {
  await briq.run({ recipe: 'postgres', size: 'large' });
} catch (e) {
  if (e instanceof BriqError && e.code === 'policy_violation') {
    // pick a smaller size or ask for a wider key
  }
}

Configuration

new Briq(apiKey, {
  baseUrl: 'https://api.briq.run/v1', // default
  fetch: customFetch, // optional, for proxies and tests
});

Use a bq_test_… key against the mock provider to run your own test suite without creating machines.