whatisgithub

What is nano-llm-gateway?

reezanahamed/nano-llm-gateway — explained in plain English

Analysis updated 2026-05-18

0PythonAudience · developerComplexity · 2/5LicenseSetup · easy

In one sentence

A single readable 300-line Python file that shows how LLM gateways route one API key to Claude, GPT, Gemini, or DeepSeek with failover and cost tracking.

Mindmap

mindmap
  root((nano-llm-gateway))
    What it does
      One key for many providers
      OpenAI-compatible API
      Auto failover
      Live cost tracking
    Tech stack
      Python
      requests library
      OpenAI SDK format
    Use cases
      Learn how gateways work
      Prototype a mini gateway
      Compare provider answers side by side
    Audience
      Developers learning AI infra
      Students of LLM tooling
    Limitations
      No streaming
      No retries or queueing
      Hardcoded prices
      Not for production

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Learn how LLM gateways translate requests between different AI providers.

USE CASE 2

Run a tiny local gateway that lets any OpenAI-style app call Claude, GPT, or Gemini with one key.

USE CASE 3

Compare answers from multiple AI models side by side using the included demo script.

What is it built with?

PythonOpenAI SDKrequests

How does it compare?

reezanahamed/nano-llm-gateway0xallam/my-recipe0xhassaan/nn-from-scratch
Stars00
LanguagePythonPythonPython
Last pushed2022-11-22
MaintenanceDormant
Setup difficultyeasymoderatemoderate
Complexity2/52/54/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Just needs one existing provider API key and one pip dependency.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

So what is it?

This project is a small, deliberately simple example of how an LLM gateway works. In plain terms, an LLM gateway is a piece of software that sits between your app and multiple AI providers like Claude, GPT, Gemini, or DeepSeek, so your app only needs one key instead of juggling a separate key and format for each provider. Popular gateways such as LiteLLM or OpenRouter do this at large scale, but their codebases are big and hard to learn from. This project packs the same core idea into a single Python file of about 300 lines, meant to be read from top to bottom rather than deployed to production. Once running, the gateway starts a local server, and any tool built to talk to OpenAI's API can point at it instead, just by changing one setting. Behind the scenes it looks at the model name in the request, figures out which provider that model belongs to, and translates the request into that provider's own format, then translates the answer back into the common format your app expects. If a provider call fails, it automatically tries the next one on a fallback list. It also tracks how many tokens each request used and calculates the cost in dollars for every call, using a built in price table. Getting started involves cloning the repository, installing one dependency, copying an example environment file and adding at least one API key you already have, then running the gateway script, which starts a local server you leave running. A separate demo script then sends the same question to several providers side by side so you can compare their answers. The author is upfront about what this project is not. It has no streaming responses, no rate limiting, no retry logic, and no request queueing. Its price table is hardcoded, so costs shown may go stale as providers change pricing, and everything runs in a single process with nothing saved between runs. It is meant purely to teach how a gateway works. For actual production use, the README points readers toward LiteLLM instead. The project is released under the MIT license.

Copy-paste prompts

Prompt 1
Walk me through gateway.py line by line and explain how it translates an OpenAI-style request into Claude's format.
Prompt 2
Help me add a new LLM provider to nano-llm-gateway the way DeepSeek was added.
Prompt 3
Set up nano-llm-gateway locally with my own API keys and run the demo comparing providers.
Prompt 4
Explain how the cost tracking in this gateway calculates dollars from token counts.

Frequently asked questions

What is nano-llm-gateway?

A single readable 300-line Python file that shows how LLM gateways route one API key to Claude, GPT, Gemini, or DeepSeek with failover and cost tracking.

What language is nano-llm-gateway written in?

Mainly Python. The stack also includes Python, OpenAI SDK, requests.

What license does nano-llm-gateway use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is nano-llm-gateway to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is nano-llm-gateway for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.