BytePlus AI Generator

Max 10MB, formats: JPEG, PNG, WEBP, BMP, TIFF, GIF
Generating image...
Max 30MB
Max 30MB
Creating video task...
['message' => 'Method not allowed']]); exit; } $action = $_POST['action'] ?? ''; if ($action === 'generate_image') { $url = 'https://ark.ap-southeast.bytepluses.com/api/v3/images/generations'; $payload = [ 'model' => $IMAGE_MODEL, 'prompt' => $_POST['prompt'], 'size' => $_POST['size'] ?? '2048x2048', 'sequential_image_generation' => $_POST['sequential'] ?? 'disabled', 'response_format' => 'url' ]; // Handle image upload if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $imageData = file_get_contents($_FILES['image']['tmp_name']); $base64 = base64_encode($imageData); $mimeType = $_FILES['image']['type']; $payload['image'] = "data:$mimeType;base64,$base64"; } echo makeRequest($url, $payload, $API_KEY); } elseif ($action === 'generate_video') { $url = 'https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks'; $prompt = $_POST['prompt']; $duration = $_POST['duration'] ?? '5'; $ratio = $_POST['ratio'] ?? '16:9'; $content = [ ['type' => 'text', 'text' => "$prompt --dur $duration --rt $ratio"] ]; // Handle first frame if (isset($_FILES['first_frame']) && $_FILES['first_frame']['error'] === UPLOAD_ERR_OK) { $imageData = file_get_contents($_FILES['first_frame']['tmp_name']); $base64 = base64_encode($imageData); $mimeType = $_FILES['first_frame']['type']; $content[] = [ 'type' => 'image_url', 'image_url' => ['url' => "data:$mimeType;base64,$base64"], 'role' => 'first_frame' ]; } // Handle last frame if (isset($_FILES['last_frame']) && $_FILES['last_frame']['error'] === UPLOAD_ERR_OK) { $imageData = file_get_contents($_FILES['last_frame']['tmp_name']); $base64 = base64_encode($imageData); $mimeType = $_FILES['last_frame']['type']; $content[] = [ 'type' => 'image_url', 'image_url' => ['url' => "data:$mimeType;base64,$base64"], 'role' => 'last_frame' ]; } $payload = [ 'model' => $VIDEO_MODEL, 'content' => $content ]; echo makeRequest($url, $payload, $API_KEY); } elseif ($action === 'check_video') { $taskId = $_POST['task_id']; $url = "https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks/$taskId"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $API_KEY ]); $response = curl_exec($ch); curl_close($ch); echo $response; } else { echo json_encode(['error' => ['message' => 'Invalid action']]); } function makeRequest($url, $payload, $apiKey) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey ]); $response = curl_exec($ch); curl_close($ch); return $response; } ?>