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

推荐订阅源

H
Hacker News: Front Page
S
Secure Thoughts
N
News | PayPal Newsroom
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Threatpost
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
A
Arctic Wolf
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
L
LINUX DO - 热门话题
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
H
Heimdal Security Blog
Webroot Blog
Webroot Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
小众软件
小众软件
V
V2EX
K
Kaspersky official blog
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
Cisco Blogs
S
Schneier on Security
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志
AI
AI
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
I
InfoQ
G
Google Developers Blog
博客园_首页
Hugging Face - Blog
Hugging Face - Blog

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 OpenAI Costs From Scratch: What Nobody Tells You
eagerspark · 2026-06-27 · via DEV Community

Cutting OpenAI Costs From Scratch: What Nobody Tells You

Three months ago I sat down with my finance lead and watched her scroll through our OpenAI invoice. The number was $14,200 for the month. That was the moment I knew we had a problem. Not a "maybe we should optimize" problem — a real, existential, "this kills our margins before we hit Series B" problem.

I run a B2B SaaS platform that does a lot of LLM-powered document processing. Summarization, extraction, classification, the boring stuff that makes real money but burns tokens like crazy. We were routing everything through GPT-4o because, honestly, it was the path of least resistance when we started. Then the bills started arriving.

This is the story of how I cut our LLM spend by 97%, the architecture decisions that made it possible, and the things I wish someone had told me before I started.

The Math That Made Me Sweat

Let me put actual numbers on the table. Here's what I was paying versus what I pay now:

Model Provider Input $/M Output $/M vs GPT-4o
GPT-4o OpenAI $2.50 $10.00
GPT-4o-mini OpenAI $0.15 $0.60 16.7× cheaper
DeepSeek V4 Flash Global API $0.18 $0.25 40× cheaper
Qwen3-32B Global API $0.18 $0.28 35.7× cheaper
DeepSeek V4 Pro Global API $0.57 $0.78 12.8× cheaper
GLM-5 Global API $0.73 $1.92 5.2× cheaper
Kimi K2.5 Global API $0.59 $3.00 3.3× cheaper

Look at that DeepSeek V4 Flash row. 40× cheaper than GPT-4o. For comparable quality on the workloads I was running. I had been leaving 97.5% of my budget on the table.

Doing the mental math: a $500/month OpenAI bill becomes $12.50. My $14,200 bill? Theoretically $355. That's not optimization, that's a different business.

Why I Almost Didn't Do It

Here's the thing nobody tells you about cost optimization at a startup: it's not a technical problem, it's a willpower problem. The reason I was paying OpenAI 40× too much wasn't because their API is hard to use. It was because switching felt risky. I had deadlines. I had a roadmap. I had investors asking about growth metrics, not infrastructure costs.

The voice in my head said: "It's working. Don't touch it. Focus on product-market fit. Optimize later."

That voice is wrong. Here's why.

At our scale, every percentage point of margin matters more than every percentage point of growth. We weren't pre-PMF trying to find product-market fit — we were post-PMF trying to find a path to profitability. And the difference between spending 3% of revenue on inference and spending 30% of revenue on inference is the difference between raising a Series A on our own terms and having our runway dictate every decision we make.

The other voice in my head said: "Vendor lock-in. If you build everything on OpenAI and they raise prices, you're screwed."

That voice was 100% right.

The Decision Framework That Worked

I didn't just want to switch providers. I wanted to build a system where switching was a configuration change, not a rewrite. That meant three architectural principles:

  1. Standardize on the OpenAI SDK. Even if I'm not using OpenAI, use the OpenAI client library. Every major model provider supports it. The SDK is a commodity. The model is a commodity. Don't couple yourself to either.

  2. Abstract the model name. Hardcoding gpt-4o in your codebase is how you end up locked in. Make it a config value. Better yet, make it a runtime decision.

  3. Build a router. Even if it starts as an if/else, build a router that can send requests to different models based on the task. Different models for different jobs. Don't send everything through the most expensive one.

Once I had those principles, the actual migration became trivial. Two lines of code, as it turns out.

The Migration: What Actually Happened

I want to walk you through the real migration path I took, with real code, because the docs out there are full of hand-waving and I want this to be the post I wish I had read.

