---
title: "Mubit + Neon AI Gateway: an agent that cuts its own frontier-model tokens by 73%"
description: "Mubit, a proxy placed in front of Neon AI Gateway, records an agent's model calls, groups recurring calls into tasks, and fine-tunes a small open-weight model once a task has at least 25 good replies."
url: "https://swe.quest/articles/mubit-neon-ai-gateway-an-agent-that-cuts-its-own-frontier-model-tokens-by-73-358da1147275d399"
canonical: "https://neon.com/blog/mubit-neon-ai-gateway"
source: "Neon"
published: "2026-11-12"
difficulty: "medium"
kind: "Case study"
reading_minutes: 10
tags: ["ai-agents","llms","cost-optimization","inference","postgres"]
---

# Mubit + Neon AI Gateway: an agent that cuts its own frontier-model tokens by 73%

A post on [Neon](https://swe.quest/sources/neon.md), published 2026-11-12, 10 min read, Case study. Original: [https://neon.com/blog/mubit-neon-ai-gateway](https://neon.com/blog/mubit-neon-ai-gateway)

## Summary

Mubit, a proxy placed in front of Neon AI Gateway, records an agent's model calls, groups recurring calls into tasks, and fine-tunes a small open-weight model once a task has at least 25 good replies. The tuned model must pass a held-out exam, then moves through shadow, canary and promotion stages, and is demoted if sampled quality drops. It also stores verified lessons tied to schema versions. On 20 CL-bench questions run against a Postgres analyst agent, gpt-5.5 input tokens fell 73% (21.7k to 5.9k per question) and latency fell 40% with roughly equal accuracy. SQL generation stayed on the frontier model because the small model matched only 8-10% of the time, and lessons doubled correct runs after a schema change. The template runs on Neon Functions with an outbox-style lesson queue and uses Neon branches to test before and after a migration.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)

## Prerequisites

- LLM agents and tool calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- OpenAI-compatible APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))
- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

Mubit, Neon AI Gateway, Neon Functions, Lakebase, gpt-5.5, CL-bench, Neon branches

## Related posts

- [Open-weight models are fast on Neon AI Gateway. Here's why](https://swe.quest/articles/open-weight-models-are-fast-on-neon-ai-gateway-here-s-why-a042a513966cd27f.md): Neon · 2026-08-20 · Medium · 7 min read · Inference & serving, LLMs, Performance engineering, Caching, AI agents
  Neon AI Gateway serves open-weight models through Databricks Foundation Model APIs, so it gets that stack's inference optimizations: continuous batching with PagedAttention-style KV-cache paging and overlapped prefill/decode, a TensorRT-LLM backend with fused and GroupGEMM kernels for MoE, tensor parallelism, FP8 quantization, and per-GPU tuning.
- [How Shopify turns open models into task experts](https://swe.quest/articles/how-shopify-turns-open-models-into-task-experts-a2ba67e222beb92b.md): Shopify Engineering · 2026-10-21 · Hard · 5 min read · Model training, Inference & serving, Evaluation, AI agents, Cost optimization
  Shopify's Sidekick keeps a frontier model for merchant conversation and planning but offloads token-heavy subagent work, such as GraphQL query generation, to open models it post-trains and self-hosts.
- [Neon for Agent Platforms: A Companion Skill for the AI Agent Program](https://swe.quest/articles/neon-for-agent-platforms-a-companion-skill-for-the-ai-agent-program-6b42423040c5c41e.md): Neon · 2026-05-22 · Medium · 3 min read · PostgreSQL, Multi-tenancy, AI agents, Cloud platforms
  neon-for-agent-platforms is an open-source companion Agent Skill and set of TypeScript scripts for running fleets of Neon Postgres databases on agent platforms.
- [Sidekick's continual learning loop](https://swe.quest/articles/sidekick-s-continual-learning-loop-f72e46000910fa09.md): Shopify Engineering · 2026-08-05 · Hard · 9 min read · Model training, Evaluation, Inference & serving, LLMs, Cost optimization
  Shopify's Sidekick GraphQL agent improves daily through a continual learning loop that turns production failures into model weight updates, beating frontier-model quality while cutting estimated serving costs from about $27M to $1M per year (96%).
- [Training 100x Cheaper Retrieval models Neon and Castform](https://swe.quest/articles/training-100x-cheaper-retrieval-models-neon-and-castform-05a64846d2e32056.md): Neon · 2026-08-05 · Easy · 5 min read · Model training, RAG & retrieval, PostgreSQL, AI agents, Search
  Castform uses data stored in Neon Postgres, exposed through Lakebase Search's BM25 and vector functions, to RL post-train a 4B open-source model for agentic retrieval.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
