DEV Community

kongkong
kongkong

Posted on

Your AI Feature Doesn't Fail at the Model. It Fails at the Handoff.

Last week I watched a demo where an agent drafted a database migration. The chat UI streamed the plan token by token, and then the save button returned a 413: the JSON body had outgrown the proxy's limit. The model had done its job flawlessly, and the handoff had not. Nobody in the room blamed the model, yet everybody went back to comparing models.

Here is my position, stated plainly: the model is the most reliable component in your AI feature. The handoffs around it are where the feature actually dies. Auth, storage, streaming, retries, idempotency — those layers fail in ways the model never will, because they are your code and your deployment. We keep treating AI features as model problems when they are integration problems wearing a model costume.

Disclosure: This article was prepared as part of MonkeyCode's product outreach. I have been rehearsing this argument with the open-source MonkeyCode project, which gives me two things that make handoff rehearsal cheap: ten million free tokens and a free server to run the slice against. I am not claiming the tokens make the model smarter, because they do not; they make the rehearsal cheaper, and that is the entire point.

Here is the smallest slice I could build that still crosses every boundary. It is a boring FastAPI proxy that takes a chat request, checks the auth header, rejects oversized bodies, calls the upstream model, and streams the response back. The model call is about ten lines, and the handoff is everything else.

# handoff.py — the boring proxy that owns every boundary
from fastapi import FastAPI, Header, HTTPException
from fastapi.responses import StreamingResponse
import httpx

app = FastAPI()

UPSTREAM = "https://provider.example/v1/chat/completions"  # replace with your endpoint
TOKEN = "your_free_token"
MAX_MESSAGES = 50

@app.post("/chat")
async def chat(payload: dict, authorization: str = Header(default="")):
    if authorization != f"Bearer {TOKEN}":
        raise HTTPException(status_code=401, detail="missing or bad token")
    if len(payload.get("messages", [])) > MAX_MESSAGES:
        raise HTTPException(status_code=413, detail="payload too large")
    async with httpx.AsyncClient(timeout=60) as client:
        upstream = await client.post(
            UPSTREAM,
            json=payload,
            headers={"Authorization": authorization},
        )
        upstream.raise_for_status()
        return StreamingResponse(upstream.aiter_bytes(), media_type="text/event-stream")
Enter fullscreen mode Exit fullscreen mode

Now deploy that proxy to the free server and run this rehearsal script against it. Every row is a boundary, not a benchmark, and the model never sees the failing requests.

# rehearse.py — every row is a boundary, not a benchmark
import httpx

BASE = "https://your-free-server.example"   # the free server
TOKEN = "your_free_token"

def check(name, headers, body, expected):
    r = httpx.post(f"{BASE}/chat", headers=headers, json=body, timeout=30)
    verdict = "PASS" if r.status_code == expected else f"FAIL (got {r.status_code})"
    print(f"{name:24} -> {verdict}")

big = {"messages": [{"role": "user", "content": "x" * 200_000}]}
small = {"messages": [{"role": "user", "content": "hello"}]}

check("missing auth", {}, small, 401)
check("wrong token", {"Authorization": "Bearer nope"}, small, 401)
check("oversized body", {"Authorization": f"Bearer {TOKEN}"}, big, 413)
check("happy path", {"Authorization": f"Bearer {TOKEN}"}, small, 200)
Enter fullscreen mode Exit fullscreen mode

Run it once and you will learn more about your feature than a week of prompt tuning will teach you. The missing-auth case proves your gateway actually enforces identity, the oversized case proves your proxy has a real limit and not an aspirational one, and the happy path proves the free tokens reach the model through your code and not around it. Each of those is a handoff, and each of them can break in production without the model changing at all. The script takes about thirty seconds to run, and it gives you a table you can paste straight into a PR description.

Why does the server need to be free? Because the whole point of rehearsal is that you run it often, and you will not run it often if every run costs you money or a ticket. Localhost flatters you: TLS works, DNS works, cold starts do not exist, and the proxy limit is whatever you imagine it to be. A real server, even a free one, has real network boundaries, real timeouts, and real proxy layers between you and the model, and those are exactly the layers that fail in production. Think of the free server as a rehearsal room rather than a stage; you are not performing for users, you are practicing the parts that usually go wrong.

You might object that the model is the unpredictable part, and you are right that its output is unpredictable. But unpredictability is not the same as unreliability: the model returns a string, your proxy returns a 502, and one of those is your code. How many teams are spending their week comparing model names when their real failure is a 413 they have never once triggered? The cheapest failure is the one you have already seen, because you have already written the fix for it.

Now the honest limits, because this approach is not for everyone. If your bottleneck is genuinely prompt quality, meaning you are doing research rather than shipping, free tokens will not fix your prompt design and rehearsal will not help you. If you operate under data-residency rules, do not put customer data on a free server just because it is free, because compliance does not care about your budget. And do not build a production business on a free allowance, because a free allowance is a rehearsal budget, not a business model; treat the ten million tokens as fuel for finding handoff bugs and meter your real traffic separately. The same logic applies to the free server: it is a staging tool, so treat it like one and keep your real infrastructure separate.

Here is the checklist I reuse on every AI slice now. Deploy the proxy to the free server before you tune the prompt. Run the rehearsal script on every deploy, not just the first one. Treat every non-200 as a handoff bug until you have proven otherwise. Spend the free tokens on rehearsals rather than demos, and tear the server down when the sprint ends so the next sprint starts from a clean slate.

If you want to see where your own feature actually fails, deploy the proxy, run the script, and read the table with fresh eyes. The model will be fine, and the question is whether your handoffs are; MonkeyCode's free tokens and free server are a cheap place to start that rehearsal, and the project is open source if you want to look under the hood. Which handoff is least stable in your stack, and what response code does it return when it breaks?

MonkeyCode provides free models that can run this workflow.

Top comments (0)