Set up the inference shell proxy with Hono for edge and serverless deployments.
Installation
1npm install @inferencesh/sdk honoBasic Setup
1import { Hono } from "hono";2import { createHandler } from "@inferencesh/sdk/proxy/hono";34const app = new Hono();5const proxyHandler = createHandler({6 allowedEndpoints: ["my-team/*"],7 isAuthenticated: async (c) => Boolean(await getSession(c)), // your session check8});910app.all("/api/inference/proxy", proxyHandler);1112export default app;The proxy forwards app runs and agent chats only; allowedEndpoints limits them to your apps and agents, and isAuthenticated gets the Hono Context. See options.
[!WARNING] Anyone who can reach the proxy route runs apps and agents on your API key. In production set
allowedEndpointsandisAuthenticated(see what the proxy forwards), and create a Run only key in a workspace that holds nothing else.
Environment Variable
Set your API key in your runtime environment:
1# Cloudflare Workers (wrangler.toml)2[vars]3INFERENCE_API_KEY = "inf_your_key_here"1# Deno Deploy2export INFERENCE_API_KEY="inf_your_key_here"Cloudflare Workers
1// src/index.ts2import { Hono } from "hono";3import { createHandler } from "@inferencesh/sdk/proxy/hono";45const app = new Hono();67const proxyHandler = createHandler({ allowedEndpoints: ["my-team/*"] });8app.all("/api/inference/proxy", proxyHandler);910export default app;Deploy:
1npx wrangler deployDeno Deploy
1// main.ts2import { Hono } from "https://deno.land/x/hono/mod.ts";3import { createHandler } from "@inferencesh/sdk/proxy/hono";45const app = new Hono();6const proxyHandler = createHandler({ allowedEndpoints: ["my-team/*"] });78app.all("/api/inference/proxy", proxyHandler);910Deno.serve(app.fetch);Client Configuration
1import { inference } from "@inferencesh/sdk";23const client = inference({4 proxyUrl: "https://my-worker.workers.dev/api/inference/proxy"5});67const result = await client.run({8 app: "infsh/flux",9 input: { prompt: "A sunset" }10});Custom API Key Resolution
Load from KV, secrets manager, or other sources:
1import { createHandler } from "@inferencesh/sdk/proxy/hono";23const proxyHandler = createHandler({4 resolveApiKey: async () => {5 // Load from Cloudflare KV, D1, or external service6 const key = await env.SECRETS.get("INFERENCE_API_KEY");7 return key;8 }9});With Middleware
1import { Hono } from "hono";2import { cors } from "hono/cors";3import { rateLimiter } from "hono-rate-limiter";4import { createHandler } from "@inferencesh/sdk/proxy/hono";56const app = new Hono();78// CORS9app.use("/api/*", cors({10 origin: "https://myapp.com",11 allowHeaders: ["Content-Type", "x-inf-target-url"],12}));1314// Rate limiting15app.use("/api/*", rateLimiter({16 windowMs: 15 * 60 * 1000,17 limit: 100,18}));1920// Proxy21const proxyHandler = createHandler({ allowedEndpoints: ["my-team/*"] });22app.all("/api/inference/proxy", proxyHandler);2324export default app;Why Hono?
Hono is ideal for:
- Edge deployments (Cloudflare Workers, Vercel Edge)
- Minimal bundle size (~12kb)
- Fast cold starts for serverless
- Multi-runtime support (Node, Deno, Bun, Workers)