TypeScript SDK#

Client for the Rustbox judge API for Node 20+ and Bun. Uses the platform fetch, no runtime dependencies.

Install#

bun add rustbox

Quickstart#

import { Rustbox } from "rustbox";

const client = new Rustbox(process.env.RUSTBOX_API_KEY ?? "");
const execution = await client.run("python", "print(6 * 7)");
if (execution.result.verdict === "AC") console.log(execution.output.stdout);

run returns an Execution once the run has finished: status, result.verdict, result.exitCode, output.stdout, output.stderr, metrics and evidence. Missing values are ABSENT (null).

Judge against test cases#

const judged = await client.judge("python", "a, b = map(int, input().split())\nprint(a + b)", [
  { stdin: "1 2", expected: "3" },
  { stdin: "2 2", expected: "4" },
]);
console.log(judged.allPassed, judged.results.map((r) => r.verdict));

Queue now, read later#

const accepted = await client.submit("python", "print(1)", "", crypto.randomUUID());
const execution = await client.getResult(accepted.id);

With an idempotency key the submit is retried on transient failures; without one it is sent once.

Errors#

import {
  RustboxApiError,
  RustboxAuthError,
  RustboxRateLimitError,
  RustboxServerError,
  RustboxStillRunningError,
  RustboxTimeoutError,
} from "rustbox";

try {
  await client.run("python", "...");
} catch (error) {
  if (error instanceof RustboxAuthError) {
    // 401/403: check the API key
  } else if (error instanceof RustboxRateLimitError) {
    // 429: wait error.retryAfterSecs
  } else if (error instanceof RustboxServerError) {
    // 5xx after the SDK's retries
  } else if (error instanceof RustboxTimeoutError) {
    // a request timed out
  } else if (error instanceof RustboxStillRunningError) {
    // run used up its polling budget: getResult(error.runId) later
  } else if (error instanceof RustboxApiError) {
    // other 4xx: error.status, error.detail
  }
}

Every error extends RustboxError; RustboxConfigError, RustboxTransportError and RustboxDecodeError complete the set.

Configuration#

Options are a complete RustboxOptions object. Start from DEFAULT_OPTIONS and override what you need.

import { DEFAULT_OPTIONS, Rustbox } from "rustbox";

const client = new Rustbox(apiKey, { ...DEFAULT_OPTIONS, region: "in", timeoutSecs: 30 });

baseUrl pins an exact endpoint. RUSTBOX_BASE_URL and RUSTBOX_REGION are read when the options leave them ABSENT.

Server only#

Calling Rustbox from a browser would expose your API key. Call it from your server.

Source#

github.com/orkait/rustbox-sdk/typescript