Whispher model translation API gives 400 Bad Request

I am using Java Language.

Here is my code :

final String API_KEY = whisperRecordingTextApiKey;
final String API_URL = "https://api.openai.com/v1/audio/translations";

			HttpHeaders headers = new HttpHeaders();
			headers.set("Authorization", "Bearer " + API_KEY); // Replace with your OpenAI API key
			headers.setContentType(MediaType.MULTIPART_FORM_DATA);

			WhisperTranscriptionRequest whisperTranscriptionRequest = WhisperTranscriptionRequest.builder()
					.model("whisper-1").file(file).temperature((int) 0.2).build();

			MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
			body.add("model", whisperTranscriptionRequest.getModel());
			body.add("temperature", whisperTranscriptionRequest.getTemperature());
			body.add("file", new ByteArrayResource(whisperTranscriptionRequest.getFile().getBytes()) {
				@Override
				public String getFilename() {
					return whisperTranscriptionRequest.getFile().getOriginalFilename();
				}
			});

			HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);

			RestTemplate restTemplate = new RestTemplate();
			ResponseEntity<WhisperTranscriptionResponse> responseEntity = restTemplate.postForEntity(API_URL,
					requestEntity, WhisperTranscriptionResponse.class);

			log.info(responseEntity.getBody().getText());
			return responseEntity.getBody().getText();

I am using translation API to convert mp3 file to text and pass mp3 file as multipart file in translation API.

Welcome to the dev forum @nimesh

I’d recommend sharing the complete error, as it’s likely to include more details than just the 400 which just means invalid request.