Snippets JavaScript SDK
Create pastes and read them back as raw text from Node and TypeScript with the hepgg package.
Snippets SDK
The hepgg package wraps the Snippets API in a typed client. Create a paste, get its URL, read the raw bytes back. The class is named Paste and lives on the hepgg/paste subpath (the app is "Snippets", the client is the paste client).
Install
Create And Read
import { Paste, Visibility } from "hepgg/paste";
const paste = new Paste({ token: process.env.PASTE_KEY });
const { id, url } = await paste.create({
content: 'console.log("hi")',
language: "javascript",
title: "snippet",
visibility: Visibility.Unlisted,
});
console.log(url); // https://paste.hep.gg/<id>
console.log(await paste.raw(id)); // 'console.log("hi")'create() returns { id, url, expiresAt, anonymous }. Reading is auth-free for public and unlisted pastes.
Helpers
paste.raw(id); // raw text (GET /<id>/raw)
paste.read(id); // alias of raw
paste.url(id); // https://paste.hep.gg/<id>
paste.rawUrl(id); // https://paste.hep.gg/<id>/rawOptions And Errors
paste.create(input)
contentstringrequired
The paste body. Non-empty.
titlestringoptional
Optional title (trimmed to 200 chars).
languagestringoptional
Syntax language. Omit for auto-detect.
visibilityVisibilityoptionaldefault:
publicpublic, unlisted, or private. Private needs a session, not a key.isPermanentbooleanoptionaldefault:
falsePrime only. Never expire.
Empty content throws a TypeError before any request. API failures throw a typed HepError (for example 413 when over your plan cap). The constructor also takes baseURL, timeoutMs, retries, and fetch.
import { HepError } from "hepgg";
try {
await paste.create({ content: code });
} catch (err) {
if (err instanceof HepError && err.status === 429) console.error("paste cap reached");
}