curl --request POST \
--url https://api.example.com/api/conversations/{id}/toggle-ai \
--header 'Content-Type: application/json' \
--data '
{
"ai_enabled": true
}
'{
"success": true,
"message": "<string>",
"error": "<string>"
}Enable or disable AI responses for a specific conversation
curl --request POST \
--url https://api.example.com/api/conversations/{id}/toggle-ai \
--header 'Content-Type: application/json' \
--data '
{
"ai_enabled": true
}
'{
"success": true,
"message": "<string>",
"error": "<string>"
}POST /api/conversations/{id}/toggle-ai
true to enable AI responses, or false to disable themsuccess is true)success is false)curl -X POST 'https://your-domain.com/api/conversations/1/toggle-ai' \
-H 'Content-Type: application/json' \
-d '{
"ai_enabled": true
}'
{
"success": true,
"message": "AI state updated successfully"
}
{
"success": false,
"error": "Error al cambiar estado de IA"
}
{
"success": false,
"error": "INSUFFICIENT_FUNDS",
"message": "No se puede activar la IA. Fondos insuficientes en OpenAI."
}
api/toggle-ai.php and performs the following operations:
ai_enabled state are providedai_enabled field in the conversations tableindex.php:178):
if ($requestMethod === 'POST' &&
preg_match('#^/api/conversations/(\d+)/toggle-ai$#', $path, $matches)) {
$_GET['id'] = $matches[1];
require __DIR__ . '/api/toggle-ai.php';
}
toggle-ai.php:9-15):
$id = $_GET['id'] ?? null;
$input = json_decode(file_get_contents('php://input'), true);
$aiEnabled = $input['ai_enabled'] ?? null;
if (!$id || $aiEnabled === null) {
throw new \InvalidArgumentException('Conversation ID and ai_enabled state required');
}
toggle-ai.php:17-33):
if ($aiEnabled) {
$openaiStatus = $db->fetchOne(
"SELECT setting_value FROM settings WHERE setting_key = 'openai_status'",
[]
);
if ($openaiStatus && $openaiStatus['setting_value'] === 'insufficient_funds') {
http_response_code(402);
echo json_encode([
'success' => false,
'error' => 'INSUFFICIENT_FUNDS',
'message' => 'No se puede activar la IA. Fondos insuficientes en OpenAI.'
]);
exit;
}
}
toggle-ai.php:35-41):
$db->query(
'UPDATE conversations SET ai_enabled = :ai_enabled WHERE id = :id',
[
':ai_enabled' => $aiEnabled ? 1 : 0,
':id' => $id
]
);
ai_enabled: true), the endpoint checks if OpenAI has sufficient funds by querying the settings table for the openai_status key.
If the status is insufficient_funds, the request returns:
INSUFFICIENT_FUNDSawait toggleAI(conversationId, false);
await toggleAI(conversationId, true);
const conversationIds = [1, 2, 3, 4, 5];
for (const id of conversationIds) {
await toggleAI(id, false);
}
ai_enabled field is stored as an integer (0 or 1) in the database