Here's the Python example, which is what runs in our production backend:

from openai import OpenAI

client = OpenAI(api_key="sk-proj-...")

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Summarize this contract."}],
    temperature=0.3,
    max_tokens=1000,
)

That was the entirety of our integration. Hundreds of calls per minute, all going through that exact pattern. Now here's the after:

# After: Global API with DeepSeek V4 Flash
from openai import OpenAI

client = OpenAI(
    api_key="ga_xxxxxxxxxxxx",
    base_url="https://global-apis.com/v1"
)

response = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Summarize this contract."}],
    temperature=0.3,
    max_tokens=1000,
)

That's it. Two changes: api_key and base_url. The model name changed too, but that's the configuration decision, not a code change in the abstract sense.

The OpenAI client library is just an HTTP client with a friendly interface. It doesn't care where the endpoint points. It doesn't care what model responds. It's an abstraction layer that happens to default to OpenAI's servers, but you can route it anywhere.

This is the moment I realized I had been psychologically anchoring on a vendor when the actual coupling in my code was minimal.

A More Realistic Production Setup

Two lines of code works for a quick test. In production, you want a router. Here's what I actually deployed:

# model_router.py
import os
from openai import OpenAI
from dataclasses import dataclass

@dataclass
class ModelConfig:
    name: str
    client: OpenAI
    cost_per_million_output: float
    use_for: list[str]

# Build clients for each provider we use
openai_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
global_api_client = OpenAI(
    api_key=os.environ["GLOBAL_API_KEY"],
    base_url="https://global-apis.com/v1"
)

MODELS = {
    "fast": ModelConfig(
        name="deepseek-v4-flash",
        client=global_api_client,
        cost_per_million_output=0.25,
        use_for=["classification", "extraction", "simple_summarization"]
    ),
    "balanced": ModelConfig(
        name="qwen3-32b",
        client=global_api_client,
        cost_per_million_output=0.28,
        use_for=["summarization", "translation", "code_review"]
    ),
    "premium": ModelConfig(
        name="gpt-4o",
        client=openai_client,
        cost_per_million_output=10.00,
        use_for=["complex_reasoning", "agentic_tasks"]
    ),
}

def get_model(task_type: str) -> ModelConfig:
    for model in MODELS.values():
        if task_type in model.use_for:
            return model
    return MODELS["balanced"]  # safe default

def complete(task_type: str, messages: list, **kwargs):
    model = get_model(task_type)
    return model.client.chat.completions.create(
        model=model.name,
        messages=messages,
        **kwargs
    )

This is a real router. It picks the cheapest model that can handle the task. Classification doesn't need GPT-4o — it needs DeepSeek V4 Flash at $0.25/M output. Complex reasoning might still warrant GPT-4o, but only for the 5% of requests that actually need it.

The result: our average cost per request dropped from something like $0.012 to something like $0.0008. The math works.

What I Got Wrong The First Time

Let me save you some pain. Here are the things I tried that didn't work, and the things that did.

What didn't work: trying to migrate everything at once. I picked a Friday afternoon, made the switch, pushed to production, and watched error rates spike. Why? Because not every OpenAI feature is supported everywhere yet. I had been using the Assistants API for one specific workflow. That feature isn't available on Global API (yet). I had to build a workaround using the chat completions endpoint.

What didn't work: assuming all "cheap" models are equivalent. I tested DeepSeek V4 Flash on classification. It crushed it. I tested it on nuanced summarization. It was noticeably worse than GPT-4o. The router I showed you above exists because of this. Use the right tool for the job.

What worked: building a feature parity matrix before migrating. I sat down and listed every OpenAI feature I was using. Chat completions? Easy. Streaming? Easy. Function calling? Easy. Vision? Easy. Embeddings? Coming soon. Fine-tuning? Not available. Assistants API? Not available. TTS/STT? Not available.

Once I had that list, I knew exactly which features I needed to keep on OpenAI (none, in the end) and which features I needed to architect around.

What worked: load testing with real production traffic. I duplicated a percentage of production traffic to the new provider for a week. Compared outputs. Compared latency. Compared cost. Only after I had data did I make the full switch.

