(params)
| 331 | } |
| 332 | |
| 333 | async function generateVideo(params) { |
| 334 | requireApiKey(); |
| 335 | |
| 336 | const { |
| 337 | prompt, |
| 338 | model = "veo", |
| 339 | duration, |
| 340 | aspectRatio, |
| 341 | audio, |
| 342 | image, |
| 343 | seed, |
| 344 | } = params; |
| 345 | const { encodedPrompt, queryParams } = await prepareVideoRequest(params); |
| 346 | |
| 347 | const url = buildUrl(`/image/${encodedPrompt}`, queryParams); |
| 348 | |
| 349 | try { |
| 350 | const { buffer, contentType } = await fetchBinaryWithAuth(url); |
| 351 | const base64Data = arrayBufferToBase64(buffer); |
| 352 | |
| 353 | const metadata = { |
| 354 | prompt, |
| 355 | model, |
| 356 | duration, |
| 357 | aspectRatio, |
| 358 | audio: model === "veo" ? audio || false : undefined, |
| 359 | hasReferenceImage: !!image, |
| 360 | seed, |
| 361 | }; |
| 362 | |
| 363 | return createMCPResponse([ |
| 364 | { |
| 365 | type: "resource", |
| 366 | resource: { |
| 367 | uri: `pollinations://video/${Date.now()}`, |
| 368 | mimeType: contentType || "video/mp4", |
| 369 | blob: base64Data, |
| 370 | }, |
| 371 | }, |
| 372 | createTextContent( |
| 373 | `Generated video from prompt: "${prompt}"\n\nMetadata: ${JSON.stringify(metadata, null, 2)}\n\nVideo returned as base64-encoded resource (decode and save as .mp4)`, |
| 374 | ), |
| 375 | ]); |
| 376 | } catch (error) { |
| 377 | console.error("Error generating video:", error); |
| 378 | throw error; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | async function generateVideoUrl(params) { |
| 383 | requireApiKey(); |
nothing calls this directly
no test coverage detected