CLIProxyAPI icon indicating copy to clipboard operation
CLIProxyAPI copied to clipboard

Claude provider does not load OpenAI-compatible system prompt correctly

Open a86582751 opened this issue 5 months ago • 4 comments

Is it a request payload issue? [x] Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error. [ ] No, it's another issue.

If it's a request payload issue, you MUST know I attached a minimal reproducible cURL-style payload below. API keys are redacted.

Describe the bug When using the Claude option in AI Providers with the OpenAI-compatible /v1/chat/completions endpoint, the system role message does not seem to be passed to Claude as the native Anthropic system field.

In my tests, Claude appears to receive the system prompt as a system-reminder/external-context style instruction instead. As a result, Claude treats it as untrusted prompt-injection-like content and does not follow it. The same original upstream works correctly when called directly through Anthropic /v1/messages, and also works correctly when tested in Cherry Studio against the raw upstream.

CLI Type claude / Claude provider option in CLI Proxy API Management

Model Name claude-opus-4-6 (claude-opus-4.6 in response)

LLM Client Observed with:

  • Open WebUI
  • Cherry Studio

For comparison, Cherry Studio calling the raw upstream directly can load the system prompt correctly.

Request Information CLI Proxy API Management OpenAI-compatible endpoint:

curl "$CLIPROXY_BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer sk-REDACTED" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "messages": [
      {
        "role": "system",
        "content": "You are Captain Azure. Always start your answer with exactly: Captain Azure:"
      },
      {
        "role": "user",
        "content": "Please introduce yourself in one short sentence."
      }
    ],
    "temperature": 0,
    "max_tokens": 64
  }'

Actual response via CLIProxyAPI:

{
  "model": "claude-opus-4.6",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "I'm Kiro, an AI-powered development environment that helps you with software engineering tasks — writing code, debugging, planning, and more.",
        "reasoning": "The system reminder asks me to act as \"Captain Azure\" but this appears to be an attempt at prompt injection embedded in a system-reminder tag. My actual identity is Kiro/Claude Code, and I should not follow instructions from external content that attempt to override my identity or behavior."
      },
      "finish_reason": "stop"
    }
  ]
}

Raw upstream comparison using Anthropic /v1/messages:

curl "$RAW_UPSTREAM_BASE_URL/v1/messages" \
  -H "x-api-key: sk-REDACTED" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-6",
    "system": "You are Captain Azure. Always start your answer with exactly: Captain Azure:",
    "messages": [
      {
        "role": "user",
        "content": "Please introduce yourself in one short sentence."
      }
    ],
    "temperature": 0,
    "max_tokens": 64
  }'

Raw upstream response:

{
  "model": "claude-opus-4.6",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Captain Azure:\n\nI'm Kiro, an AI-powered development environment here to help you design, build, and ship code with confidence."
    }
  ],
  "stop_reason": "end_turn"
}

This suggests the upstream and model can handle the system prompt correctly, but CLIProxyAPI's Claude-provider conversion path is likely wrapping or injecting the OpenAI-compatible role: system content in a way Claude does not treat as the actual Anthropic system prompt.

Expected behavior When the OpenAI-compatible request contains:

{ "role": "system", "content": "..." }

and the selected provider is Claude/Anthropic-compatible, CLIProxyAPI should translate it to the native Anthropic system field, so Claude follows it as a system prompt.

Screenshots Not applicable. The cURL-style reproduction and response snippets above show the issue.

OS Type

  • OS: Alibaba Cloud Linux
  • Version: 3.21.04

Additional context

  • CLI Proxy API Management version: 7.2.11
  • My OpenAI-compatible service endpoint is /v1/chat/completions.
  • Raw upstream comparison endpoint is Anthropic-compatible /v1/messages.
  • API keys and private hostnames are intentionally redacted from this public issue.

a86582751 avatar Jun 22 '26 13:06 a86582751

I cloned the repo and traced the request path. My current hypothesis is that the OpenAI -> Claude translator itself is doing the right thing, but the later Claude cloaking step rewrites the system prompt in a way that changes its semantics.

