You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React调用Stable Diffusion text2video API报错:需传入seconds参数求助

解决Stable Diffusion text2video API请求缺少seconds参数的问题
  • 问题原因:你调用的text2video接口要求必须传入seconds参数,用来指定生成视频的时长,你的请求体里未包含这个必填项,因此触发错误。
  • 修复方法:在request_body对象中添加seconds字段,设置一个合法数值(比如5,具体取值范围可参考接口规范)。

修改后的完整代码:

const request_body = {
    key: process.env.REACT_APP_STABLE_DIFFUSION_API,
    prompt: "ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner))",
    negative_prompt: null,
    width: "512",
    height: "512",
    samples: 1,
    num_inference_steps: "20",
    seed: null,
    guidance_scale: 7.5,
    safety_checker: "yes",
    multi_lingual: "no",
    panorama: "no",
    self_attention: "no",
    upscale: "no",
    embeddings_model: null,
    webhook: null,
    track_id: null,
    seconds: 5, // 添加必填的视频时长参数(单位:秒)
};

const generateImage = async () => {
  try {
    const generateResponse = await axios.post(
      "https://stablediffusionapi.com/api/v5/text2video",
      request_body
    );
    console.log(generateResponse.data);
  } catch (error) {
    // 新增错误捕获,方便后续排查问题
    console.error("请求失败:", error.response?.data || error.message);
  }
};

额外建议:

  • 给异步请求加上try/catch可以更直观地获取接口返回的错误详情,便于后续调试。
  • seconds参数通常支持1-10之间的整数,具体可根据接口要求调整。

内容的提问来源于stack exchange,提问作者theavocoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:04:50