Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.edgespark.dev/llms.txt

Use this file to discover all available pages before exploring further.

EdgeSpark exposes two public SDK surfaces:
  • the server runtime imports from edgespark and edgespark/http
  • the browser SDK from @edgespark/web
This page starts with the server runtime imports, then links to the browser SDK reference.

Main runtime imports

server/src/index.ts
import { ctx, db, secret, storage, vars } from "edgespark";
import { auth } from "edgespark/http";
These imports are typed from generated declarations in server/src/__generated__/.

Import contract

The public server runtime import contract is:
import { ctx, db, secret, storage, vars } from "edgespark";
import { auth } from "edgespark/http";
That is the contract AI coding agents should rely on in app code. Do not invent your own runtime client factory for server handlers.

Example server route

server/src/index.ts
import { db, secret } from "edgespark";
import { auth } from "edgespark/http";
import { eq } from "drizzle-orm";
import { Hono } from "hono";
import { posts } from "@defs";

const app = new Hono().get("/api/posts/:id", async (c) => {
  const stripeKey = secret.get("STRIPE_SECRET_KEY");
  const [post] = await db.select().from(posts).where(eq(posts.id, Number(c.req.param("id"))));

  return c.json({
    post,
    userEmail: auth.user.email,
    hasStripeKey: Boolean(stripeKey),
  });
});

export default app;

Modules

web

The browser SDK for auth, managed auth UI, and same-origin API calls.

db

Query your D1 database with Drizzle ORM.

auth

Access the current user and session.

storage

Upload, download, and manage files in R2.

secret

Read encrypted secrets by name.

vars

Read plain runtime variables by key.

ctx

Use ctx for request-scoped helpers:
server/src/index.ts
import { ctx } from "edgespark";
import { Hono } from "hono";

async function sendToAnalytics(event: unknown) {
  await fetch("https://example.com/analytics", {
    method: "POST",
    body: JSON.stringify(event),
  });
}

const app = new Hono().post("/api/events", async (c) => {
  const event = await c.req.json();

  ctx.runInBackground(sendToAnalytics(event));

  return c.json({
    received: true,
    environment: ctx.environment,
  });
});

export default app;

Generated types

Run edgespark pull types to refresh the generated declarations for edgespark imports. Run edgespark pull types --check to detect stale types in CI or before deploy.

See also

The client object

Conceptual overview of the runtime SDK and how it is injected per request.

Project structure

Where generated files and repo-authored defs live in the scaffold.
Last modified on April 7, 2026