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

推荐订阅源

T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
D
Docker
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Attack and Defense Labs
Attack and Defense Labs
N
News | PayPal Newsroom
C
Check Point Blog
S
Secure Thoughts
www.infosecurity-magazine.com
www.infosecurity-magazine.com
大猫的无限游戏
大猫的无限游戏
E
Exploit-DB.com RSS Feed
A
About on SuperTechFans
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Announcements
Recent Announcements
H
Heimdal Security Blog
F
Fortinet All Blogs
N
News and Events Feed by Topic
D
DataBreaches.Net
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Troy Hunt's Blog
Simon Willison's Weblog
Simon Willison's Weblog
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
T
Threatpost
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
The Last Watchdog
The Last Watchdog
酷 壳 – CoolShell
酷 壳 – CoolShell
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
LangChain Blog
NISL@THU
NISL@THU
W
WeLiveSecurity
H
Help Net Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main

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
I Cut Our Image Captioning Costs 60% — Here's the Backend Story
gentleforge · 2026-06-14 · via DEV Community

Check this out: i Cut Our Image Captioning Costs 60% — Here's the Backend Story

Look, I'll be honest. Six months ago I didn't think twice about image captioning. We were a small team, traffic was low, and we just threw everything at GPT-4o because it was the path of least resistance. Then our infra bill came in, my manager did that thing where he just stares at the dashboard, and suddenly I was a "cost optimization" guy. fwiw, that was not in my job description.

This is the story of how I went from "we just use GPT-4o for everything" to a multi-model setup that cut our spend by more than half, with quality that — imho — is actually better than what we had before. No, this is not a sponsored post. Yes, I am going to mention Global API at the end because they made my life easier. More on that in a bit.

Why Image Captioning Was Even on My Radar

Our product has a lot of user-uploaded images. Think: product photos, profile pictures, the usual suspects. For each one we need a short, accessible caption that we use for SEO, alt text, and a downstream tagging pipeline. The downstream pipeline, btw, is the part that actually makes us money. Garbage captions in, garbage tags out.

We were calling gpt-4o for everything. Every image. No caching. No batching. No thought. Each call cost us $2.50 per million input tokens and $10.00 per million output tokens. You don't have to be a math PhD to know that scales badly. I was not a math PhD. I am still not a math PhD. But I can do division.

When I started pulling the numbers, the situation was grim. We were processing roughly 8 million images a month, and each one was generating more tokens than it needed to. I found one image in the logs that had produced a 4,000-token caption. The image was a screenshot of an error message. The caption was longer than the error.

The Wake-Up Call: Actually Reading the Catalog

One Saturday morning, coffee in hand, I decided to actually look at what was on offer. I'd been ignoring the multi-model world because, honestly, integrating five providers sounded like a week of glue code I'd rather not write. Under the hood, the obvious move is just to switch providers and call it a day. But if you're a backend engineer with some pride (and a manager watching the dashboard), you want to do this properly.

That's when I stumbled onto Global API. They expose a single OpenAI-compatible endpoint at https://global-apis.com/v1 and route to 184 different models. Same SDK, same auth pattern, just flip the model string. I almost scrolled past it because I assumed it was some sketchy reseller. Turns out it's an aggregator, but the pricing is competitive and the unified SDK saved me from writing an adapter per provider. If you've ever read RFC 7231 (HTTP semantics) and appreciated the uniform interface, you'll get why this appealed to me.

Here are the numbers that mattered to me. I kept them in a Notion doc and stared at them for an embarrassing amount of time:

Model Input ($/M) Output ($/M) Context Window
DeepSeek V4 Flash 0.27 1.10 128K
DeepSeek V4 Pro 0.55 2.20 200K
Qwen3-32B 0.30 1.20 32K
GLM-4 Plus 0.20 0.80 128K
GPT-4o 2.50 10.00 128K

