Back to docs
RECIPE

Hono primer

Hono is a tiny, ultra-fast web framework built for edge runtimes. This primer walks through wiring a Hono server in front of Meridian so you can stream completions, proxy tool calls, and ship a chat endpoint in under fifty lines of TypeScript.

1.Install and bootstrap

Hono ships as a single dependency with zero runtime overhead. Pick the adapter that matches your deploy target — Cloudflare Workers, Bun, Deno, or Node — and Hono will tree-shake everything else away.

npm install hono
npm install @hono/node-server

2.Wire a Meridian completion route

Forward the request body straight to Meridian’s OpenAI-compatible endpoint. Hono’s context object gives you a streaming Response without any middleware glue.

import { Hono } from 'hono';

const app = new Hono();

app.post('/chat', async (c) => {
  const body = await c.req.json();
  const upstream = await fetch(
    'https://llm.getnimbus.net/v1/chat/completions',
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${c.env.MERIDIAN_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
    },
  );
  return new Response(upstream.body, {
    headers: { 'Content-Type': 'text/event-stream' },
  });
});

export default app;

3.Add auth and rate limiting

Hono’s middleware chain composes like a Koa app. Drop in bearer auth, a per-IP throttle, and a CORS allowlist before your handler runs. Meridian charges by token, so cap unauthenticated traffic hard at the edge.

  • Use hono/bearer-auth for the simplest API-key gate.
  • Pair hono/cors with an origin allowlist for browser callers.
  • Cache the Meridian model list with hono/cache — it rarely changes.