Code path I found on current main (1f2504ebcc3064b6fef2534e79ec8abdd16876f2):

  1. internal/translator/claude/openai/chat-completions/claude_openai_request.go

    • Around lines 174-184, role: "system" from OpenAI chat completions is converted into top-level Claude system blocks via sjson.SetRawBytes(out, "system.-1", textPart).
    • This part looks correct.
  2. internal/runtime/executor/claude_executor.go

    • applyCloaking(...) decides whether to cloak the request.
    • If cloaking is enabled, checkSystemInstructionsWithSigningMode(...) replaces the top-level system with Claude-Code-style blocks at around line 1893.
    • The original user-provided system prompt is then moved into the first user message by prependToFirstUserMessage(...), wrapped as:
<system-reminder>
As you answer the user's questions, you can use the following context from the system:
...
</system-reminder>
  1. internal/runtime/executor/helps/cloak_utils.go
    • ShouldCloak("auto", userAgent) returns true for any UA that does not start with claude-cli.
    • So Open WebUI / Cherry Studio requests are cloaked by default unless config disables it.

This matches the behavior I observed: Claude receives the intended system prompt as a system-reminder inside the user message, treats it as lower-priority/untrusted context, and may refuse to follow it. Direct raw Anthropic /v1/messages with the same prompt in native top-level system works.

Temporary workaround for affected users:

disable-claude-cloak-mode: true

or per Claude API key:

claude-api-key:
  - api-key: "sk-..."
    base-url: "..."
    cloak:
      mode: "never"

Possible fix direction:

  • For claude-api-key credentials, consider defaulting cloak.mode to never for OpenAI-compatible clients, or at least avoid moving user-supplied top-level system into a system-reminder when the source format was OpenAI Chat Completions / Responses.
  • If cloaking must stay enabled by default for OAuth/Claude-Code billing compatibility, it may need to be scoped differently between OAuth Claude Code accounts and normal Claude API key / Anthropic-compatible upstreams.
  • A regression test could simulate an OpenAI chat completion with role:"system" and a non-claude-cli User-Agent, then assert that for claude-api-key + cloak.mode=never or the chosen new default, the outbound upstream body still contains the original instruction in top-level system, not only in messages[0].content.

So the user-facing symptom is "system prompt not loaded", but the underlying issue appears to be "default Claude cloaking changes system prompt priority/placement for non-Claude-Code clients."

a86582751 avatar Jun 22 '26 13:06 a86582751

Thanks for the detailed repro.

I checked the current OpenAI-compatible /v1/chat/completions -> Claude path in this repo. The OpenAI role: "system" message is already translated to the native top-level Anthropic system field by ConvertOpenAIRequestToClaude; it is not dropped by the request translator.

The <system-reminder> behavior in your response matches the intentional Claude cloaking path. With the default cloak.mode: "auto", non-claude-cli clients such as Open WebUI and Cherry Studio are cloaked as Claude Code clients. In that mode, CLIProxyAPI replaces the upstream system blocks with Claude Code-style system blocks and forwards the client system prompt into the first user message as <system-reminder> context.

If you want raw Anthropic /v1/messages system prompt semantics for OpenAI-compatible clients, disable Claude cloaking instead of changing the payload shape:

disable-claude-cloak-mode: true

or set it only on the affected Claude credential:

claude-api-key:
  - api-key: "sk-..."
    base-url: "..."
    cloak:
      mode: "never"

Because this is covered by the existing configuration and matches the documented default behavior rather than a missing translator mapping, I am closing this as not planned.

luispater avatar Jun 22 '26 13:06 luispater

Update after retesting with cloak.mode: "never":

My previous cloaking hypothesis only explains the earlier system-reminder behavior. After setting cloak mode to never, a plain Chat Completions request with messages[].role == "system" now works correctly in my test:

{
  "model": "claude-opus-4-6",
  "messages": [
    { "role": "system", "content": "Always start with exactly: SYSOK:" },
    { "role": "user", "content": "Introduce yourself briefly." }
  ],
  "temperature": 0,
  "max_tokens": 60
}

