Skip to content

Claude Code 2.1.263 can send system inside messages, causing 422 validation error #1

Description

@albCarlosRodrigues

When using Claude Code v2.1.263 against free-claude-code on Windows, the proxy can reject a request with HTTP 422 because Claude Code sends a message entry whose role is system.

The error returned to Claude Code is:

API Error: 422 {"detail":[{"type":"literal_error","loc":["body","messages",1,"role"]

The proxy log shows:

POST /v1/messages?beta=true HTTP/1.1" 422 Unprocessable Content

Environment

OS: Windows

Shell: PowerShell

Claude Code: v2.1.263

Proxy started with:

uv run uvicorn server:app --host 0.0.0.0 --port 8082

Claude Code started with:

$env:ANTHROPIC_AUTH_TOKEN="freecc"
$env:ANTHROPIC_BASE_URL="http://localhost:8082"
claude

Steps to reproduce

Start the free-claude-code proxy on port 8082.

Point Claude Code to the proxy using ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN.

Start Claude Code v2.1.263.

Send a simple prompt, for example:

Responda apenas: funcionando

One of the /v1/messages?beta=true requests is rejected with HTTP 422.

Suspected cause

In api/models/anthropic.py, Role includes system, but Message.role only accepts:

Literal["user", "assistant"]

So a system entry inside messages fails Pydantic validation.

There is also a related issue in core/anthropic/conversion.py: list-content handling explicitly branches only for assistant and user, so accepting system in the model alone may not be enough.

Workaround tested

Locally, changing:

role: Literal["user", "assistant"]

to:

role: Literal["user", "assistant", "system"]

and adding handling for system list content in the Anthropic-to-OpenAI converter allowed the request to get past the 422 validation error.

After this change, the proxy was able to continue processing the request successfully.

Expected behavior

The proxy should accept the request format currently emitted by Claude Code v2.1.263 and correctly normalize system messages instead of returning HTTP 422.

Additional note

I can provide a PR with the compatibility fix if needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions