Skip to main content
Glama

generateVideo

Generate videos from text prompts using AI models, with options for resolution, dimensions, and custom start/end frames.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathNo首帧和尾帧图片路径,支持数组,最多2个元素,分别为首帧和尾帧
resolutionNo分辨率,可选720p或1080p,默认720p
modelNo模型名称,可选值: jimeng-video-seedance-2.0, jimeng-video-seedance-2.0-fast, jimeng-video-3.5-pro, jimeng-video-3.0-pro, jimeng-video-3.0-fast, jimeng-video-3.0,默认jimeng-video-3.0-fast
promptYes生成视频的文本描述
widthNo视频宽度,默认1024
heightNo视频高度,默认1024
refresh_tokenNo即梦API令牌(可选,通常从环境变量读取)
req_keyNo自定义参数,兼容旧接口

Implementation Reference

  • The core logic for generating a video by constructing the API request, handling model selection, and polling for the final video URL.
    async generateVideo(params: VideoGenerationParams): Promise<string> {
      if (!params.prompt || typeof params.prompt !== 'string') {
        throw new Error('prompt必须是非空字符串');
      }
      const actualModel = this.getModel(params.model || DEFAULT_VIDEO_MODEL);
      let first_frame_image = undefined
      let end_frame_image = undefined
      if (params?.filePath) {
        let uploadIDs: any[] = []
        for (const item of params.filePath) {
          const uploadID = await this.uploadCoverFile(item)
          uploadIDs.push(uploadID)
        }
        if (uploadIDs[0]) {
          first_frame_image = {
            format: "",
            height: params.height || 1024,
            id: generateUuid(),
            image_uri: uploadIDs[0],
            name: "",
            platform_type: 1,
            source_from: "upload",
            type: "image",
            uri: uploadIDs[0],
            width: params.width || 1024,
          }
        }
        if (uploadIDs[1]) {
          end_frame_image = {
            format: "",
            height: params.height || 1024,
            id: generateUuid(),
            image_uri: uploadIDs[1],
            name: "",
            platform_type: 1,
            source_from: "upload",
            type: "image",
            uri: uploadIDs[1],
            width: params.width || 1024,
          }
        }
        if (!first_frame_image && !end_frame_image) {
          throw new Error('上传封面图片失败,请检查图片路径是否正确');
        }
      }
      const componentId = generateUuid();
      let submitId = generateUuid()
      const metricsExtra = jsonEncode({
        "enterFrom": "click",
        "isDefaultSeed": 1,
        "promptSource": "custom",
        "isRegenerate": false,
        "originSubmitId": submitId,
        "position": "page_bottom_box",
      })
      const rqParams: {
        [key: string]: string | number
      } = {
        msToken: generateMsToken(),
        aigc_features: "app_lip_sync",
        web_version: "6.6.0",
        "da_version": "3.2.8",
        "aid": parseInt(DEFAULT_ASSISTANT_ID),
        "device_platform": "web",
        "region": "CN",
        "web_id": WEB_ID
      }
      rqParams['a_bogus'] = generate_a_bogus(toUrlParams(rqParams), UA)
      const rqData = {
        "extend": {
          "root_model": actualModel,
          "m_video_commerce_info": {
            benefit_type: "basic_video_operation_vgfm_v_three",
            resource_id: "generate_video",
            resource_id_type: "str",
            resource_sub_type: "aigc"
          },
          "m_video_commerce_info_list": [{
            benefit_type: "basic_video_operation_vgfm_v_three",
            resource_id: "generate_video",
            resource_id_type: "str",
            resource_sub_type: "aigc"
          }]
        },
        "submit_id": submitId,
        "metrics_extra": metricsExtra,
        "draft_content": jsonEncode({
          "type": "draft",
          "id": generateUuid(),
          "min_version": "3.0.5",
          "is_from_tsn": true,
          "version": "3.3.11",
          "main_component_id": componentId,
          "component_list": [{
            "type": "video_base_component",
            "id": componentId,
            "min_version": "1.0.0",
            "metadata": {
              "type": "",
              "id": generateUuid(),
              "created_platform": 3,
              "created_platform_version": "",
              "created_time_in_ms": Date.now(),
              "created_did": ""
            },
            "generate_type": "gen_video",
            "aigc_mode": "workbench",
            "abilities": {
              "type": "",
              "id": generateUuid(),
              "gen_video": {
                "id": generateUuid(),
                "type": "",
                "text_to_video_params": {
                  "type": "",
                  "id": generateUuid(),
                  "model_req_key": actualModel,
                  "priority": 0,
                  "seed": Math.floor(Math.random() * 100000000) + 2500000000,
                  "video_aspect_ratio": "1:1",
                  "video_gen_inputs": [{
                    duration_ms: 5000,
                    first_frame_image: first_frame_image,
                    end_frame_image: end_frame_image,
                    fps: 24,
                    id: generateUuid(),
                    min_version: "3.0.5",
                    prompt: params.prompt,
                    resolution: params.resolution || "720p",
                    type: "",
                    video_mode: 2
                  }]
                },
                "video_task_extra": metricsExtra,
              }
            }
          }],
        }),
      }
      // 发送生成请求(积分不足时自动切换Token重试)
      let generateResult: any;
      while (this.tokens.length > 0) {
        const creditInfo = await this.getCredit();
        if (creditInfo.totalCredit <= 0) {
          await this.receiveCredit();
        }
        generateResult = await this.request(
          'POST',
          '/mweb/v1/aigc_draft/generate',
          rqData,
          rqParams
        );
        if (generateResult?.ret === '1006') {
          console.log(`Token [${this.tokenIndex + 1}/${this.tokens.length}] 积分不足,移除并切换下一个Token重试`);
          this.nextToken();
          if (this.tokens.length === 0) break;
          submitId = generateUuid();
          rqData.submit_id = submitId;
          continue;
        }
        break;
      }
      if (!generateResult || generateResult?.ret === '1006') {
        throw new Error('所有Token积分不足或没有相关权益');
      }
      console.log('生成请求结果:', generateResult);
      const itemList = await this.pollResultWithHistory(generateResult, submitId);
      const videoUrl = itemList?.[0]?.video?.transcoded_video?.origin?.video_url
      console.log('生成视频结果:', videoUrl);
    
      return videoUrl;
    }
  • The public-facing wrapper function for the `generateVideo` tool.
    export const generateVideo = (params: VideoGenerationParams): Promise<string> => {
      return apiClient.generateVideo(params)
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/c-rick/jimeng-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server