Hugging Face /hf-inference/v1/chat/completions returns 422 in Eclipse plugin
I'm building an Eclipse plugin for code completion using the Hugging Face API. My plugin sends a prompt to the endpoint:
https://router.huggingface.co/hf-inference/v1/chat/completions
I replaced the old endpoint (https://api-inference.huggingface.co) as recommended.
Here’s my Java request code:
String json = "{"
+ "\"inputs\": \"" + safePrompt + "\""
+ "}";
RequestBody body = RequestBody.create(json, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url("https://router.huggingface.co/hf-inference/v1/chat/completions")
.addHeader("Authorization", "Bearer " + hfToken)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println(response.code());
System.out.println(response.body().string());
}
When I run this, I always get:
Response code: 422
Raw body length: 24
Can someone suggest a free Hugging Face model that works for code completion in Java/Eclipse?