Licence
MIT
Version
0.1.2
Deps
0
Size
15 kB
Vulns
0
Weekly
0
@08byte/sdk
Official TypeScript / JavaScript SDK for the 08byte Edge Data Parser & Token Compression API.
npm install @08byte/sdk
Usage
import { Zero8Byte } from "@08byte/sdk";
const client = new Zero8Byte({ apiKey: process.env.ZERO8BYTE_API_KEY! });
// Mode-preset extraction
const news = await client.parse("https://techcrunch.com/article-url", { mode: "news" });
console.log(news.data.headline, news.data.what_happened);
// Custom schema extraction
const product = await client.extract("https://example.com/product/123", {
schema: {
properties: {
title: { type: "string" },
price: { type: "number" },
in_stock: { type: "boolean" },
features: { type: "array" },
},
required: ["title", "price"],
},
});
// Batch parsing (up to 50 URLs per call)
const batch = await client.batchParseAndWait({
urls: ["https://a.example.com", "https://b.example.com"],
mode: "product",
});
console.log(batch.status, batch.results);
// Or fire-and-forget with a webhook instead of polling:
const accepted = await client.batchParse({
urls: ["https://a.example.com", "https://b.example.com"],
webhookUrl: "https://your-server.com/webhooks/08byte",
webhookSecret: "whsec_your_own_secret",
});
Machine-to-Machine x402 Micropayments (Base USDC)
For autonomous agents and developers who want pay-per-call access without pre-funding an API key:
import { Zero8Byte, type X402Challenge } from "@08byte/sdk";
// Option A: Pre-signed X-PAYMENT header
const client = new Zero8Byte({
x402Payment: "eyJ4NDAyVmVyc2lvbiI6MSwic2NoZW1lIjoiZXhhY3QiLC...",
});
const res = await client.parse("https://en.wikipedia.org/wiki/Artificial_intelligence");
// Option B: Dynamic auto-signing callback for 402 challenges
const agentClient = new Zero8Byte({
signPayment: async (challenge: X402Challenge) => {
// Sign the payment challenge using your wallet (e.g. viem, ethers)
// and return the Base64-encoded payment string
return signWithEVMWallet(challenge);
},
});
const data = await agentClient.parse("https://news.ycombinator.com");
Verifying inbound batch webhooks
import { verifyWebhookSignature } from "@08byte/sdk";
// req.rawBody MUST be the exact bytes received — not a re-serialized
// JSON.parse(...) round-trip — or the signature will never match.
const valid = verifyWebhookSignature(
req.rawBody,
req.headers["x-08byte-signature"],
process.env.ZERO8BYTE_WEBHOOK_SECRET!
);
Error handling
Every non-2xx response throws Zero8ByteError (.status, .code, .message):
import { Zero8ByteError } from "@08byte/sdk";
try {
await client.parse("http://169.254.169.254/");
} catch (err) {
if (err instanceof Zero8ByteError) {
console.log(err.status, err.code); // 422 "INVALID_URL"
}
}
Requirements
Node.js >= 18 (needs global fetch and node:crypto's timingSafeEqual).