Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatible

Đang mở Phù hợp với người mới
#1,085 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api, backend

Hướng nghiên cứu

Tìm bộ xác thực yêu cầu của /v1/messages và mô hình của nó cho messages[].role; issue xác định giới hạn vai trò là điểm gây lỗi. Trước tiên, hãy đọc bộ xác thực và các kiểm thử yêu cầu của nó, sau đó kiểm tra cách các thông điệp đã được xác thực được chuyển tiếp upstream. Công việc hoàn tất khi một thông điệp có vai trò system sau lượt của user vượt qua bước xác thực và các trường hợp user và assistant hiện có vẫn hoạt động.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatible

Summary

The Provider Anthropic Messages endpoint validates messages[].role against only user/assistant and returns:

{"type":"error","error":{"type":"invalid_request_error","message":"Invalid input at messages.1.role"}}

This breaks vanilla Claude Code ≥ 2.1.154, which sends a system-role message inside messages[] (a still-open regression: anthropics/claude-code#63469). Your own command-code CLI sends the legacy shape and works — vanilla Claude Code against api.commandcode.ai/provider does not.

Repro (curl, max_tokens 2 — both uncharged/zero-cost)

Works (control, legacy shape):

curl https://api.commandcode.ai/provider/v1/messages \
  -H "Authorization: Bearer $CMD_PROVIDER_API_KEY" \
  -H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
  -d '{"model":"claude-haiku-5-5","max_tokens":2,"messages":[{"role":"user","content":"hi"}]}'
# → HTTP 200, normal completion

Fails with 400 Invalid input at messages.0.role (system-role message):

curl https://api.commandcode.ai/provider/v1/messages \
  -H "Authorization: Bearer $CMD_PROVIDER_API_KEY" \
  -H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
  -d '{"model":"claude-haiku-5-5","max_tokens":2,"messages":[{"role":"system","content":"You reply tersely."},{"role":"user","content":"hi"}]}'

Verified 2026-10-29: identical 400 on every Claude model in the catalog — claude-opus-5-5, claude-opus-5, claude-sonnet-5-5, claude-sonnet-4-6, claude-fable-5-1, claude-haiku-5-5 (so it's central validation, not per-upstream). The failure fires before upstream routing model-level plan checks fire earlier; the schema gate is the blocker.

Why this is valid per Anthropic's own API

Working with Messages API → System role in messages documents mid-conversation system messages on Opus 5/5.5, Sonnet 5/5.5, Haiku 5.5, Fable/Mythos 5.x, Opus 4.8 — legal after a user turn (only messages[0] is excluded, and Claude Code ≥ 2.1.154 places it after the first user message). First-party api.anthropic.com accepts this since Claude Code 2.1.154 onward.

References

  • anthropics/claude-code#63469 — regression thread: Claude Code started sending messages[].role="system" in 2.1.154; still unfixed upstream (closed stale 2026-08); broke DeepSeek/GLM/Kimi-compatible gateways for 5 months
  • free-claude-code#611 — a third-party Anthropic-compatible server fixed exactly this by widening its role validator to include "system" (then merging/forwarding)
  • Your docs example requests only ever use user messages, so the docs and validator are consistent today — but Claude Code (the highest-volume /v1/messages client) is not

Suggested fix

In the /v1/messages request validator, allow "system" alongside user|assistant for messages[].role (≈10 lines in the pydantic model: role: Literal["user","assistant","system"]), then either forward as-is to system-role-aware upstreams (Anthropic's newer API accepts it on the 5.x families) or pre-merge system-role messages into the top-level system param for legacy upstreams. The free-claude-code fix is the minimal version and has been in production for 5 months.

Environment: macOS, Claude Code 2.1.308 (Homebrew cask), Provider plan key. happy to provide more traces (request captured verbatim via local listener: anthropic-beta headers list included).

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
4.2k
Fork
372
Merge trung bình
4 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CommandCodeAI/command-code

Tất cả issue của CommandCodeAI/command-code

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.