Swift on the Server with Hummingbird
A series on server-side Swift with the Hummingbird framework — from the first route to a deployable LLM gateway on Linux.
We are building an OpenAI-compatible LLM gateway in Swift with the Hummingbird framework. The gateway runs against a local MLX model on Apple Silicon and deploys as a fully statically linked binary on Linux — with streaming, API-key auth, rate limiting, Prometheus metrics, and distributed tracing. The demo project is swift-mlx-gateway on Codeberg, with a Git tag per article to follow along. Six articles plus the prologue.
- 0
Swift on the Server — Hummingbird 2 and a Local LLM Gateway
Prologue · Series: Swift on the Server with Hummingbird. Why Swift on the server is no longer a hobby project in 2026, how Hummingbird differs from Vapor and why we chose a local LLM gateway as our demo project.13. May 2026 - 1
Hello Hummingbird — The Skeleton
Article 1 · Swift on the Server with Hummingbird. We create the project, write Package.swift, set up the AsyncParsableCommand entry point, and build a minimal router with /healthz and /v1/models until curl gets an answer.14. May 2026 - 2
Two Protocols, One Backend — Anthropic and OpenAI with Codable
Article 2 of the Hummingbird series. We implement the Anthropic Messages API and the OpenAI Chat Completions API in the same gateway: Codable types for both protocols, two POST endpoints, input validation, mock inference.15. May 2026 - 3
Real Inference — MLXClient and the Local Model
Article 3 of the Hummingbird series. We connect the gateway to mlx_lm.server: MLXClient as a Swift actor, format conversion from Anthropic to OpenAI, error mapping with HTTP status codes. After this article, the gateway delivers real model responses.15. May 2026 - 4
Streaming — Tokens Flow as They Are Born
Article 4 of the Hummingbird series. We add streaming to both endpoints via Server-Sent Events: MLXClient.completeStream as AsyncThrowingStream, Anthropic events, OpenAI chunks, task cancellation. Tokens appear at the client as the model generates them.16. May 2026 - 5
Auth and RequestContext — Closing the Gate
Article 5 of the Hummingbird series. We add API key auth, token-bucket rate limiting, and spec-compliant error responses — using Hummingbird 2's generic RequestContext to carry typed middleware state without dictionaries.17. May 2026 - 6
Observability and Linux Deployment — From swift run to systemd
Article 6 of the Hummingbird series. We add Prometheus metrics via swift-metrics and swift-prometheus, a /metrics endpoint, MetricsMiddleware and TracingMiddleware. Plus: cross-compiling to a statically linked Linux binary via the Swift Static Linux SDK, a multi-stage Dockerfile, and a systemd unit for bare-metal Linux deployment.19. May 2026 - 7
Benchmarks — Hummingbird against FastAPI and Fastify
Article 7 of the Hummingbird series. We measure the LLM gateway against functionally equivalent implementations in FastAPI and Fastify — with a fair middleware stack, a deterministic backend stub, and oha as the load generator. The results are both what you expect and somewhat surprising.20. May 2026