4141 * OpenAI Image API.
4242 *
4343 * @see <a href= "https://platform.openai.com/docs/api-reference/images">Images</a>
44+ * @author lambochen
4445 */
4546public class OpenAiImageApi {
4647
4748 public static final String DEFAULT_IMAGE_MODEL = ImageModel .DALL_E_3 .getValue ();
4849
4950 private final RestClient restClient ;
5051
52+ private final String imagesPath ;
53+
5154 /**
5255 * Create a new OpenAI Image API with the provided base URL.
5356 * @param baseUrl the base URL for the OpenAI API.
5457 * @param apiKey OpenAI apiKey.
5558 * @param headers the http headers to use.
59+ * @param imagesPath the images path to use.
5660 * @param restClientBuilder the rest client builder to use.
5761 * @param responseErrorHandler the response error handler to use.
5862 */
59- public OpenAiImageApi (String baseUrl , ApiKey apiKey , MultiValueMap <String , String > headers ,
63+ public OpenAiImageApi (String baseUrl , ApiKey apiKey , MultiValueMap <String , String > headers , String imagesPath ,
6064 RestClient .Builder restClientBuilder , ResponseErrorHandler responseErrorHandler ) {
6165
6266 // @formatter:off
@@ -70,14 +74,16 @@ public OpenAiImageApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, Strin
7074 .defaultStatusHandler (responseErrorHandler )
7175 .build ();
7276 // @formatter:on
77+
78+ this .imagesPath = imagesPath ;
7379 }
7480
7581 public ResponseEntity <OpenAiImageResponse > createImage (OpenAiImageRequest openAiImageRequest ) {
7682 Assert .notNull (openAiImageRequest , "Image request cannot be null." );
7783 Assert .hasLength (openAiImageRequest .prompt (), "Prompt cannot be empty." );
7884
7985 return this .restClient .post ()
80- .uri ("v1/images/generations" )
86+ .uri (this . imagesPath )
8187 .body (openAiImageRequest )
8288 .contentType (MediaType .APPLICATION_JSON )
8389 .retrieve ()
@@ -233,12 +239,20 @@ public static class Builder {
233239
234240 private ResponseErrorHandler responseErrorHandler = RetryUtils .DEFAULT_RESPONSE_ERROR_HANDLER ;
235241
242+ private String imagesPath = "v1/images/generations" ;
243+
236244 public Builder baseUrl (String baseUrl ) {
237245 Assert .hasText (baseUrl , "baseUrl cannot be null or empty" );
238246 this .baseUrl = baseUrl ;
239247 return this ;
240248 }
241249
250+ public Builder imagesPath (String imagesPath ) {
251+ Assert .hasText (imagesPath , "imagesPath cannot be null or empty" );
252+ this .imagesPath = imagesPath ;
253+ return this ;
254+ }
255+
242256 public Builder apiKey (ApiKey apiKey ) {
243257 Assert .notNull (apiKey , "apiKey cannot be null" );
244258 this .apiKey = apiKey ;
@@ -271,7 +285,7 @@ public Builder responseErrorHandler(ResponseErrorHandler responseErrorHandler) {
271285
272286 public OpenAiImageApi build () {
273287 Assert .notNull (this .apiKey , "apiKey must be set" );
274- return new OpenAiImageApi (this .baseUrl , this .apiKey , this .headers , this .restClientBuilder ,
288+ return new OpenAiImageApi (this .baseUrl , this .apiKey , this .headers , this .imagesPath , this . restClientBuilder ,
275289 this .responseErrorHandler );
276290 }
277291
0 commit comments