Docs

Documentation versions (currently viewingVaadin 24)
Documentation translations (currently viewingEnglish)

API Key for your IDE

Learn how to configure environment variables and API keys in IntelliJ IDEA so your Vaadin application can access AI and LLM services.

To connect your Vaadin application with an AI provider such as OpenAI, you could access the environment variable or configure the API key specifically for a project in IntelliJ IDEA. The recommended approach is to use environment variables instead of hardcoding the key in your source code or IDE settings.

Warning

Never commit API keys to source control. Use environment variables or IDE run configurations instead.

Using Environment Variables

You can directly reference environment variables in your application.properties or application.yml. This allows you to reuse the same key across multiple projects and keeps your code clean.

Source code
properties
spring.ai.openai.api-key=${OPENAI_API_KEY}

Configuring the API key in IntelliJ IDEA

If you prefer to manage the key within IntelliJ IDEA, you have several options:

  • Run/Debug configuration - add the environment variable OPENAI_API_KEY in Run → Edit Configurations → Environment Variables.

  • Maven runner settings - configure the key under Settings → Build, Execution, Deployment → Build Tools → Maven → Runner.

  • VM options - pass the key as a system property, for example: -DOPENAI_API_KEY=your-key.

configuration intellij

With these approaches, your Vaadin application can access the OpenAI API key securely during development.