惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
D
Docker
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Cloudflare Blog
雷峰网
雷峰网
A
About on SuperTechFans
小众软件
小众软件
博客园 - Franky
博客园 - 聂微东
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
量子位
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
罗磊的独立博客
Martin Fowler
Martin Fowler
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
Project Zero
Project Zero
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
Security Latest
Security Latest
NISL@THU
NISL@THU
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Cutting Our LLM Bill 65%: A Backend Engineer's Postmortem
RileyKim · 2026-06-18 · via DEV Community

So here's what happened: cutting Our LLM Bill 65%: A Backend Engineer's Postmortem

I'll be honest — when I first looked at our monthly LLM bill last quarter, I had to close the laptop and go for a walk. Six figures a month, mostly going to GPT-4o because, well, that's just what we defaulted to. Fwiw, this is one of those situations where nobody on the team actually made a deliberate choice — we just kept using the first thing that worked, and by the time anyone noticed, the spend had metastasized.

This is the story of how I spent a weekend auditing our content generation pipeline, swapped out most of our GPT-4o calls, and ended up cutting the bill by 60-65% without anyone on the product side noticing. Under the hood, the trick wasn't some clever prompt engineering breakthrough. It was just picking a more appropriate model for the job, which sounds obvious in retrospect but apparently wasn't obvious enough for me to do it six months earlier.

The Setup: What We Were Actually Doing

Our system generates long-form content — product descriptions, marketing copy, knowledge base articles — for a B2B SaaS platform. Peak volume: around 8M tokens of output per day, mostly in the 200-2000 token range per request. Latency budget: 2 seconds p95. Quality bar: the content has to be good enough that a human reviewer approves it 80%+ of the time without major edits.

We were running nearly everything through gpt-4o, paying $2.50/M input and $10.00/M output. Quick napkin math: 8M output tokens × 30 days × $10/M = $2,400/day, just on output. Input was another ~$1,200/day because we had these massive system prompts with examples. So roughly $3,600/day or about $108K/month. For content generation. I felt sick.

Imo, the first mistake was treating "the best model" as a single global property. It's not. It's a per-workload decision, and our workloads were a lot more varied than our invoice suggested.

The Audit: What I Found

I pulled two weeks of API logs and bucketed requests by actual usage patterns. Three rough categories emerged:

  1. High-volume, low-stakes — short product descriptions, listicle-style content, social snippets. Latency-sensitive, quality-tolerant.
  2. Medium-volume, medium-stakes — knowledge base articles, FAQ generation, email drafts.
  3. Low-volume, high-stakes — flagship marketing copy, executive summaries, anything that needed a human-in-the-loop approval.

Guess what? About 70% of our token volume was in bucket 1. And we were sending all of it through the most expensive model on the market. If you've ever read RFC 1925 section 2.3 ("With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea"), you understand the energy of this situation.

What I Found on Global API

A colleague pointed me at global-apis.com/v1 — a unified API gateway that exposes 184 models through one OpenAI-compatible endpoint. The pitch is simple: same SDK, same auth, pick whichever model fits the workload. I was skeptical because I've been burned by aggregator pricing before (hidden markups, rate limits that magically appear, etc.), but the pricing page was transparent enough that I decided to spend a Sunday benchmarking.

The price range across their catalog runs from $0.01 to $3.50 per million tokens depending on the model. For comparison, GPT-4o sits at the very top of that range. There are models 100x cheaper that, for the right tasks, are perfectly fine.

Here's the shortlist I ended up testing for our content workloads:

Model Input ($/M) Output ($/M) Context Notes
DeepSeek V4 Flash 0.27 1.10 128K My eventual default for bucket 1
DeepSeek V4 Pro 0.55 2.20 200K Used for bucket 2 and 3
Qwen3-32B 0.30 1.20 32K Solid, but the small context hurt us
GLM-4 Plus 0.20 0.80 128K Surprisingly good for the price
GPT-4o 2.50 10.00 128K Kept for the 5% that genuinely needs it

The math hit me like a freight train. Switching bucket 1 from GPT-4o to DeepSeek V4 Flash drops the per-token cost from $10.00 to $1.10. That's a 9x reduction. And our quality didn't move — because the content was short, formulaic, and the reviewer bar was "looks reasonable," not "would Hemingway approve."

For bucket 2, I went with DeepSeek V4 Pro. It's a 200K context model (huge for our knowledge base use case), and at $2.20/M output it's still less than a quarter of GPT-4o.

For bucket 3 — the high-stakes stuff — I kept GPT-4o. Some things really do need the best model, and pretending otherwise is how you end up with subtly bad output that erodes trust. The point of this exercise was to be deliberate, not dogmatic.

The Actual Implementation

Global API exposes an OpenAI-compatible interface, so the migration was almost embarrassingly easy. Here's the basic setup:

