调用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();
相关推荐
the3clipse2 天前
系统盘怎么无损从 MBR 转 GPT 并开启 UEFI 启动?mbr2gpt 完整教程
gpt·mbr·uefi启动·无损转换分区表·bcdboot·引导修复
一缕82年的清风2 天前
百万 Token 砍到 0.5 美元!微软新模型半价、DeepSeek 连夜撤回搜索费,11 月底开发者怎么搭最省钱?
gpt·claude·deepseek
翰墨之道2 天前
AI日报:豆包工作ARR超20亿,GPT-6.2跑分与实测割裂
人工智能·gpt·数据挖掘
Maynor9962 天前
Trymodel 使用介绍:一个平台同时用 Claude、GPT、Gemini 和 Grok
人工智能·gpt·ai·程序员·教程·claude·语音
bryant_meng3 天前
ChatGPT Desktop Model Evolution (2025): From GPT-4.1 to GPT-5.1
gpt·chatgpt·gpt4·gpt4o·gpt5
一缕82年的清风3 天前
谷歌甩出 Gemini 4 Neon:Agent 编程榜登顶第一、缓存仅 $0.15,把刚发的 GPT-6.2 架在火上烤!
gpt·claude·gemini
2301_767113983 天前
GPT-6.2 Astra 和 Sol 发布:真正变化的是长任务成本与交付方式
gpt
zdr尽职尽责4 天前
终端工具凭空消失:Codex + GPT-6 的一次完整排障复盘
数据库·gpt·学习·ai
一缕82年的清风4 天前
OpenAI 突发 GPT-6.2:Sol 提速 8 倍跑分追平旗舰,但这 1 处暗改会让缓存直接失效!
gpt·chatgpt
回眸&啤酒鸭4 天前
【回眸】GPT-6.1 Sol 新手快速上手指南
gpt