RECIPE

Bun server primer

Spin up a production-grade Bun HTTP server that proxies Meridian inference requests in under twenty lines. This recipe walks through the minimal handler, streaming response forwarding, and a single-process deploy with zero Node dependencies.

1.Install Bun and bootstrap the project

Bun ships as a single binary. Install it once, initialize an empty project, and add your Meridian gateway key as an environment variable. No package.json edits are required for the smallest case.

curl -fsSL https://bun.sh/install | bash
bun init -y
export MERIDIAN_KEY=sk_live_...

2.Write the handler in server.ts

Bun.serve takes a fetch handler and binds to a port. The body below accepts JSON payloads, forwards them to the Meridian gateway, and streams the response back to the caller without buffering.

Bun.serve({
  port: 3000,
  async fetch(req) {
    if (req.method !== 'POST') {
      return new Response('Method Not Allowed', { status: 405 });
    }
    const body = await req.text();
    const upstream = await fetch('https://llm.getnimbus.net/v1/chat/completions', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + process.env.MERIDIAN_KEY,
      },
      body,
    });
    return new Response(upstream.body, {
      status: upstream.status,
      headers: { 'Content-Type': 'application/json' },
    });
  },
});

3.Run, test, and deploy

Bun runs TypeScript natively, so there is no build step. Launch the server, hit it with curl, and ship the same file behind a reverse proxy or a container. The cold start is under fifty milliseconds on a modest VPS.

bun run server.ts
curl -X POST http://localhost:3000 \
  -H 'Content-Type: application/json' \
  -d '{"model":"azure/model-router","messages":[{"role":"user","content":"hi"}]}'