pi-commandcode-provider icon indicating copy to clipboard operation
pi-commandcode-provider copied to clipboard

Bug: invalid request "input item is missing type" on zai-org/GLM-5.3

Open ThomasByr opened this issue 2 weeks ago • 2 comments

Safe diagnostics

plugin: 0.8.2                                                                                                                                                                                                                                                                            
 host: pi 1.5.2                                                                                                                                                                                                                                                                           
 catalog CLI: 1.88.5                                                                                                                                                                                                                                                                      
 model: zai-org/GLM-5.3                                                                                                                                                                                                                                                                   
 route: unknown/openai-responses                                                                                                                                                                                                                                                          
 capabilities: bundled snapshot; host overrides may apply                                                                                                                                                                                                                                 
 price: known (verified 2026-11-11; estimate, not billing)                                                                                                                                                                                                                                
 last request: none                                                                                                                                                                                                                                                                       
 Timing measures received body chunks, not tokens. No prompts, tool content, credentials, account data or configured local paths are collected. Model IDs come from the host; review custom names before sharing.                                                                         
 model endpoint: openai-responses (auto; catalog)

Plan

Max

Minimal reproduction

first message: "hey" with model zai-org/GLM-5.3

Error and timing

Error: commandcode API error (400): {"message":"{\"error\":{\"code\":\"invalid_request\",\"details\":{},\"message\":\"input item is missing                                                                                                                                              
 type\",\"param\":null,\"request_id\":\"req_bxxx\",\"type\":\"invalid_request_error\"}}","type":"invalid_request_error"} 

Exact same setup while using deepseek/deepseek-v4.1-flash just works. Edit Selecting chat-completions for zai-org/GLM-5.3 also works: Pi does not report any suspicious cache misses for that model on completions but I'm unsure if caching works on completions for that model.

ThomasByr avatar Nov 13 '26 07:11 ThomasByr

Thanks for the precise report — it reproduced exactly, and it turned out to be two stacked causes, not one. I probed the live Provider API with a minimal text-only request ("hey", max_output_tokens: 16) against zai-org/GLM-5.3 in four configurations:

Request body Result
input items as pi sends them today, no reasoning field 400 invalid_request: input item is missing type
input items with type: "message", no reasoning field 200, full SSE stream
input items with type: "message" + reasoning: {effort: "none"} 400 unsupported output_config.effort: none
input items as pi sends them today + reasoning: {effort: "none"} 400 input item is missing type

So the missing item type is real, and it is independent of reasoning — removing reasoning alone still fails (row 1). But fixing it alone is not enough either: once the input is accepted, effort: "none" is refused (row 3).

Why the items are untagged

The Responses body is built by the host encoder, not by this extension: pi-ai only tags non-message items (type: "message" for assistant text, function_call, function_call_output, reasoning). The leading system/developer item and every user item go out as a bare {role, content} pair. OpenAI accepts that shorthand; the adapter in front of GLM-5.3 does not. I confirmed it by driving the installed pi-ai encoder directly and dumping the body it produces for this model — the very first turn emits a single untagged {role: "user", ...} item.

Why effort: "none" is sent

When thinking is off, pi-ai reads the level from thinkingLevelMap and falls back to "none". Declaring off: null does not fix it: pi then clamps to the lowest allowed level and sends effort: "low", which silently forces reasoning on instead of disabling it. Omitting the reasoning field is what actually works.

Not specific to GLM-5.3

I swept all 74 models that advertise /responses with the same minimal request:

  • untagged input items refused by exactly one model: zai-org/GLM-5.3. Every other /responses model accepts the shorthand, so this is an adapter quirk, not a general defect of the Responses route.
  • effort: "none" refused by two models: zai-org/GLM-5.3 (unsupported output_config.effort: none) and mistral/mistral-large-4 (reasoning_effort none is not supported for this model, supported values: [high, low, ...]). mistral-large-4 accepts the shorthand fine and answers 200 with effort: "low" or with no reasoning field at all — it is broken the same way for anyone running it with thinking off, unrelated to this issue.

Two unrelated observations from the sweep, worth separate issues: Qwen/Qwen3.6-Max-Preview and stepfun/Step-3.5-Flash are still advertised by /provider/v1/models but answer 404 Model '...' not found.

Workaround available today

/commandcode-endpoint zai-org/GLM-5.3 chat-completions (you already found it) — it works because Chat Completions has a different encoder. Same command fixes mistral/mistral-large-4.

Fix

A per-model repair table in the Responses fetch wrapper: add type: "message" to role-carrying input items for GLM-5.3, and drop a reasoning block that only says effort: "none" for both models. Everything else passes through byte-identical — other models, malformed JSON, non-object bodies, and already-tagged items are untouched. Both repairs are keyed off live evidence, so no other backend's request changes.

Locally: tsc --noEmit, Prettier, 13 new unit tests over the rewrite, and the full npm test suite against real hosts are green. I'll open a PR shortly and link it here. Nothing has been released for this yet.

pierreraby avatar Nov 13 '26 11:11 pierreraby

Confirmed and fixed in #215 (merged as 6094904), which is on main now.

Post-merge verification with the bodies the fix actually produces:

model / body result
zai-org/GLM-5.3, tagged items, no reasoning 200, real answer, 1 reasoning token
mistral/mistral-large-4, untouched items, no reasoning 200, real answer, 228 reasoning tokens / 265 output

One caveat worth knowing when you re-test by hand: mistral-large-4 reasons by default even with no reasoning field, so a small max_output_tokens gets spent entirely on reasoning and the answer arrives empty. That is not a wire failure — it shows up as 200 with 0 text deltas and a large reasoning_tokens. With a realistic budget it answers normally.

The merged change adds type: "message" to the system/user items for GLM-5.3 and drops the inert reasoning block for both GLM-5.3 and mistral/mistral-large-4; every other model's request body is untouched. Until a release is cut, /commandcode-endpoint zai-org/GLM-5.3 chat-completions remains the workaround on 0.8.2.

Closing this issue — the pricing gate is green again on main and a patch release will follow.

pierreraby avatar Nov 13 '26 11:11 pierreraby