跳到正文
DEV Community· Florian·· 4 小時前AI 評分49

省略 reasoning_effort 不等於傳送 none

Omitting reasoning_effort is not the same as sending none

AI 導讀

模型設定登錄表必須區分傳送 reasoning_effort: "none" 與完全省略欄位,否則請求可能失去預期行為或直接失敗。Luna 需要傳送 "none",Gemini flash-lite 則不接受 reasoning_effort;設定為 null 才代表省略欄位,Terra 使用 "low"。

正文

A registry that stores reasoningEffort can hold two different empties. One means send none. The other means leave the field out. They sit in the same config. On the wire they are different requests.

Two models, two meanings of nothing

Luna is the fast path. It stays real-time only when the request explicitly carries reasoning_effort: "none", with a 15 second timeout. Leaving the field out is a different request, and it does not get that behavior.

Terra sits one step up: reasoning_effort: "low", timeout 25 seconds.

Gemini flash-lite is the awkward case. The OpenAI-compatible endpoint rejects reasoning_effort and thinking_level. The call fails because the key is in the body. The value does not matter, so sending none still fails.

The registry has to keep those apart:

type ReasoningEffort = "none" | "low" | null;

interface ModelConfig {
  id: string;
  // null means: do not put the field in the request body at all
  reasoningEffort: ReasoningEffort;
  timeoutMs?: number;
}

const MODELS: ModelConfig[] = [
  { id: "luna", reasoningEffort: "none", timeoutMs: 15_000 },
  { id: "terra", reasoningEffort: "low", timeoutMs: 25_000 },
  { id: "gemini-flash-lite", reasoningEffort: null },
];

The null on flash-lite is written that way on purpose. It means omit the field. Luna's none means send none. Fold both into the same empty and one of the two calls breaks.

Where it breaks

Any code that treats the two empties as the same will hit this. It can go either way.

Somebody tidies the request builder and treats none as the default:

if (cfg.reasoningEffort && cfg.reasoningEffort !== "none") {
  body.reasoning_effort = cfg.reasoningEffort;
}

Luna now goes out without the field. Nothing errors. It just stops being the real-time model the registry described.

Or every request is made explicit:

body.reasoning_effort = cfg.reasoningEffort ?? "none";

Every flash-lite call fails, because the field is present.

Each change looks reasonable in review. Each one fixes one model by breaking the other. A loader that coerces missing values to one shared default does the same thing without anyone touching the request builder.

The builder that respects both

Branch on null, and pass everything else through.

function buildBody(cfg: ModelConfig, messages: unknown[]) {
  const body: Record<string, unknown> = { model: cfg.id, messages };
  if (cfg.reasoningEffort !== null) {
    body.reasoning_effort = cfg.reasoningEffort;
  }
  return body;
}

Test the serialized body, not the config object. The Luna payload should contain reasoning_effort set to none. The flash-lite payload should not contain the key. Check what the serializer does with null too. If it writes "reasoning_effort": null, the key is in the body.

The picker and the resolver are different lists

getAllModels() is the list the picker shows. It does not expose internal models. getModelConfig still returns config for those ids.

Ids that leave the picker stay in INTERNAL_MODELS. A session that already started on that id can still resolve it, and a rollback does not need a redeploy. The moved entry keeps the same reasoningEffort. That is the config the in-flight session still asks for.

I build LiveSuggest, a meeting assistant that stays on your screen. No bot joins the call.

來源:DEV Community · dev.to