Skip to content

TypeScript SDK

For Node tools, txAdmin-adjacent services, and the JS/TS server side of FiveM resources (the spawnbase resource’s server is built on it).

import { create } from "@spawnbase/sdk";
const sdk = create({
apiUrl: "https://api.spawnbase.gg", // default
mediaKey: process.env.SPAWNBASE_MEDIA_KEY,
logsKey: process.env.SPAWNBASE_LOGS_KEY,
// version: "v1", // "v3" only for a Fivemanage-shaped backend
});

Keys are server-side secrets. Never embed them in a client or NUI page — mint a presigned URL instead.

// Direct upload (multipart) — returns { id, url, originalUrl? }
const file = await sdk.media.upload(bytes, {
fileName: "clip.mp4",
metadata: { name: "Dashcam" },
});
// Base64 upload
const via64 = await sdk.media.upload64(base64Png, { fileName: "a.png" });
// Server: mint a one-time URL (safe to hand to a client)
const url = await sdk.media.presign("image");
// Anywhere: upload through it. No Authorization header is sent —
// the SDK uses a key-less client for this call on purpose.
const stored = await sdk.media.send(url, bytes, { fileName: "shot.jpg" });
console.log(stored.url);

Buffered per dataset and flushed in batches (500 entries / 512 KB / 5s by default); a failed flush retries once, then drops with a console error — log calls never throw into your code.

sdk.logs.info("economy", "Purchase", { playerSource: 1, action: "buy" });
sdk.logs.error("core", "Save failed", { error: "db locked" });
sdk.logs.tune({ level: "debug" }); // level floor, batch size, echo…
await sdk.logs.flush(); // send everything now
await sdk.logs.close(); // flush + finish (call on shutdown)
const session = sdk.session("203.0.113.10:30120"); // your server endpoint
await session.open(); // authorize + heartbeat at half the token TTL
await session.beat(); // refresh manually
await session.close(); // terminate

Sessions follow the upstream /api/sdk/* shape; those routes are not live on Spawnbase yet, and open() failing never affects media or logs.

API failures throw an Error carrying the API’s message (except where an export documents a null return, like the FiveM resource’s uploadImage). Replies are validated against the contract on arrival — a malformed response throws instead of passing bad data along.