调用GPT接口使用3.5模型报错:Unrecognized request argument supplied: messages

报错信息:

话不多说,今天我请求chatgpt接口返回这样的信息:

java 复制代码
{
  "error": {
    "message": "Unrecognized request argument supplied: messages",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

一看懵逼了,我的请求参数存在问题,然后各种试,各种改,改成json字符串,改http请求方式,都不行,当中我又怀疑是我key的问题,又换了key还是不行,又以为是我代理网站的问题,后面又换海外网络,用官网域名请求,还是不行,自我怀疑好久,是不是3.5接口更新了,请求格式不对?后面才发现是我请求url和text模型的url搞错了

text模型接口URL:https://api.openai.com/v1/completions

3.5模型接口URL:https://api.openai.com/v1/chat/completions

最终修改请求URL就能正常调用了,分享一下请求体的json数据:

java 复制代码
{
    "messages": [
        {
            "content": "你是一个智能的AI助手。",
            "role": "system"
        },
        {
            "content": "请用java写一个helloWorld",
            "role": "user"
        }
    ],
    "model": "gpt-3.5-turbo"
}

请求方式是用okhttp3:

java 复制代码
    private static String fetch(String rowStr, String url) {
        RequestBody requestBody = RequestBody.create(rowStr, MediaType.parse("application/json; charset=utf-8"));
        Request request = new Request.Builder()
                .url(url)
                .header("Authorization", "Bearer " + token)
                .post(requestBody)
                .build();

        Call call = client.newCall(request);
        try {
            Response execute = call.execute();
            return execute.body().string();
        } catch (IOException e) {
            return "error";
        }
    }


//client初始化:

static OkHttpClient client = new OkHttpClient();
相关推荐
赞奇科技Xsuperzone15 小时前
DGX Spark 实战解析:模型选择与效率优化全指南
大数据·人工智能·gpt·spark·nvidia
CV-杨帆3 天前
博客阅读:chatgpt 2025 GPT-5 Jailbreak with Echo Chamber and Storytelling
gpt·chatgpt
2401_841495643 天前
【自然语言处理】轻量版生成式语言模型GPT
人工智能·python·gpt·深度学习·语言模型·自然语言处理·transformer
你的人类朋友4 天前
AI领域常见概念一览
gpt·ai编程·trae
wwlsm_zql5 天前
微软Copilot+企业版亮相:GPT-5赋能,效率激增47%,多模态操控金融级安全
人工智能·gpt·microsoft·copilot
DisonTangor6 天前
OpenAI开源gpt-oss-safeguard-120b和gpt-oss-safeguard-20b
人工智能·gpt·语言模型·开源·aigc
Baihai IDP6 天前
对 GPT 5 模型路由机制的深度解析
人工智能·gpt·ai·大模型·llms
七宝大爷6 天前
从 “你好 Siri” 到 “你好 GPT”:语言模型如何改变对话?
人工智能·gpt·语言模型
山山而川 潺潺如镜6 天前
chatgpt崩溃了,gpt怎么了
gpt
迪三达7 天前
GPT-0: Attention+Transformer+可视化
gpt·深度学习·transformer