跳到正文
DEV Community· UncensoredAI (uncensoredai.click)·· 1 小時前AI 評分48

DeepSeek V4.1 Flash 與深度推理模型的雙層路由:串流速度比較及 Agent 應用

Two-Tier Routing for Coding & Authorized Security Agents: Measuring DeepSeek V4.1 Flash Streaming Speed (~198 tok/s) vs. Deep Reasoning Models

AI 導讀

UncensoredAI 實測 DeepSeek V4.1 Flash 1017 的 Fast 路由中位串流輸出速度為 197.66 tok/s,約為 Standard 路由的 3.8 倍,並提出以雙層路由分配 Agent 工作。Fast 路由適合高頻工具呼叫,複雜推理及程式碼審核則交由 Kimi-K3.1-Pro-Uncensored-Cyber;兩者上下文窗口均為 1M。

正文

Disclosure: I build and operate UncensoredAI, the OpenAI-compatible gateway used in the measurements below. I used an AI assistant to help tighten the wording of this write-up; all benchmark numbers, model IDs, and code patterns were verified against our live endpoints.

If you build multi-step coding agents, automated repo auditors, or authorized security / CTF harnesses, two practical engineering problems show up fast:

  1. Mid-loop false refusals: An agent spends 30K tokens gathering context, then hits an unnecessary refusal on step 7 because a file mentions a vulnerability class or exploit test case — wasting the whole trajectory.
  2. Routing cost vs. latency: Sending every routine file read, grep summary, and tool call to a heavy reasoning model burns budget and stalls interactive workflows.

A much cleaner architecture is two-tier routing behind a single OpenAI-compatible client: send high-frequency worker/tool-calling turns to a fast, lower-refusal open model, and escalate only deep reasoning or complex code-audit steps to a heavier reasoning specialist.


1. How We Measure Streaming Throughput (And Why Standard vs. Fast Matters)

Headline "tokens per second" claims are easy to game with 100-token toy prompts. For real agent workloads, long-context prefill plus sustained long output is what actually affects wall-clock latency.

We measured our two DeepSeek V4.1 Flash 1017 lower-refusal routes using direct streaming requests with:

  • 32K uncached input tokens
  • 4K output tokens
  • Reasoning off, concurrency 1, 5 runs per route (reporting the median)
Route Exact Model ID Median Completion Median Sustained Output Reference Rate / 1M (In / Cached / Out)
DeepSeek 1017 Fast DeepSeek_V4.1_Flash_1017_Fast_Uncensored 36.07 s 197.66 tok/s $0.1755 / $0.036 / $0.585
DeepSeek 1017 Standard DeepSeek_V4.1_Flash_1017_Uncensored 138.32 s 74.66 tok/s $0.1755 / $0.0312 / $0.585

Both routes serve the same underlying model capabilities at the same input/output token rate; the difference is pure serving throughput (~3.8× faster median completion on Fast).

For quality sanity-checking, we also ran a paired GPQA Diamond evaluation (2026-11-10, completed responses) on the Standard route (DeepSeek_V4.1_Flash_1017_Uncensored, same base weights as Fast):

  • Official DeepSeek API: 94.82% ($3.4644 estimated cost for the test workload)
  • UncensoredAI route: 93.78% (1.04pp gap, $1.2392 estimated cost at published rates — 64.2% lower)

DeepSeek V4.1 Flash 1017 streaming benchmark and Standard-route GPQA comparison


2. When to Switch Tiers in an Agent Loop

