DEV Community

Cover image for Refusals that come back as HTTP 200, and why they break agents
Dennison Bertram
Dennison Bertram

Posted on

Refusals that come back as HTTP 200, and why they break agents

You ask your coding agent to check your own app for a security bug. It reads a few files, then stops. No error. No red text. Just a polite paragraph saying it can't help with that, and a prompt waiting for you.

Every log says the request succeeded. And it did. The provider returned HTTP 200, the stream finished cleanly, and the model said no.

This post explains why a refusal is invisible to the parts of an agent built to handle failure. I'll walk through the request path in FreePi, a free AI coding agent for the terminal, and show where an error gets caught and where a refusal slips through. Then I'll cover what you can actually do about it.

Try it: run npx free-pi-cli@latest in a terminal.

Give this to your agent: freepi.ai/llms.txt

Two kinds of "no"

An API can say no in two ways.

The first is an error. The HTTP status is 4xx or 5xx, or the stream carries an error object instead of text. Code can see this. You check the status, you retry, you switch providers.

The second is a refusal. The model ran, produced tokens, and those tokens happen to say "I can't help with that." To the transport layer this is a perfect response. Status 200. Normal text deltas. A clean finish.

Here's what a refusal looks like on the wire, as an example of an OpenAI-compatible reply:

{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "I can't help with exploiting that."
    },
    "finish_reason": "stop"
  }]
}
Enter fullscreen mode Exit fullscreen mode

Nothing in that body is an error. It's shaped exactly like a correct answer.

Where errors get caught

FreePi's server sits between the CLI and the model providers. When a provider fails, it moves on to the next step in a fallback chain.

The tricky part is streaming. Once a server sends a 200 status line to the client, it can't take it back. So FreePi's server waits before committing. A comment in the completions route says it plainly: read far enough to see the first real data: frame before committing to a 200, so an error frame that arrives there can still become a 502.

While it waits, these all count as failures. If there's another step in the chain, the server moves on to it:

  • Timeout. No first token before the deadline.
  • Error frame. The provider streamed an error object.
  • Empty stream. The stream ended with nothing in it.
  • Bad status. The provider answered with anything other than 2xx.

For some routes, the server only commits on what the code calls a substantive delta: content, reasoning or a tool call. An empty role frame isn't enough.

That's a decent safety net. Now look at what a refusal does to it. The first frame is content. It's substantive. The server commits the 200 and streams it to you. By every rule in that code, this was a success, and the attempt is recorded as one.

No router can catch that without reading what the text means. Status codes and frame types don't carry it.

Where the agent loop stops

The CLI runs the pi coding agent. pi's agent loop is simple at its core. After each model reply, it checks for tool calls:

const toolCalls = message.content.filter(
  (c) => c.type === "toolCall"
);
hasMoreToolCalls = false;
if (toolCalls.length > 0) {
  // run the tools, then ask the model again
}
Enter fullscreen mode Exit fullscreen mode

If the reply has tool calls, the loop runs them and goes around again. If it doesn't, the loop has nothing left to do. Unless something queues another message, the agent stops and hands control back to you.

A refusal has no tool calls. So from the loop's point of view, the model just finished the task. That's the break. A long task doesn't fail, it ends. You come back expecting a patched file and find a paragraph.

A provider that refuses with a status code

FreePi's image route is a useful contrast. Image providers can decline with a real HTTP error, with a body that names the reason.

The server checks 400, 403 and 422 responses against a pattern:

const REFUSAL_RE =
  /moderat|content[ _-]?policy|safety|blocked/i;
Enter fullscreen mode Exit fullscreen mode

That's trimmed. The real pattern also matches "prohibited", "not allowed" and "violat".

When it matches, the server returns its own 422 with the code content_rejected and the message "the image provider declined this prompt". It also skips the fallback model on purpose. A fallback is for broken providers. A policy decision isn't broken, so retrying it elsewhere is the wrong move.

That only works because the "no" arrived as a status code. Chat refusals don't, so the same trick isn't available.

What you can do about it

You have three options, and they stack.

1. Detect it in your own harness. A refusal has a recognizable shape: the model stopped normally, made no tool calls, and the text is short and apologetic. If you build agents, you can check for that shape at the point where the loop would stop:

function looksLikeRefusal(text: string) {
  const t = text.slice(0, 300).toLowerCase();
  return /i can('|no)t (help|assist)|i won't/.test(t);
}
Enter fullscreen mode Exit fullscreen mode

This is a heuristic, not a fix. It will miss refusals worded differently and flag some honest answers. Use it to tell the user what happened, not to retry silently.

2. Give the model the context it needs. Some refusals on security work come from missing context. Say who owns the system and what you're allowed to do. "This is my own staging app. I want to confirm this endpoint leaks other users' records, then fix it." Ask for the fix and a test, not just the exploit.

3. Use a model that refuses less, for authorized work. This is why FreePi has a Defense section in /model. It lists low-refusal models, including abliterated ones, under a separate free-pi-defense provider. Today that includes models like Abliterated Large Flash, DeepSeek V4.1 Flash Abliterated and GLM 4.7 Flash Heretic. You opt in by picking one. They're for signed-in users only. The server refuses a guest's request for one before it reaches a model.

These models are for systems you own or have written permission to test, and bug bounty targets inside the program's scope. Picking one doesn't change what you're legally allowed to do.

Wrapping up

A refusal is a successful HTTP response that says no. Status checks, error frames, timeouts and fallbacks all pass it straight through, and an agent loop treats it as a finished task because it has no tool calls. Catch it by its shape in your harness, give the model real context, and for authorized security work, use a model that won't stall on it.

If you want to try that last part, FreePi is free and runs in your terminal. Grab it at www.freepi.ai or run npx free-pi-cli@latest.

Top comments (0)