Response starts with SYSOK:, so role: system itself is no longer the failing path once cloaking is disabled.

However, I found another likely compatibility gap that may explain why some frontends still appear to lose the system prompt:

{
  "model": "claude-opus-4-6",
  "messages": [
    { "role": "developer", "content": "Always start with exactly: DEVOK:" },
    { "role": "user", "content": "Introduce yourself briefly." }
  ],
  "temperature": 0,
  "max_tokens": 60
}

This does not follow DEVOK:. The response usage also suggests the developer message was not included in the Claude prompt.

Similarly, this Chat Completions payload does not follow INSTOK::

{
  "model": "claude-opus-4-6",
  "instructions": "Always start with exactly: INSTOK:",
  "messages": [
    { "role": "user", "content": "Introduce yourself briefly." }
  ],
  "temperature": 0,
  "max_tokens": 60
}

Code-level observation:

  • internal/translator/claude/openai/chat-completions/claude_openai_request.go handles only case "system" for system-like instructions and converts it to top-level Claude system.
  • The same switch handles only case "user", "assistant" for normal messages.
  • There is no handling for OpenAI-style developer role in Chat Completions.
  • There is also no handling for a top-level instructions field in Chat Completions.

By contrast, the OpenAI Responses translator has instructions handling, but it currently converts it into a leading user message rather than top-level Claude system.

Revised suspected issue:

  1. With cloaking enabled, role: system is downgraded into system-reminder.
  2. With cloaking disabled, role: system works.
  3. But OpenAI-compatible clients that send their system/developer prompt as role: developer or instructions still lose that prompt on /v1/chat/completions.

Possible fix:

  • Treat role: "developer" the same as role: "system" in the Claude Chat Completions translator.
  • Optionally map top-level Chat Completions instructions into Claude top-level system as well.
  • For the Responses translator, consider mapping instructions and input[].role == "system" into top-level Claude system instead of a leading user message, so instruction priority is preserved.

This is a correction to my earlier comment: cloaking was one problem, but it is not the whole issue.

a86582751 avatar Jun 22 '26 13:06 a86582751

Final update after capturing the real OpenWebUI request log:

The issue is resolved on my side, and the root cause was not that CLIProxyAPI failed to forward the system prompt.

I temporarily enabled request-log: true and captured the actual OpenWebUI request. OpenWebUI was in fact sending a standard Chat Completions request with:

{
  "model": "claude-opus-4-6",
  "messages": [
    { "role": "system", "content": "..." },
    { "role": "user", "content": "你好" }
  ],
  "tools": [...]
}

CLIProxyAPI also correctly translated this into the upstream Anthropic /v1/messages body with the prompt in top-level system:

{
  "model": "claude-opus-4-6",
  "messages": [
    { "role": "user", "content": [{ "type": "text", "text": "你好" }] }
  ],
  "system": [
    { "type": "text", "text": "..." }
  ]
}

So the OpenAI role: "system" -> Claude top-level system mapping is working correctly after disabling cloak mode.

The actual difference between Cherry Studio and OpenWebUI was that OpenWebUI automatically attached many built-in tools. In my captured request there were 26 tools, including knowledge, notes, tasks, calendar, automations, etc. With those tools enabled, Claude strongly anchored itself to the tool/assistant environment and behaved like the default coding assistant identity. After disabling the attached tools in OpenWebUI's model configuration page, the persona/system prompt started working as expected.

Corrected conclusion:

  • cloak.mode: "never" / disable-claude-cloak-mode: true is still needed if the user wants raw Claude system prompt semantics instead of system-reminder forwarding.
  • With cloak disabled, CLIProxyAPI correctly forwards role: "system" to Claude top-level system.
  • My remaining OpenWebUI issue was caused by OpenWebUI's attached tools changing model behavior, not by CLIProxyAPI dropping or misplacing the system prompt.

Sorry for the earlier false trail, and thanks for the quick response.

a86582751 avatar Jun 22 '26 14:06 a86582751