mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-03-30 02:27:11 +00:00
fix(openai): convert string input to array for Codex OAuth responses endpoint
The ChatGPT backend-api codex/responses endpoint requires `input` to be an array, but the OpenAI Responses API spec allows it to be a plain string. When a client sends a string input, sub2api now converts it to the expected message array format. Empty/whitespace-only strings become an empty array to avoid triggering a 400 "Input must be a list" error.
This commit is contained in:
@@ -146,6 +146,22 @@ func applyCodexOAuthTransform(reqBody map[string]any, isCodexCLI bool, isCompact
|
||||
input = filterCodexInput(input, needsToolContinuation)
|
||||
reqBody["input"] = input
|
||||
result.Modified = true
|
||||
} else if inputStr, ok := reqBody["input"].(string); ok {
|
||||
// ChatGPT codex endpoint requires input to be a list, not a string.
|
||||
// Convert string input to the expected message array format.
|
||||
trimmed := strings.TrimSpace(inputStr)
|
||||
if trimmed != "" {
|
||||
reqBody["input"] = []any{
|
||||
map[string]any{
|
||||
"type": "message",
|
||||
"role": "user",
|
||||
"content": inputStr,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
reqBody["input"] = []any{}
|
||||
}
|
||||
result.Modified = true
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user