- LiteLLM: An open-source AI gateway that puts more than a hundred model providers behind one OpenAI-format interface. Here its Router groups deployments by pipeline step, retries and falls back between them, and reports the cost of every call from its built-in model cost map, including ZeroGPUβs native
zerogpu/route. - ZeroGPU: A compute-efficient inference provider for apps and agents. We run purpose-built small and nano language models across an edge network for the high-volume tasks you run constantly - classification, extraction, moderation, routing, summarization - at ~10x lower latency and 50%+ lower cost than frontier-model workflows. Auto-scaling, with zero GPU infrastructure to manage. Plug in and youβre live.
- OpenAI: A leading provider of advanced AI models capable of natural language understanding, contextual reasoning, and content generation. It enables intelligent, human-like interactions and supports a wide range of applications across various domains.
π₯ Watch the Video Guide
Video walkthrough coming soon.π¦ Installation
First, install the LiteLLM package with all its dependencies:zerogpu/ provider route that points at ZeroGPUβs OpenAI-compatible endpoint at https://api.zerogpu.ai/v1. See the LiteLLM integration guide for every option the route supports.
π Setting Up API Keys
Youβll need to set up your API keys for ZeroGPU and OpenAI. This ensures that the tools can interact with external services securely. You can go to here to get an API key and Project ID from ZeroGPU. The key starts withzgpu-api- and the Project ID (UUID) is on the project settings page.
Python
Python
ZEROGPU_API_KEY and OPENAI_API_KEY from the environment automatically. The Project ID travels as an x-project-id header, which youβll attach to each ZeroGPU deployment in the Router below.
π Access Text Generation with ZeroGPU
ZeroGPU is a compute-efficient inference provider for apps and agents. We run purpose-built small and nano language models across an edge network for the high-volume tasks you run constantly - classification, extraction, moderation, routing, summarization - at ~10x lower latency and 50%+ lower cost than frontier-model workflows. Auto-scaling, with zero GPU infrastructure to manage. Plug in and youβre live. In this section, we will make a singlezerogpu/ call through LiteLLM and read its cost straight off the response.
Python
zerogpu/ route, with the cost of the call already computed, providing a drop-in, spend-aware model provider for AI integration!
π§ Building the Lead Desk Router
Each step of the pipeline gets its own Router model group, backed by the cheapest ZeroGPU model that can do that step well, with GPT-4.1 as both the escalation target and the safety net.Python
qualify runs on a fast 8B model, extract on gpt-6-luna for strict JSON, draft on the reasoning model gpt-oss-120b, and frontier on GPT-4.1:
Python
json_schema output is the backbone of the first two steps:
Python
π§Ύ Tracking Spend with a Cost Ledger
Every Router call goes through one helper that records which model actually answered, the tokens it used, what it cost, and what the same tokens would have cost on GPT-4.1.Python
π₯ The Inbound Leads
Here are six submissions from a βContact salesβ form, the kind of mix every real inbox gets: a big enterprise deal, a tiny agency, a customer who used the wrong form, a spammer, a reseller, and a mid-market evaluation.Python
π― Step 1: Qualify Every Lead
Thequalify group reads each lead and returns three enums under a strict schema, so the code branches on fields rather than parsing prose.
Python
π Step 2: Extract the CRM Fields
For leads worth pursuing, theextract group pulls out the fields a CRM record needs. Nullable types let the model say βnot statedβ instead of guessing.
Python
βοΈ Step 3: Draft the First-Touch Reply
The reply step is where routing judgment pays off: a hot enterprise deal is worth frontier tokens, while everything else drafts perfectly well on ZeroGPU.Python
πΈ Reading the Cost Ledger
Now, letβs see what the whole run cost, call by call, next to what the same tokens would have cost if every step had run on GPT-4.1:Python
π‘οΈ Testing the Safety Net
Fallbacks only matter if they work when ZeroGPU, the network, or a deployment has a bad minute. LiteLLM can simulate a failure so you can prove the path end to end. Passmock_testing_fallbacks=True and the Router fails the primary deployment on purpose, then walks the fallbacks list:
Python
reasoning_effort was quietly dropped for GPT-4.1 thanks to litellm.drop_params, and the higher cost shows up in the same place as every other call, so a spike in fallback traffic is visible the moment it starts.
π You just ran a full inbound lead desk through one LiteLLM Router: thirteen of fourteen calls ran on ZeroGPUβs small models, the only frontier call went to the deal that justified it, and the whole batch cost about a sixth of the all-GPT-4.1 baseline, with fallbacks proven to keep replies flowing if a ZeroGPU step fails. The costs above come from LiteLLMβs cost map; the authoritative charges are on your own ZeroGPU dashboard and OpenAI account.
π Highlights
This notebook has guided you through setting up and running a LiteLLM workflow with ZeroGPU for qualifying, enriching, and answering inbound sales leads. You can adapt and expand this example for various other scenarios requiring cost-aware, multi-step LLM pipelines with structured outputs and a frontier-model safety net. Key tools utilized in this notebook include:- LiteLLM: An open-source AI gateway that puts more than a hundred model providers behind one OpenAI-format interface. Here its Router groups deployments by pipeline step, retries and falls back between them, and reports the cost of every call from its built-in model cost map, including ZeroGPUβs native
zerogpu/route. - ZeroGPU: A compute-efficient inference provider for apps and agents. We run purpose-built small and nano language models across an edge network for the high-volume tasks you run constantly - classification, extraction, moderation, routing, summarization - at ~10x lower latency and 50%+ lower cost than frontier-model workflows. Auto-scaling, with zero GPU infrastructure to manage. Plug in and youβre live.
- OpenAI: A leading provider of advanced AI models capable of natural language understanding, contextual reasoning, and content generation. It enables intelligent, human-like interactions and supports a wide range of applications across various domains.