In practice, splitting turns by tool-calling vs. deep reasoning keeps both latency and cost predictable:

  • Tier 1 — Worker & Tool-Calling Loop (DeepSeek_V4.1_Flash_1017_Fast_Uncensored)
    • 1M context window, streaming, and verified native function tool calling.
    • Best for high-frequency steps: reading files, parsing scanner output, running MCP tool loops, and iterative code edits.
    • Because prompt caching drops repeated repo context down to $0.036 / 1M, 30-turn agent loops stay cheap (~$0.0007 for a typical 3K-in / 300-out turn even before caching).
  • Tier 2 — Deep Reasoning & Authorized Code Audit (Kimi-K3.1-Pro-Uncensored-Cyber)
    • 1M context window, visible reasoning_content trace, up to 32K output tokens ($3.71 in / $0.35 cached / $5.42 out per 1M).
    • Best reserved for hard root-cause analysis, CTF problem breakdown, and complex patch review.
    • Implementation caveat: Native tool calling is not currently advertised on Kimi here, so keep tool-execution turns on Tier 1 and pass structured summaries up to Tier 2 when you need deeper reasoning.

3. Minimal Python Two-Tier Streaming Pattern

Both models use the standard openai Python SDK over https://uncensoredai.click/v1. One small detail that trips people up with reasoning models: always separate delta.reasoning_content from delta.content so reasoning traces don't pollute downstream JSON parsers.

import os
import sys
import time
from openai import OpenAI

client = OpenAI(
    base_url="https://uncensoredai.click/v1",
    api_key=os.environ["UNCENSOREDAI_API_KEY"],
    timeout=600.0,
    max_retries=0,
)

FAST_WORKER = "DeepSeek_V4.1_Flash_1017_Fast_Uncensored"
DEEP_CYBER = "Kimi-K3.1-Pro-Uncensored-Cyber"


def run_step(messages, deep=False, max_tokens=2048):
    model = DEEP_CYBER if deep else FAST_WORKER
    kwargs = {
        "model": model,
        "messages": messages,
        "max_tokens": 16000 if deep else max_tokens,
        "stream": True,
        "stream_options": {"include_usage": True},
    }
    if deep:
        kwargs["reasoning_effort"] = "low"

    t0 = time.perf_counter()
    first_token_at = None
    out = []

    stream = client.chat.completions.create(**kwargs)
    for chunk in stream:
        if chunk.usage:
            elapsed = time.perf_counter() - t0
            ttft = (first_token_at - t0) if first_token_at else elapsed
            print(
                f"\n[{model}] ttft={ttft:.2f}s total={elapsed:.2f}s usage={chunk.usage}",
                file=sys.stderr,
            )
        if not chunk.choices:
            continue
        delta = chunk.choices[0].delta
        reasoning = getattr(delta, "reasoning_content", None)
        if isinstance(reasoning, str) and reasoning:
            if first_token_at is None:
                first_token_at = time.perf_counter()
            sys.stderr.write(reasoning)
        if isinstance(delta.content, str) and delta.content:
            if first_token_at is None:
                first_token_at = time.perf_counter()
            sys.stdout.write(delta.content)
            sys.stdout.flush()
            out.append(delta.content)
    print()
    return "".join(out)


if __name__ == "__main__":
    # Tier 1: fast worker / triage step
    run_step(
        [{"role": "user", "content": "Explain Nginx alias path traversal and show a safe config fix."}],
        deep=False,
    )

4. Two Practical Guardrails for Autonomous Loops

Regardless of which OpenAI-compatible provider you plug into an autonomous agent, two operational safeguards save a lot of grief:

  1. Hard per-API-key USD spending limits: Isolate each agent harness on its own API key with a strict dollar cap. If a retry loop bugs out overnight, the key hits its ceiling instead of draining your whole account.
  2. Clear prompt-retention boundaries: For code audits or authorized pentest outputs, verify whether the gateway itself logs prompt/response bodies vs. billing metadata only. On UncensoredAI, /v1 API prompt and response text are not stored on our servers (only operational/billing metadata is retained; upstream inference providers handle requests under their own policies).

References

Note: Security-oriented models are strictly for authorized testing, CTF competitions, defensive research, and systems you own or have written permission to test.

Curious how others are splitting worker vs. reasoning models in their coding or security harnesses — what's your current latency/cost threshold for switching tiers?

來源:DEV Community · dev.to