QuantumNous/new-api

Google Vertex: Gemini频繁报错 400 relay error: `edit` functionDeclaration `parameters.edits.lines` schema didn't specify the schema type field.

Open

#3,022 opened on Feb 26, 2026

View on GitHub
 (6 comments) (1 reaction) (0 assignees)Go (7,359 forks)batch import
buggood first issue

Repository metrics

Stars
 (33,398 stars)
PR merge metrics
 (Avg merge 3d 5h) (83 merged PRs in 30d)

Description

例行检查

  • 我已确认目前没有类似 issue
  • 我已确认我已升级到最新版本
  • 我已完整查看过项目 README,尤其是常见问题部分
  • 我理解并愿意跟进此 issue,协助测试和提供反馈
  • 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭

问题描述 下游使用OpenAI协议,上游Google Vertex AI,调用 gemini-3.1-pro-previewgemini-3-flash-preview 都频繁报错以下信息,完全无法使用的状态。

relay error: Unable to submit request because edit functionDeclaration parameters.edits.lines schema didn't specify the schema type field. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling

  • 值得注意的是,几天前还在正常使用,可能是Google方面的变更所致。
  • Update: 发现 parameters.edits.lines 与 repo:code-yeongyu/oh-my-opencode 有关
  • Vertex AI 所提供的其他第三方模型(未广泛测试)暂未发现同样错误。

复现步骤 使用的 OpenCode (with Oh-my-opencode Plugin, OpenAI格式请求) --> New-API --> Vertex AI 。

预期结果 正常使用。

AI 分析结论(仅供参考) 已尝试修复,无效

问题定位relay/channel/gemini/relay-gemini.go 第 843-903 行 根因normalizeGeminiSchemaTypeAndNullable 函数在处理 schema 转换时,如果 type 字段缺失,直接 return 而非补充默认值。Gemini API 要求所有 schema 节点必须显式声明 type,而 OpenAI 格式允许嵌套对象省略 type关键代码

func normalizeGeminiSchemaTypeAndNullable(schema map[string]interface{}) {
    rawType, ok := schema["type"]
    if !ok || rawType == nil {
        return  // ← BUG: 缺失时不补充默认值
    }
    // ...
}

建议修复

func normalizeGeminiSchemaTypeAndNullable(schema map[string]interface{}) {
    rawType, ok := schema["type"]
    if !ok || rawType == nil {
        // 根据其他字段推断 type
        if _, hasProps := schema["properties"]; hasProps {
            schema["type"] = "OBJECT"
        } else if _, hasItems := schema["items"]; hasItems {
            schema["type"] = "ARRAY"
        } else if _, hasEnum := schema["enum"]; hasEnum {
            schema["type"] = "STRING"
        } else {
            schema["type"] = "OBJECT"
        }
        return
    }
    // ... 原有逻辑
}

Contributor guide