diff --git a/internal/translator/codex/openai/chat-completions/codex_openai_request.go b/internal/translator/codex/openai/chat-completions/codex_openai_request.go index e3a380d0..335e53b1 100644 --- a/internal/translator/codex/openai/chat-completions/codex_openai_request.go +++ b/internal/translator/codex/openai/chat-completions/codex_openai_request.go @@ -110,6 +110,11 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b for i := 0; i < len(arr); i++ { m := arr[i] role := m.Get("role").String() + if role == "system" { + // Codex backend rejects role=system in input ("System messages are not allowed"). + // Preserve the content by downgrading to a user message. + role = "user" + } switch role { case "tool": diff --git a/internal/translator/codex/openai/responses/codex_openai-responses_request.go b/internal/translator/codex/openai/responses/codex_openai-responses_request.go index b4c39d22..e127837c 100644 --- a/internal/translator/codex/openai/responses/codex_openai-responses_request.go +++ b/internal/translator/codex/openai/responses/codex_openai-responses_request.go @@ -49,9 +49,10 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte, inputResults = []gjson.Result{} } - // Preserve caller instructions by converting them into an explicit system message inside "input". + // Preserve caller instructions by converting them into an explicit leading user message inside "input". + // Note: Codex backend rejects role=system in input ("System messages are not allowed"). if strings.TrimSpace(originalInstructionsText) != "" { - sys := `{"type":"message","role":"system","content":[{"type":"input_text","text":""}]}` + sys := `{"type":"message","role":"user","content":[{"type":"input_text","text":""}]}` sys, _ = sjson.Set(sys, "content.0.text", originalInstructionsText) newInput := "[]"