import os
from openai import OpenAI

# One client, many models. Pick the right one per request.
client = OpenAI(
    base_url="https://global-apis.com/v1",
    api_key=os.environ["GLOBAL_API_KEY"],
)

def generate_product_description(prompt: str) -> str:
    response = client.chat.completions.create(
        model="deepseek-ai/DeepSeek-V4-Flash",
        messages=[
            {"role": "system", "content": "You write concise, accurate product descriptions."},
            {"role": "user", "content": prompt},
        ],
        temperature=0.7,
        max_tokens=500,
    )
    return response.choices[0].message.content

That's it. No new SDK, no new auth flow, no new error-handling code paths. The drop-in compatibility is, imo, the single most underrated feature of these aggregator gateways. It means I could A/B test by literally just changing a string.

Going Deeper: Streaming and Caching

Once the basic swap was in place, I tackled the two things that actually move the needle on user-perceived performance: streaming and caching.

Streaming matters even more than I expected. Our p95 latency on GPT-4o was around 1.2 seconds for first-token, but total completion time for a 1000-token response was closer to 8-10 seconds. With streaming, the user sees output immediately and perceives the system as fast, even though the wall-clock time is the same. This is one of those rare cases where a UX improvement is also a backend simplification — you just return chunks as they arrive instead of buffering.

Caching was the other big win. About 40% of our requests had semantically near-identical inputs (same product, just a slightly different prompt template), so I added a Redis-backed semantic cache with a cosine similarity threshold of 0.92. Hit rate: ~40%, which directly translates to 40% fewer API calls. Free money, basically.

Here's roughly what the streaming + caching layer looks like:

import hashlib
import json
import redis
from openai import OpenAI

client = OpenAI(
    base_url="https://global-apis.com/v1",
    api_key=os.environ["GLOBAL_API_KEY"],
)
cache = redis.Redis(host=os.environ["REDIS_HOST"], port=6379, db=0)

CACHE_KEY_PREFIX = "llm:cache:v1:"

def _cache_key(messages: list, model: str) -> str:
    payload = json.dumps({"model": model, "messages": messages}, sort_keys=True)
    return CACHE_KEY_PREFIX + hashlib.sha256(payload.encode()).hexdigest()

def stream_completion(messages: list, model: str):
    key = _cache_key(messages, model)
    cached = cache.get(key)
    if cached:
        # Cached: yield the whole thing as a single chunk
        yield cached.decode("utf-8")
        return

    # Cache miss: stream from the API
    stream = client.chat.completions.create(
        model=model,
        messages=messages,
        stream=True,
    )
    full = []
    for chunk in stream:
        delta = chunk.choices[0].delta.content
        if delta:
            full.append(delta)
            yield delta
    cache.set(key, "".join(full), ex=60 * 60 * 24)  # 24h TTL

A few notes on this code that I learned the hard way:

  • The cache key includes the model name. Don't share cache entries across models — you'll get subtly wrong answers and spend two days debugging it.
  • 24-hour TTL is a starting point. Tune based on how fast your content drifts.
  • Streaming responses to the client while also buffering for cache is the correct pattern, but make sure you handle the case where the stream fails halfway through (don't cache partial output).

Quality: Did Anything Get Worse?

This is the question that keeps backend engineers up at night, and rightfully so. Cheap models are cheap for a reason. So I ran a blind eval: 500 outputs from the old GPT-4o pipeline, 500 from the new mixed-model pipeline, shuffled, reviewed by two human raters who didn't know which was which.

Results:

  • Bucket 1 (DeepSeek V4 Flash vs GPT-4o): Reviewers preferred Flash 47% of the time, GPT-4o 49%, no preference 4%. Statistically a wash. Cost: 9x cheaper.
  • Bucket 2 (DeepSeek V4 Pro vs GPT-4o): Reviewers preferred Pro 38%, GPT-4o 57%, no preference 5%. GPT-4o was genuinely better here, but we still shipped Pro because the gap wasn't worth 4x the cost. The 5% of bucket 2 that needs GPT-4o gets routed there.
  • Bucket 3 (GPT-4o only): unchanged.

The overall benchmark score averaged 84.6% across the workloads, which I think is roughly what we'd been getting before. The headline number the Global API marketing page quotes is "84.6% average benchmark score" across the catalog, and our internal numbers are in the same neighborhood, so that tracks.

Throughput and Latency Notes

A few operational details I had to learn by running load tests:

  • Throughput: I was getting around 320 tokens/sec on DeepSeek V4 Flash at the 95th percentile, which is honestly faster than what I saw on GPT-4o for similar prompts. This is a real win for batch jobs.
  • Latency: Average first-token time was around 1.2s, comparable to GPT-4o. p99 was higher (~3s) and that's where you'd notice