Feature Compatibility: The Real List

Here's the actual matrix I used, presented in a way that made the decision obvious:

Feature OpenAI Global API Notes
Chat Completions Yes Yes Identical API
Streaming (SSE) Yes Yes Identical
Function Calling Yes Yes Identical format
JSON Mode Yes Yes response_format
Vision (Images) Yes Yes GPT-4V / Qwen-VL
Embeddings Yes Coming soon Use OpenAI for now
Fine-tuning Yes Not available Different strategy needed
Assistants API Yes Not available Build your own
TTS / STT Yes Not available Use dedicated services

Three "not available" features. For us, none of them were dealbreakers. For you, they might be. Do the audit before you migrate.

The Vendor Lock-In Question

People keep asking me: "But aren't you just trading OpenAI lock-in for Global API lock-in?"

Fair question. The answer is no, and here's why.

The OpenAI client SDK is an industry standard. Every serious provider supports it. If Global API disappears tomorrow, I change my base_url and point at someone else. The code doesn't change. The model name changes. That's a deployment, not a rewrite.

If OpenAI disappears tomorrow — or, more realistically, raises prices 3× — same story. I change my base_url and I'm done.

The lock-in I had before was real. The "lock-in" I have now is configuration. There's a world of difference.

What About Quality?

I know what you're thinking: "Sure, it's cheaper, but is the quality good enough?"

For our use cases: yes, and sometimes better. DeepSeek V4 Flash on classification tasks was, in my testing, at parity with GPT-4o. For some extraction tasks, it was actually more consistent (probably because GPT-4o tries to be too clever and second-guesses instructions).

For complex reasoning — multi-step analysis, agentic workflows, anything where the model needs to hold a lot of state and reason about it — GPT-4o still wins. That's why the router sends those tasks to the premium tier. You don't have to pick one model. You have to pick the right model for each task.

The other thing I learned: quality isn't a single dimension. Latency matters. Consistency matters. Predictability matters. I found that DeepSeek V4 Flash was actually faster on my workloads than GPT-4o, which meant I could handle more requests with the same infrastructure. That compounds the cost savings.

The Actual Numbers, Three Months In

Let me give you the real numbers from my last three months, because the marketing claims of "40× cheaper" are meaningless without proof.

Month 1 (baseline, all OpenAI): $14,200
Month 2 (migration, 60/40 split): $5,840
Month 3 (production, full router): $1,180

The volume went up. The cost went down. That's the entire pitch.

The other thing that happened: I stopped being afraid of adding LLM features. Before the migration, every new feature request went through a "is this worth the inference cost" filter. After the migration, that filter basically went away. I added three new product features in month 3 that I would have killed in month 1 based on cost alone. The infrastructure savings unlocked product velocity.

That's the real ROI. Not just the 92% cost reduction — the fact that cost stopped being a constraint on the roadmap.

Things To Watch Out For

A few gotchas I hit that aren't in the docs:

  1. Rate limits are different. Global API has different rate limits than OpenAI. Check them before you migrate, not after. I learned this the hard way when I got 429s on a Tuesday afternoon.

  2. Streaming behavior is slightly different. The chunk format is identical, but the timing can vary. If you have UI that depends on token-by-token timing, test it thoroughly.

  3. Error codes are different. If you have retry logic that depends on specific OpenAI error codes (like rate_limit_error vs RateLimitError), update it. The codes follow a similar pattern but aren't identical.

  4. Model naming is more flexible. Global API exposes 184 models, which is great, but you need to know what you're asking for. Don't just guess model names — use the API reference.

My Recommendation

If you're a startup CTO spending real money on OpenAI, here's what I'd do, in order:

  1. Audit your actual spend. Not your estimated spend. Your actual, line-item spend. Break it down by feature/use case.

  2. Identify your high-volume, low-complexity workloads. These are your migration candidates. Classification, extraction, simple summarization, anything that's high-volume and doesn't need GPT-4o's full reasoning power.

  3. Build the router. Even if you only have two providers today, build the abstraction. Future you will thank present you.

  4. Run a parallel test. Send a percentage of traffic to the new provider for a week. Compare outputs. Compare latency. Compare