Recipe

Deno Server Primer

Ship a Meridian-powered Deno HTTP server in under five minutes. This recipe walks you through bootstrapping a zero-config endpoint, wiring it to the Meridian model router, and streaming completions back to your client without bundlers or package managers.

1.Bootstrap the runtime

Deno ships with native TypeScript and a built-in HTTP server. No package.json, no node_modules. Save the snippet below as server.ts and run it with deno run --allow-net --allow-env server.ts.

Deno.serve({ port: 8000 }, (req) => {
  const url = new URL(req.url);
  if (url.pathname === "/health") {
    return new Response("ok", { status: 200 });
  }
  return new Response("Meridian Deno primer", {
    headers: { "content-type": "text/plain" },
  });
});

2.Call the Meridian gateway

Point your fetch at https://llm.getnimbus.net/v1/chat/completions with your Meridian key in the Authorization header. The gateway speaks the OpenAI wire format so you can reuse any existing SDK helpers without modification.

const res = await fetch(
  "https://llm.getnimbus.net/v1/chat/completions",
  {
    method: "POST",
    headers: {
      "authorization": "Bearer " + Deno.env.get("MERIDIAN_KEY"),
      "content-type": "application/json",
    },
    body: JSON.stringify({
      model: "azure/model-router",
      messages: [{ role: "user", content: "Hello" }],
    }),
  },
);
const data = await res.json();

3.Stream tokens to the client

Pass stream: true in the request body and pipe the response body straight back to the browser. Deno's native ReadableStream handles backpressure for you, so a single server handler can fan out to thousands of concurrent listeners without buffering.

Deno.serve(async (req) => {
  const upstream = await fetch(MERIDIAN_URL, {
    method: "POST",
    headers: AUTH_HEADERS,
    body: JSON.stringify({ ...payload, stream: true }),
  });
  return new Response(upstream.body, {
    headers: { "content-type": "text/event-stream" },
  });
});