调用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();
相关推荐
深频率12 小时前
6倍价格买8倍速度?GPT-6.1 Sol极速版的两个倍率
人工智能·gpt
AI你一生一世19 小时前
GPT-6 Astra 深度拆解:当推理模型开始为“长任务”重新设计
人工智能·gpt·大语言模型·astra·推理模型·长任务·gpt-6
Tangyuewei19 小时前
GPT-6.1 Astra 被砍内情
gpt
Sammyyyyy21 小时前
Claude Haiku 5.5 与 GPT-6.1 Sol 选型拆解:20 倍价差不等于 20 倍总成本,附网关分流思路
人工智能·gpt
江屿风1 天前
【Plain Language Large Model】【理清常见国内外大模型的定位和特长】流食般投喂
人工智能·gpt·claude·glm·gemini·千问·deepseek
DM今天肝到几点?2 天前
OpenAI 向全量用户开放 GPT-6 与 Intelligent UI:聊天框正在变成工作台
gpt·ui·chatgpt
空堂与归2 天前
清华VPP2登顶RoboDojo:凭预测解耦突围GPT-6
人工智能·gpt·ai·具身智能
空堂与归2 天前
GPT-6 智能界面上线,对话式 Agent 真没戏了?
人工智能·gpt·ai
AI日报派送佬2 天前
2026年10月8日AI行业日报|GPT-6可视化UI全面上线、AI PC硬件革新、智能体安全与商业化提速
人工智能·gpt·openai·谷歌·deepseek·ai日报·智能体技术