API Key for your IDE
Choose a Java library to call an LLM API from your Vaadin application. For the individual configuration of common models, see each option in the respective documentation:
Set the API Key in Your OS
To access commercial LLMs (e.g., OpenAI or Anthropic) you need to configure an API key to authenticate your requests. The recommended approach is to define the key as an environment variable in your operating system, so it is not hard-coded or committed to source control and can be reused across multiple projects.
Source code
bash
export OPENAI_API_KEY="sk-..."
bash
powershell
powershell
Alternatively, you can provide the API Key as a "local" environment variable or as a Java system property through your IDE’s Run/Debug configuration. You can find detailed instructions in the IDE Quick Guides section below.
You can also give API Keys as VM arguments. The following VM argument sets the OPENAI_API_KEY
system property:
Source code
-DOPENAI_API_KEY=sk-your-key-here
For Spring AI, reference the system property or environment variable in your configuration:
Source code
properties
spring.ai.openai.api-key=${OPENAI_API_KEY}
Warning
| Never commit API keys to source control. Prefer environment variables or your CI/CD secret store. |
IDE Quick Guides
If you’re unsure how to set environment variables in your specific IDE, see:
-
IntelliJ IDEA (Ultimate or Community)
Verify the Setup
Run the application and check that the model call succeeds. If you see authentication errors, confirm the variable is set in the environment that starts the JVM and that your configuration references ${OPENAI_API_KEY}
.
Note
| For Java/IDE requirements and plugins, see Vaadin Prerequisites. |