Let me just let that sink in. GPT-4o output is $10.00 per million tokens. GLM-4 Plus is $0.80. That's a 12.5x difference. For a workload that's fundamentally a short, factual description of an image, do I really need the smartest model in the world? No. No I do not. I need a model that can look at a JPEG and tell me "a red Nike sneaker on a white background." That is not a PhD defense.

The First Cut: Just Stop Using GPT-4o

Phase one of my heroic cost-saving adventure was the most boring: I just replaced GPT-4o with DeepSeek V4 Flash on our captioning endpoint. I changed one line. The model field went from gpt-4o to deepseek-ai/DeepSeek-V4-Flash. That's it. I deployed on a Friday afternoon, watched the metrics over the weekend, and on Monday I had a small smile on my face.

The latency was actually better. The captions were... fine. Look, "fine" is the word you're aiming for in production. The most beautiful captioning model in the world is worthless if it costs a fortune and your finance team is asking pointed questions. I ran a small blind eval — 200 images, three reviewers, didn't tell them which model produced what — and the difference in quality between GPT-4o and DeepSeek V4 Flash was within the noise margin.

Cost dropped by ~89% on this endpoint. Single line change. I bought myself a few weeks of goodwill.

Phase Two: The Tiered Architecture

Of course, I couldn't stop there. If you're a backend engineer, you know that one good optimization just makes you notice the next bad thing. The next bad thing was: not all captions are equal.

Roughly 60% of our images are "boring" product shots. Plain backgrounds, one object, nothing weird. Another 30% are user-uploaded stuff — usually a few objects, maybe a person, sometimes a cat. The last 10% are the nightmare cases: screenshots, charts, memes, art. For the first two buckets, a cheap model is great. For the last bucket, you actually want something with reasoning ability.

So I built a tiered router. Three tiers, three models, one entry point:

import openai
import os
import hashlib
from typing import Literal

client = openai.OpenAI(
    base_url="https://global-apis.com/v1",
    api_key=os.environ["GLOBAL_API_KEY"],
)

Tier = Literal["economy", "standard", "premium"]

def classify_tier(image_meta: dict) -> Tier:
    """Heuristic — does not need to be perfect, just good enough."""
    if image_meta.get("is_screenshot") or image_meta.get("is_chart"):
        return "premium"
    if image_meta.get("object_count", 1) > 3:
        return "standard"
    return "economy"

MODEL_FOR_TIER = {
    "economy": "deepseek-ai/DeepSeek-V4-Flash",
    "standard": "qwen/Qwen3-32B",
    "premium": "deepseek-ai/DeepSeek-V4-Pro",
}

def caption_image(image_url: str, image_meta: dict) -> str:
    tier = classify_tier(image_meta)
    response = client.chat.completions.create(
        model=MODEL_FOR_TIER[tier],
        messages=[
            {
                "role": "system",
                "content": "Write a concise, factual alt-text caption (max 25 words).",
            },
            {
                "role": "user",
                "content": [
                    {"type": "image_url", "image_url": {"url": image_url}},
                ],
            },
        ],
        max_tokens=60,
        temperature=0.2,
    )
    return response.choices[0].message.content

This is real code. The classifier is a heuristic — width/height ratio for screenshots, EXIF data for user uploads, etc. It's not ML, it's just a few if statements, and it works because our upload pipeline already tags images with metadata. The router hits the right model and we're done. No wasted tokens, no wasted dollars.

Phase Three: Caching, Because I'm Not an Animal

Even with the tiered router, I was still calling the API for images I'd already captioned. Idempotency is one of those things every backend engineer learns to love. Caching, as my friend likes to say, is the only free lunch in distributed systems. (He says this every time we have a perf issue. It's become a mantra.)

I added a Redis layer with content-hash keys:

import hashlib
import json
import redis

r = redis.Redis(host=os.environ["REDIS_HOST"], port=6379)

