调用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();
相关推荐
波尔德3 天前
GPT是否降智的测试问题
gpt
量子位3 天前
Nano Banana新玩法无限套娃!“GPT-5都不会处理这种级别的递归”
人工智能·gpt
AIBox3653 天前
国内可用 ChatGPT 中文版网站推荐(2025年11月最新)
人工智能·gpt·chatgpt
Ma0407134 天前
GPT:生成式预训练变形金刚
gpt
极客BIM工作室6 天前
从Transformer的Encoder与Decoder,到BERT和GPT的独立王国
gpt·bert·transformer
倔强的石头10610 天前
AiOnly大模型深度测评:调用GPT-5 API+RAG知识库,快速构建智能客服机器人
人工智能·gpt·机器人·aionly
boring_11110 天前
KubeFlow
gpt
智算菩萨10 天前
2025年通用大语言模型前沿进展评测:GPT-5.1、Claude 4.5、文心一言5.0 等全面解析
gpt·语言模型·文心一言
智慧地球(AI·Earth)11 天前
GPT-5.1发布!你的AI更暖更智能!
人工智能·gpt·神经网络·aigc·agi
盼小辉丶13 天前
PyTorch实战(10)——从零开始实现GPT模型
人工智能·pytorch·gpt·深度学习