-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Milestone
Description
Description
When sending text-only messages to the OpenAI Responses API (/v1/responses), the API returns a 400 error:
Bad Request (400) - Invalid value: 'input_text'. Supported values are: 'output_text' and 'refusal'.
Root Cause
The getMessageInputItem() method in OpenAiTextGenerationModel.php sends text-only messages as objects with a type field:
// Current (broken) behavior
'content' => [
'type' => 'input_text', // ❌ API rejects this
'text' => $text
]However, the OpenAI Responses API expects text-only messages to have the text sent directly as a string in the content field, not as an object.
Expected Behavior
For text-only messages, the content field should be a plain string:
// Correct format
'content' => $text // ✅ Plain string, not an objectSteps to Reproduce
- Create a text-only
UserMessagewith a single text part - Send it via
OpenAiTextGenerationModel::generateTextResult() - API returns 400 error: "Invalid value: 'input_text'"
Proposed Fix
In src/ProviderImplementations/OpenAi/OpenAiTextGenerationModel.php, modify getMessageInputItem() to handle text-only messages specially:
protected function getMessageInputItem(Message $message): ?array
{
$parts = $message->getParts();
if (empty($parts)) {
return null;
}
// Special handling for text-only messages: send text directly as a string
if (count($parts) === 1 && $parts[0]->getType()->isText()) {
$text = $parts[0]->getText();
return [
'role' => $this->getMessageRoleString($message->getRole()),
'content' => $text, // Send text directly as a string
];
}
// ... rest of the method for messages with files, function calls, etc.
}Environment
- php-ai-client version: 0.4.0
- OpenAI API: Responses API (
/v1/responses) - PHP version: 7.4+
Additional Notes
- Messages with files or multiple parts should continue to use the object format with
typefields - Only single-part text messages need this special handling
- This is specific to the Responses API - Chat Completions API may have different requirements
Related
This issue was discovered when upgrading from 0.3.x to 0.4.0 (which switched from Chat Completions to Responses API).
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended

