3939 * OpenAI Image API.
4040 *
4141 * @see <a href= "https://platform.openai.com/docs/api-reference/images">Images</a>
42+ * @author lambochen
4243 */
4344public class OpenAiImageApi {
4445
4546 public static final String DEFAULT_IMAGE_MODEL = ImageModel .DALL_E_3 .getValue ();
4647
4748 private final RestClient restClient ;
4849
50+ private final String imagesPath ;
51+
4952 /**
5053 * Create a new OpenAI Image API with the provided base URL.
5154 * @param baseUrl the base URL for the OpenAI API.
5255 * @param apiKey OpenAI apiKey.
5356 * @param headers the http headers to use.
57+ * @param imagesPath the images path to use.
5458 * @param restClientBuilder the rest client builder to use.
5559 * @param responseErrorHandler the response error handler to use.
5660 */
57- public OpenAiImageApi (String baseUrl , ApiKey apiKey , MultiValueMap <String , String > headers ,
61+ public OpenAiImageApi (String baseUrl , ApiKey apiKey , MultiValueMap <String , String > headers , String imagesPath ,
5862 RestClient .Builder restClientBuilder , ResponseErrorHandler responseErrorHandler ) {
5963
6064 // @formatter:off
@@ -69,14 +73,16 @@ public OpenAiImageApi(String baseUrl, ApiKey apiKey, MultiValueMap<String, Strin
6973 .defaultStatusHandler (responseErrorHandler )
7074 .build ();
7175 // @formatter:on
76+
77+ this .imagesPath = imagesPath ;
7278 }
7379
7480 public ResponseEntity <OpenAiImageResponse > createImage (OpenAiImageRequest openAiImageRequest ) {
7581 Assert .notNull (openAiImageRequest , "Image request cannot be null." );
7682 Assert .hasLength (openAiImageRequest .prompt (), "Prompt cannot be empty." );
7783
7884 return this .restClient .post ()
79- .uri ("v1/images/generations" )
85+ .uri (this . imagesPath )
8086 .body (openAiImageRequest )
8187 .retrieve ()
8288 .toEntity (OpenAiImageResponse .class );
@@ -163,12 +169,20 @@ public static class Builder {
163169
164170 private ResponseErrorHandler responseErrorHandler = RetryUtils .DEFAULT_RESPONSE_ERROR_HANDLER ;
165171
172+ private String imagesPath = "v1/images/generations" ;
173+
166174 public Builder baseUrl (String baseUrl ) {
167175 Assert .hasText (baseUrl , "baseUrl cannot be null or empty" );
168176 this .baseUrl = baseUrl ;
169177 return this ;
170178 }
171179
180+ public Builder imagesPath (String imagesPath ) {
181+ Assert .hasText (imagesPath , "imagesPath cannot be null or empty" );
182+ this .imagesPath = imagesPath ;
183+ return this ;
184+ }
185+
172186 public Builder apiKey (ApiKey apiKey ) {
173187 Assert .notNull (apiKey , "apiKey cannot be null" );
174188 this .apiKey = apiKey ;
@@ -201,7 +215,7 @@ public Builder responseErrorHandler(ResponseErrorHandler responseErrorHandler) {
201215
202216 public OpenAiImageApi build () {
203217 Assert .notNull (this .apiKey , "apiKey must be set" );
204- return new OpenAiImageApi (this .baseUrl , this .apiKey , this .headers , this .restClientBuilder ,
218+ return new OpenAiImageApi (this .baseUrl , this .apiKey , this .headers , this .imagesPath , this . restClientBuilder ,
205219 this .responseErrorHandler );
206220 }
207221
0 commit comments