调用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();
相关推荐
前端大波4 小时前
OpenClaw 本地安装与 GPT 模型接入计划(OpenAI 登录版)
gpt
智算菩萨7 小时前
【论文复现】ML-MLM:基于PyTorch的多标签极小学习机完整复现教程(附GPT-5.4辅助科研提示词工程)
人工智能·pytorch·python·gpt·深度学习·论文笔记
ofoxcoding7 小时前
GPT-5.4 API 完全指南:性能实测、成本测算与接入方案(2026)
人工智能·gpt·算法·ai
147API8 小时前
GPT-5.4 vs Claude 4.6 接入差异对比(含迁移与统一接入)
gpt·claude·api中转·api大模型
balmtv1 天前
从“知识检索”到“深度推理”:Gemini 3.1如何用三层思考模式解决学术难题
人工智能·gpt·chatgpt
AI-Ming1 天前
程序员转行学习 AI 大模型: 踩坑记录,HuggingFace镜像设置未生效
人工智能·pytorch·python·gpt·深度学习·学习·agi
ai大模型中转api测评2 天前
从并发噩梦到弹性自由:2026年开发者如何构建高可用的API分发层?
人工智能·gpt·gemini
AI-Ming2 天前
程序员转行学习 AI 大模型: 踩坑记录:服务器内存不够,程序被killed
服务器·人工智能·python·gpt·深度学习·学习·agi
ofoxcoding2 天前
GPT-5 API 费率全拆解:2026 各平台真实价格对比,附省钱方案
gpt·ai