400 Error from provider (Console Go): Upstream request failed: The parameter cac...
错误信息
API Error: 400 Error from provider (Console Go): Upstream request failed: The parameter cache_control is not
supported for the requested model. Please try again or contact support if you expect this parameter to be
supported. (request id: 20260905141146859443763c14228f5AnXc3rpG)
AI 解决方案
🔍 报错分析
1. 🌐 错误翻译
原文:API Error: 400 Error from provider (Console Go): Upstream request failed: The parameter cache_control is not supported for the requested model. Please try again or contact support if you expect this parameter to be supported. (request id: 20260905141146859443763c14228f5AnXc3rpG)
译文:API错误:400 来自提供商的错误(Console Go):上游请求失败:请求的模型不支持 cache_control 参数。如果您期望支持此参数,请重试或联系支持人员。
2. 🎯 原因分析
cache_control 参数cache_control 功能,导致请求被拒绝3. 💡 解决方案
cache_control 参数,根据目标模型支持的参数重新构建请求// 修复示例:移除 cache_control 参数后的请求代码
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
// 正确的请求参数结构,去除 cache_control
requestBody, err := json.Marshal(map[string]interface{}{
"model": "目标模型名称", // 替换为实际请求的模型
"messages": []map[string]string{
{
"role": "user",
"content": "你的请求内容",
},
},
// 仅保留目标模型支持的参数,此处以常见支持的参数为例
// 根据实际模型文档调整其他参数,例如 temperature、max_tokens 等
"temperature": 0.7,
})
if err != nil {
fmt.Printf("请求体序列化失败: %v\n", err)
return
}
req, err := http.NewRequest("POST", "https://api.dmxapi.cn/v1/chat/completions", bytes.NewBuffer(requestBody))
if err != nil {
fmt.Printf("创建请求失败: %v\n", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer 你_API_密钥") // 替换为实际API密钥
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("请求发送失败: %v\n", err)
return
}
defer resp.Body.Close()
// 后续处理响应逻辑...
}