Hey there!
I am having quite a bit of trouble sending an API call to POST https://api.openai.com/v1/audio/transcriptions
Here’s an example of my code:
// Create Temporary file
File tmpFile = Files.write(Path.of(Files.createTempDirectory("uploads_") + File.pathSeparator + fileName), fileData).toFile();
// Put the file in the body...
FileBody fileBody = new FileBody(tmpFile, ContentType.DEFAULT_BINARY);
// Build the multiPartFile
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("model", model);
builder.addTextBody("language", languageCode);
builder.addPart("file", fileBody);
// Prepare Client
HttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("https://api.openai.com/v1/audio/transcriptions");
// Prepare Payload
httpPost.setEntity(builder.build());
// Set Headers
httpPost.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + this.apiKey);
httpPost.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
Here’s the error I am getting ( It’s invalid JSON ):
java.lang.Exception: Invalid HTTP Response from API received: {
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to support@openai.com and include any relevant code you'd like help with.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Hope somebody can help me out, I am more or less stuck on this, and the api is just saying it needs a JSON but also requesting a file? Sorry if this is coming off as noobish