Docs

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

API Key for your IDE

Configure environment variables or use a .env file in Visual Studio Code to provide API keys for your Vaadin project.

In Visual Studio Code you can configure environment variables for your project in different ways:

  • Add the variable directly in .vscode/launch.json:

    Source code
    JSON
    {
      "configurations": [
        {
          "type": "java",
          "name": "Launch Vaadin App",
          "request": "launch",
          "mainClass": "com.example.Application",
          "env": {
            "OPENAI_API_KEY": "your-key-here"
          }
        }
      ]
    }
  • Store the variable in a .env file and reference it from launch.json. This allows you to add .env to .gitignore to avoid committing keys.

Source code
JSON
{
  "configurations": [
    {
      "type": "java",
      "name": "Launch Vaadin App",
      "request": "launch",
      "mainClass": "com.example.Application",
      "envFile": "${workspaceFolder}/.env"
    }
  ]
}

You can then reference the variable in your configuration files:

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