"'image' is a required property" with openfeign in Spring boot

I always get his error “‘image’ is a required property” even tho I’m providing the image in the request. Here is the config of the feign:

@Configuration
@Slf4j
public class OpenAiClientConfig {
    @Value("${spring.ai.openai.image.base-url}")
    String openAiBaseUrl;
    @Autowired
    private ObjectFactory<HttpMessageConverters> converters;
    @Bean
    @Primary
    @Scope("prototype")
    public Encoder encoder() {
        return new SpringFormEncoder(new SpringEncoder(converters));
    }

    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> {
            String requestUrl = openAiBaseUrl + "/v1/images/edits";

            requestTemplate.target(requestUrl);
            log.info("Request intercepted: {} with method: {}", requestTemplate.url(), requestTemplate.method());
        };
    }
}

here is the client:

@FeignClient(name = "dalleeditor", configuration = OpenAiClientConfig.class)
public interface OpenAiApiClient {
    @PostMapping()
    ImageResponseBody getEditedImage(@RequestHeader("Authorization") String bearerToken,
                                     @RequestHeader("Content-Type") String contentType,
                                     @RequestParam(name = "image") final MultipartFile image,
                                     @RequestParam(name = "prompt") final String prompt,
                                     @RequestParam(name = "model", required = false) final String model,
                                     @RequestParam(name = "n", required = false) final Integer n,
                                     @RequestParam(name = "response_format", required = false) final String responseFormat,
                                     @RequestParam(name = "size", required = false) final String size,
                                     @RequestParam(name = "user", required = false) String user
    );
}

and here is where i call it:

String authorization = "bearer " + openAiKey;
        String contentType = "multipart/form-data; boundary=${boundary}";

        log.info("sending request to openai");
        ImageResponseBody response = openAiApiClient.getEditedImage(
                authorization, contentType, imageRequestBody.getImage(), imageRequestBody.getPrompt(),
                imageRequestBody.getModel(),
                imageRequestBody.getN(), imageRequestBody.getResponseFormat(), imageRequestBody.getSize(), null);

Please help because I m giving up here. :skull:

1 Like

This might be useful…

Also relevant maybe…

Looks like you’re setting boundary, though…

OpenAI requires the image to be Base64 encoded, so check that too… You can pass the image via an URL too…

Actually it was solved I removed the boundary thing, and changed the anotation from @requestparam to @Requestpart