QuantumNous/new-api
View on GitHubGoogle Vertex: Gemini频繁报错 400 relay error: `edit` functionDeclaration `parameters.edits.lines` schema didn't specify the schema type field.
Open
#3022 opened on Feb 26, 2026
buggood first issue
Description
例行检查
- 我已确认目前没有类似 issue
- 我已确认我已升级到最新版本
- 我已完整查看过项目 README,尤其是常见问题部分
- 我理解并愿意跟进此 issue,协助测试和提供反馈
- 我理解并认可上述内容,并理解项目维护者精力有限,不遵循规则的 issue 可能会被无视或直接关闭
问题描述
下游使用OpenAI协议,上游Google Vertex AI,调用 gemini-3.1-pro-preview 和 gemini-3-flash-preview 都频繁报错以下信息,完全无法使用的状态。
relay error: Unable to submit request because
editfunctionDeclarationparameters.edits.linesschema 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
}
// ... 原有逻辑
}