( apiKey: string, model: string, prompt: string, duration: number, promptOptimizer: boolean, endpoint: string | undefined, requestId: string, logger: ReturnType<typeof createLogger> )
| 723 | } |
| 724 | |
| 725 | async function generateWithMiniMax( |
| 726 | apiKey: string, |
| 727 | model: string, |
| 728 | prompt: string, |
| 729 | duration: number, |
| 730 | promptOptimizer: boolean, |
| 731 | endpoint: string | undefined, |
| 732 | requestId: string, |
| 733 | logger: ReturnType<typeof createLogger> |
| 734 | ): Promise<{ buffer: Buffer; width: number; height: number; jobId: string; duration: number }> { |
| 735 | logger.info(`[${requestId}] Starting MiniMax Hailuo generation via MiniMax Platform API`) |
| 736 | logger.info( |
| 737 | `[${requestId}] Request params - model: ${model}, duration: ${duration}, endpoint: ${endpoint || 'standard'}, promptOptimizer: ${promptOptimizer}` |
| 738 | ) |
| 739 | |
| 740 | const useProResolution = endpoint === 'pro' && duration === 6 |
| 741 | const resolution = useProResolution ? '1080P' : '768P' |
| 742 | const dimensions = useProResolution ? { width: 1920, height: 1080 } : { width: 1360, height: 768 } |
| 743 | |
| 744 | logger.info( |
| 745 | `[${requestId}] Using resolution: ${resolution}, dimensions: ${dimensions.width}x${dimensions.height}` |
| 746 | ) |
| 747 | |
| 748 | const minimaxModel = model === 'hailuo-02' ? 'MiniMax-Hailuo-02' : 'MiniMax-Hailuo-2.3' |
| 749 | |
| 750 | const createResponse = await fetch('https://api.minimax.io/v1/video_generation', { |
| 751 | method: 'POST', |
| 752 | headers: { |
| 753 | Authorization: `Bearer ${apiKey}`, |
| 754 | 'Content-Type': 'application/json', |
| 755 | }, |
| 756 | body: JSON.stringify({ |
| 757 | model: minimaxModel, |
| 758 | prompt: prompt, |
| 759 | duration: duration, |
| 760 | resolution: resolution, |
| 761 | prompt_optimizer: promptOptimizer, |
| 762 | }), |
| 763 | }) |
| 764 | |
| 765 | if (!createResponse.ok) { |
| 766 | const errorText = await readVideoErrorText(createResponse, 'MiniMax create error response') |
| 767 | if (createResponse.status === 401 || createResponse.status === 1004) { |
| 768 | throw new Error( |
| 769 | `MiniMax API authentication failed (${createResponse.status}). Please ensure you're using a valid MiniMax API key from platform.minimax.io. Error: ${errorText}` |
| 770 | ) |
| 771 | } |
| 772 | throw new Error(`MiniMax API error: ${createResponse.status} - ${errorText}`) |
| 773 | } |
| 774 | |
| 775 | const createData = await readVideoJson<{ |
| 776 | base_resp?: { status_code?: number; status_msg?: string } |
| 777 | task_id?: string |
| 778 | }>(createResponse, 'MiniMax create response') |
| 779 | |
| 780 | // Check for error in response |
| 781 | if (createData.base_resp?.status_code !== 0) { |
| 782 | throw new Error(`MiniMax API error: ${createData.base_resp?.status_msg || 'Unknown error'}`) |
no test coverage detected