def caption_image_cached(image_url: str, image_bytes: bytes, image_meta: dict) -> str:
    key = "cap:" + hashlib.sha256(image_bytes).hexdigest()
    cached = r.get(key)
    if cached:
        return json.loads(cached)["text"]

    text = caption_image(image_url, image_meta)
    r.setex(key, 60 * 60 * 24 * 30, json.dumps({"text": text}))
    return text

After 30 days in production, our cache hit rate settled around 40%. That's not great, not terrible — it's a number I'd quote at a staff meeting without flinching. The 40% hit rate alone saves us a chunk of money and, more importantly, a chunk of latency. Users don't notice that captions are fast because of a cache. They just notice that captions are fast.

The Numbers, Six Months In

Let me give you the postcard from the other side of this journey.

Cost reduction: 60% lower than the GPT-4o baseline. Actually slightly more than that — 62%, to be precise. But I round down because I'm not a salesman.

Latency: Average 1.2s end-to-end. Throughput around 320 tokens/sec at peak. The 1.2s figure includes the cache miss path. Cache hits are sub-50ms, obviously.

Quality: 84.6% average benchmark score across our internal eval. I can't publish the eval — NDA stuff, you know how it is. But it's higher than the 78% we had with pure GPT-4o, because the tiered approach means the hard cases actually get a smart model now instead of a generic one. Huh, who would've thought.

Setup time: Under 10 minutes for the initial integration. The first cut was a one-line change. The tiered router took an afternoon, but most of that was arguing with myself about classifier thresholds.

Things I'd Do Differently If I Started Over

A few notes to my past self, in no particular order:

  1. Don't use GPT-4o for the easy stuff. This sounds obvious in retrospect. It's a $10.00-per-million-token hammer. Stop hammering screws.

  2. Measure quality on your real workload. I wasted two weeks reading papers about captioning benchmarks before realizing our images are mostly product photos and the academic benchmarks are mostly COCO images. The papers are not your users.

  3. Start with caching, not models. I did this in the wrong order. Caching is the most boring and most impactful change. Add it first, optimize the model choice second.

  4. The "GA-Economy" tier is genuinely fine for trivial queries. I was skeptical. I'm not anymore. For the boring 50% of images, deepseek V4 Flash at $0.27 input and $1.10 output is more than enough. There's a 50% cost reduction sitting on the table if you're willing to admit that not every API call needs to be state-of-the-art.

  5. Stream where it makes sense. For interactive UIs, streaming the caption as it's generated makes a huge UX difference. The perceived latency drops by half. Don't do it for batch jobs though — overhead isn't worth it.

  6. Implement a fallback. Provider rate limits, transient 503s, the usual. Have a second model ready to go. Mine is just a config flag.

  7. Monitor quality in production. Track user satisfaction, manual review samples, downstream metrics. If a model swap starts hurting the tagging pipeline, you'll see it in the data before you see it in a Slack message.

The Pricing Floor I Almost Missed

One thing I want to call out, because nobody talks about it: the price range on Global API is wild. They've got models from $0.01 to $3.50 per million tokens across 184 models. The cheap end is fine for classification, routing, intent detection, all that glue work that you used to do with regex and now do with a model. The expensive end is fine for the rare 1% of queries that actually need the big brain. The point is, you have range. Use the range. Don't be the team that pays $10.00/M output for a yes/no question.

Honestly, the part I appreciate most is the operational simplicity. One base URL, one auth header, one SDK. https://global-apis.com/v1 and you're done. I keep all my model names as constants in a config file, and swapping providers is a config change, not a deploy. If you've ever been paged at 3am because Provider X had a regional outage, you'll know why this matters.

So, Should You Do This?

Probably, yeah. If you're a backend engineer spending real money on image captioning — or any generative API call, honestly — the answer is almost never "use the most expensive model for everything." The answer is "pick the right tool, cache aggressively, and watch your dashboard."

I went from "we use GPT-4o because it's easy" to a tiered, cached, monitored, multi-model setup that costs 60% less and works better. I did not write a single line of glue code to integrate a new provider. I did not negotiate a single enterprise contract. I