": f"message"."Invalid URL (POST / v1)" "type"."invalid_request_error" "code"") ...
错误信息
Failed to get response: 404 f"error":
f"message"."Invalid URL (POST /
v1)" "type"."invalid_request_error" "code"")
java.lang.Exception:Failed to get
response: 404 ("error" : f"message" :"Invalid
URL (POST 1
v1)", "type":"invalid_request_error" , "code"
:""ト
at
me.rerere.ai.provider. providers . openai.Cha tCompletionsAPI$generateText$2.invokeSuspe nd(r8-map-id-ae05f344db9038900e98d210ee2cf 9e910c731212dd8638b198e4e1748533974:250)at
kotlin.coroutines.jvm.internal.BaseContinu ationImpl.resumeWith(r8-map-id-ae05f344db9038900e98d210ee2cf9e910c731212dd8b386198e4e1748533974:8)
at
kotlinx.coroutines.DispatchedTask. run(r8-m ap-id-ae05f344db9038900e98d210ee2cf9e910c731212dd8b38b198e4e1748533974:114)
at
com.google.android.gms.tasks.zzc.run(r8-ma p-id-ae05f344d69038900e98d210ee2cf9e910c731212dd86386198e4e1748533974:18)
at
kotlinx.coroutines.scheduling.TaskImpl. run (r8-map-id-ae05f344db9038900e98d210ee2cf9e 910c731212dd86386198e4e1748533974:3)
at
AI 解决方案
报错分析报告
1.错误翻译
原文:Invalid URL (POST / v1)
译文:无效的URL(POST / v1)
原文:Invalid URL (POST 1 v1)
译文:无效的URL(POST 1 v1)
2. 原因分析
/ v1/1 v1),不符合API端点规范。 ChatCompletionsAPI$generateText$2.invokeSuspend方法中发送请求时,目标URL无效。3. 解决方案
// 修复后的代码示例(以OkHttp为例,修正URL路径)
OkHttpClient client = new OkHttpClient();
MediaType JSON = MediaType.get("application/json; charset=utf-8");
String requestBody = "{\"model\":\"gpt-3.5-turbo\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}";
Request request = new Request.Builder()
.url("https://api.dmxapi.com/v1/chat/completions") // 关键修复:去掉空格/错误字符,用正确端点
.post(RequestBody.create(requestBody, JSON))
.addHeader("Authorization", "Bearer YOUR_API_KEY")
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.body().string());
}
4.️ 预防措施
private static final String API_URL = "https://api.dmxapi.com/v1/chat/completions"),避免硬编码错误。 ---
注:请将示例中的YOUR_API_KEY替换为实际密钥,URL需与DMXAPI文档一致。