codex: avoid role=system in input

This commit is contained in:
Finessse
2025-12-17 17:55:17 +07:00
parent 7649532c4a
commit d4c3f6fcad
2 changed files with 8 additions and 2 deletions
@@ -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":
@@ -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 := "[]"