www.dmxapi.cn/v1beta/models/gemini-3.1-flash-image-preview:generateContent:1 Fai...

2026年03月13日 10:38 processing

错误信息

www.dmxapi.cn/v1beta/models/gemini-3.1-flash-image-preview:generateContent:1 Failed to load resource: the server responded with a status of 400 ()

AI 解决方案

报错分析报告

1.错误翻译


原文:Failed to load resource: the server responded with a status of 400 ()
译文:加载资源失败:服务器响应状态为400(错误请求)

2. 原因分析


  • 根本原因:向www.dmxapi.cn/v1beta/models/gemini-3.1-flash-image-preview:generateContent发起的API请求存在语法/参数错误,触发服务器400 Bad Request响应。

  • 具体位置:代码中调用该Gemini模型生成内容接口的HTTP请求(如前端fetch/后端HTTP库调用)。
  • 3. 解决方案


    // 修复示例:以JavaScript fetch为例,确保请求合法
    async function callGeminiAPI() {
      const API_URL = "https://www.dmxapi.cn/v1beta/models/gemini-3.1-flash-image-preview:generateContent";
      const API_KEY = "YOUR_VALID_DMXAPI_KEY"; // 替换为有效密钥
      
      try {
        const response = await fetch(API_URL, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${API_KEY}`
          },
          body: JSON.stringify({
            contents: [{ parts: [{ text: "生成一张 sunset 主题的图片" }] }],
            generationConfig: { responseModalities: ["TEXT", "IMAGE"] } // 按文档填正确参数
          })
        });
        
        if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
        return await response.json();
      } catch (err) {
        console.error("请求失败:", err);
      }
    }
    

    关键修复点
  • 补全https协议(原URL缺协议易导致请求异常);

  • 核对API文档的必填参数(如contents结构、generationConfig字段);

  • 确保API_KEY有效且权限匹配。
  • 4. 预防措施


  • 预校验请求:用[DMXAPI官方文档](https://www.dmxapi.cn/docs)核对端点、参数格式,避免拼写/结构错误;

  • 工具调试:用Postman/Insomnia先测试请求,验证返回正常后再集成到代码。

  • -推荐工具:Postman(可视化API测试)、curl(命令行快速验证)。

    ---
    请补充更多报错细节(如请求参数、完整堆栈)以获取更精准分析。