omnistream-connect
v0.1.0
Published
Add OmniStream to your own API or SDK in a few lines. Validate Omni keys and meter usage.
Maintainers
Readme
@omnistream/connect
Add OmniStream to your own API or SDK in a few lines. Your consumers authenticate with their single Omni key; this validates it against OmniStream (and meters usage) without routing your traffic through the proxy.
npm install @omnistream/connectExpress
import express from "express";
import { omniExpress } from "@omnistream/connect";
const app = express();
app.use(omniExpress({ apiSlug: "my-api" }));
app.get("/things", (req, res) => {
// req.omni = { valid: true, plan: "pro" }
res.json({ things: [] });
});Next.js route handler (or any framework)
import { verifyRequest } from "@omnistream/connect";
export async function GET(req: Request) {
const result = await verifyRequest(req.headers, { apiSlug: "my-api" });
if (!result.valid) return new Response("Unauthorized", { status: 401 });
return Response.json({ ok: true, plan: result.plan });
}Inside your own SDK
import { verifyKey } from "@omnistream/connect";
const { valid, plan } = await verifyKey(userKey, { apiSlug: "my-api" });Self-hosting the Grid? Pass gatewayUrl. Verification responses are cached for 30s by default
(cacheTtlMs).
