docs/docs/integrations/image-models/dall-e.md
:::note
This is the documentation for the OpenAI integration, that uses a custom Java implementation of the OpenAI REST API, that works best with Quarkus (as it uses the Quarkus REST client) and Spring (as it uses Spring's RestClient).
LangChain4j provides 3 different integrations with OpenAI for generating images, and this is #1 :
OpenAI uses a custom Java implementation of the OpenAI REST API, that works best with Quarkus (as it uses the Quarkus REST client) and Spring (as it uses Spring's RestClient).
OpenAI Official SDK uses the official OpenAI Java SDK.
Azure OpenAI uses the Azure SDK from Microsoft, and works best if you are using the Microsoft Java stack, including advanced Azure authentication mechanisms.
:::
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>1.17.2</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
<version>1.17.2-beta27</version>
</dependency>
:::note
OpenAI has deprecated the DALL·E 2 and DALL·E 3 models in favor of the new GPT image models
(gpt-image-1, gpt-image-1-mini, gpt-image-1.5, gpt-image-2, chatgpt-image-latest).
The DALL·E-specific parameters style and response-format are no longer supported by the API and
have been removed. New parameters background, output-format, output-compression, and moderation
are available instead.
:::
OpenAiImageModelImageModel model = OpenAiImageModel.builder()
.apiKey(System.getenv("OPENAI_API_KEY"))
.modelName("gpt-image-1")
.build();
Add to the application.properties:
# Mandatory properties:
langchain4j.open-ai.image-model.api-key=${OPENAI_API_KEY}
langchain4j.open-ai.image-model.model-name=gpt-image-1
# Optional properties:
langchain4j.open-ai.image-model.background=...
langchain4j.open-ai.image-model.base-url=...
langchain4j.open-ai.image-model.custom-headers=...
langchain4j.open-ai.image-model.log-requests=...
langchain4j.open-ai.image-model.log-responses=...
langchain4j.open-ai.image-model.max-retries=...
langchain4j.open-ai.image-model.moderation=...
langchain4j.open-ai.image-model.organization-id=...
langchain4j.open-ai.image-model.output-compression=...
langchain4j.open-ai.image-model.output-format=...
langchain4j.open-ai.image-model.project-id=...
langchain4j.open-ai.image-model.quality=...
langchain4j.open-ai.image-model.size=...
langchain4j.open-ai.image-model.timeout=...
langchain4j.open-ai.image-model.user=...