API Key Security - Good Practices
oakapp.toml), which is not recommended because you can accidentally reveal sensitive access information to the public. Instead, we encourage secure handling patterns that avoid committing secrets into source control.General Recommendations
- Never commit API keys directly into repositories (e.g.,
.toml,.json,.yaml, or.pyfiles under git). - Prefer using environment variables or
.envfiles (excluded from git via.gitignore). - For deployment on hub.luxonis.com, use built-in key management tools (
oakctl, web UI) rather than hardcoding. - Keep
.envfiles local only, and avoid sharing them.
Modes & Secure Setup Options
Standalone Mode
Peripheral Mode
Standalone Mode
Hub setup
Local setup
Option 1 - Device adopted
DEPTHAI_HUB_API_KEY is already set up correctly and you can run your app locally with:Command Line
1oakctl app run .Option 2 - Override the Key
DEPTHAI_HUB_API_KEY value. In this case, have your main main.py take the parameter with load_dotenvPython
1import os
2from dotenv import load_dotenv
3
4load_dotenv(override=True)
5
6print(os.environ["DEPTHAI_HUB_API_KEY"]).env file next to main.py:Command Line
1cd <INSERT_PATH_TO_PROJECT>
2echo "DEPTHAI_HUB_API_KEY=<INSERT_YOUR_DEPTHAI_HUB_API_KEY>" > .env
3echo ".env" >> .gitignoreCommand Line
1oakctl app run .oakctl ensures that .env file copied over to the App environment on the camera. Then, similarly as for other examples, you need to implement your own mechanism in the App for reading variables from that .env file (for example, using dotenv.load_dotenv()).