调用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();
相关推荐
lazy熊29 分钟前
初学者如何快速入门学会 Claude Code?
人工智能·gpt·ai编程
IT当时语_青山师__JAVA技术栈1 小时前
DeepSeek V4 出来了,我一个 Java 老炮第一时间接进 Spring Boot——附 V3 vs V4 实测对比
gpt·openai·deepseek
Resistance丶未来2 小时前
Hy3 Preview 免费模型快速上手指南
gpt·ai·大模型·api·claude·gemini·hy3 preview
kyriewen1117 小时前
奥特曼借GPT-5.5干杯,而你的Copilot正按Token收钱
前端·gpt·ai·copilot
Resistance丶未来19 小时前
TradingAgents 多智能体交易框架深度评测
gpt·大模型·llm·agent·claude·多智能体·trading agents
huisheng_qaq1 天前
【AI入门篇-02】深入理解ChatGPT发展流程
人工智能·gpt·ai·chatgpt·大模型·transfomer
陈天伟教授1 天前
AI 未来趋势:产业应用范式之变
大数据·开发语言·人工智能·gpt
智算菩萨1 天前
OpenAI Codex 国内使用完全指南:Windows/macOS/Linux 三平台详细安装配置教程(现在最新的有gpt-5.3-codex和gpt-5.4)
linux·windows·gpt·macos·ai·ai编程·codex
码农小旋风2 天前
2026 终端 AI 编程工具深度横评:Claude Code、Codex CLI、Gemini CLI、Aider 怎么选
人工智能·gpt·claude
AdMergeX2 天前
(4.21-4.28)出海行业热点|跨境电商查账征收细则落地;OpenAI发布GPT-5.5;TikTok Shop筹备波兰、荷兰、比利时新站点
gpt