Skip to main content
This notebook demonstrates how to put a LiteLLM Router in front of ZeroGPU to run an inbound lead desk: every β€œContact sales” form submission is qualified, mined for structured fields, and answered with a first-touch reply. Each step runs on the smallest ZeroGPU model that can do the job, enterprise deals escalate to a frontier model, and every call lands in a cost ledger priced against a GPT-4.1 baseline. By combining LiteLLM and ZeroGPU, this notebook walks you through a practical pattern for routing high-volume, well-defined LLM work to cheap models while keeping a frontier model exactly where it earns its price. For the full reference, see the LiteLLM integration guide. In this notebook, you’ll explore:
  • 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.
This setup not only demonstrates a practical application of tiered model routing for sales operations, but also provides a flexible framework that can be adapted to other real-world scenarios requiring cost-aware, multi-step LLM pipelines with structured outputs and a frontier-model safety net.

πŸŽ₯ Watch the Video Guide

Video walkthrough coming soon.

πŸ“¦ Installation

First, install the LiteLLM package with all its dependencies:
ZeroGPU doesn’t need its own SDK here. LiteLLM ships a native 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 with zgpu-api- and the Project ID (UUID) is on the project settings page.
Python
You can go to here to get an API key from OpenAI.
Python
LiteLLM reads 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 single zerogpu/ call through LiteLLM and read its cost straight off the response.
Python
πŸŽ‰ ZeroGPU effortlessly answers through LiteLLM’s native 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
Now define the model groups. 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
Before running anything, check that LiteLLM knows what each ZeroGPU model can do. Strict 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

The qualify group reads each lead and returns three enums under a strict schema, so the code branches on fields rather than parsing prose.
Python
The spam lead stops here, and the support ticket gets bounced to the help desk. Neither one ever touches a bigger model.

πŸ”Ž Step 2: Extract the CRM Fields

For leads worth pursuing, the extract 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
The one enterprise reply on GPT-4.1 accounts for almost two thirds of the whole bill. That’s the trade you want to see: frontier tokens spent on the single deal most likely to close, and everything repetitive running on small models.

πŸ›‘οΈ 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. Pass mock_testing_fallbacks=True and the Router fails the primary deployment on purpose, then walks the fallbacks list:
Python
The reply still went out, 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.
This comprehensive setup allows you to adapt and expand the example for various scenarios requiring cost-aware, multi-step LLM pipelines with structured outputs and a frontier-model safety net.