Skip to content

Bug reports: Claude Code system-role message in messages[] causes HTTP 422 on GLM #74

Description

@chgwan

System Info / 系統信息

Notes

  • Affected models observed: glm-4.6, glm-5.1.
  • Client: Claude Code 2.1.156.
  • Current client-side workaround: a local proxy that moves system-role
    messages into the top-level system field before the request reaches GLM.

Your Anthropic-compatible endpoint (/api/anthropic/v1/messages) returns
HTTP 422 when the messages array contains an entry with role: "system":

422 {"detail":[{"type":"literal_error","loc":["body","messages",1,"role"],
 "msg":"Input should be 'user' or 'assistant'","input":"system",
 "ctx":{"expected":"'user' or 'assistant'"}}]}

The official Anthropic Messages API accepts such requests (it effectively folds
system-role message content into system handling rather than rejecting the
request). Tools built against the Anthropic API — notably Claude Code, which
injects hook/session context as a system-role message in messages[] — send
this shape and therefore fail against GLM while succeeding against Anthropic.

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

A) Accepted today → HTTP 200

curl -s -w "\nHTTP %{http_code}\n" \
  https://open.bigmodel.cn/api/anthropic/v1/messages \
  -H "Authorization: Bearer <TOKEN>" \
  -H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
  -d '{"model":"glm-4.6","max_tokens":20,"system":"You are helpful.",
       "messages":[{"role":"user","content":"Hello"}]}'

B) Rejected today → HTTP 422 (only difference: a system entry in messages)

curl -s -w "\nHTTP %{http_code}\n" \
  https://open.bigmodel.cn/api/anthropic/v1/messages \
  -H "Authorization: Bearer <TOKEN>" \
  -H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
  -d '{"model":"glm-4.6","max_tokens":20,
       "messages":[{"role":"user","content":"ctx"},
                   {"role":"system","content":"injected"},
                   {"role":"user","content":"Hello"}]}'

C plugin test in Claude Code

  1. Enable any plugin with a SessionStart hook that emits additionalContext
    (e.g. the superpowers plugin, which injects its using-superpowers skill text).
  2. Point Claude Code at an Anthropic-compatible endpoint that strictly validates
    message roles (GLM/Zhipu):
    • ANTHROPIC_BASE_URL=https://open.bigmodel.cn/api/anthropic
    • ANTHROPIC_AUTH_TOKEN=<token>, model glm-4.6 / glm-5.1
  3. Start an interactive session and send any message ("Hello").
  4. 422 on the first turn, every turn.

Expected behavior / 期待表现

Requested fix (either is sufficient)

  1. Tolerate system-role entries in messages[]: fold their content into
    the system prompt instead of returning 422 (match Anthropic's behavior); or
  2. Document the strict behavior and, ideally, normalize on the server side so
    Anthropic-targeted clients work unmodified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions