Skip to content

API keys & environment

A model-backed DyUI app needs one API key, for the provider in its model string. The examples in these docs default to nvidia/... models, which read NVIDIA_API_KEY. build.nvidia.com gives you one for free.

The quickest setup is a .env file next to app.py:

.env
NVIDIA_API_KEY=nvapi-...
Terminal window
dyui run app.py

dyui run loads that file before it imports your app and prints the names it loaded (never the values):

dyui: loaded .env (1 key: NVIDIA_API_KEY)

The model string’s prefix picks the provider, and each provider reads its key from its own variable. Every provider except Anthropic is reached through the openai SDK, so install pip install "dyui[openai]" for all of them, or "dyui[anthropic]" for Claude.

Prefix Variable Get a key Keys look like Notes
nvidia/ NVIDIA_API_KEY build.nvidia.com nvapi-... Free tier; the docs’ default
openai/ OPENAI_API_KEY platform.openai.com/api-keys sk-... Paid
anthropic/ ANTHROPIC_API_KEY console.anthropic.com sk-ant-... Paid; needs dyui[anthropic]
groq/ GROQ_API_KEY console.groq.com/keys gsk_... Free tier
openrouter/ OPENROUTER_API_KEY openrouter.ai/keys sk-or-... Some free models
gemini/ GEMINI_API_KEY or GOOGLE_API_KEY aistudio.google.com/apikey AIza... Free tier
together/ TOGETHER_API_KEY api.together.ai Paid
deepseek/ DEEPSEEK_API_KEY platform.deepseek.com sk-... Paid
mistral/ MISTRAL_API_KEY console.mistral.ai Free tier for some models
xai/ XAI_API_KEY console.x.ai xai-... Paid
ollama/ none runs on your machine OLLAMA_API_KEY is sent if set

Each provider’s endpoint and its base-URL variable are listed on Models & providers. Free tiers limit requests per minute; see rate limits.

A .env file holds one NAME=value per line:

.env
# comments and blank lines are ignored
NVIDIA_API_KEY=nvapi-...
DYUI_MODEL=nvidia/deepseek-ai/deepseek-v4.1-flash
APP_PASSWORD="a long passphrase # with a hash"
  • dyui run looks for .env next to the app file, then in the current directory, and loads the first one it finds.
  • A variable that is already set in your shell or platform is never overridden, so NVIDIA_API_KEY=other dyui run still wins over the file.
  • Quotes are optional. Inside double quotes \n is a newline; single quotes are taken literally. An export prefix is allowed, and there is no $VAR expansion.
  • Restart dyui run after you edit .env. The reloader restarts your app on code changes, but the file is read once at startup.
Terminal window
dyui run app.py --env-file prod.env # load another file instead
dyui run app.py --no-env-file # load none

You can keep the model in .env too: DYUI_MODEL is read by the examples in these docs (MODEL = os.getenv("DYUI_MODEL", "nvidia/...")), which makes switching providers the same on every operating system.

Use the shell instead of a file when you don’t want the key on disk in the project, or in CI.

Terminal window
export NVIDIA_API_KEY=nvapi-...
dyui run app.py

This lasts until you close the terminal. To keep it, add the export line to ~/.zshrc (macOS) or ~/.bashrc (Linux). For one command only: NVIDIA_API_KEY=nvapi-... dyui run app.py.

dyui.llm.stream reads the provider’s variable only when you don’t pass api_key=. Pass it explicitly when the key comes from a secrets manager, a vault or per-user settings. Inside your handler:

async for part in dyui.llm.stream(
"nvidia/moonshotai/kimi-k2.6",
chat.history,
components=app.catalog,
api_key=load_secret("nvidia-api-key"), # your own lookup
base_url="https://my-gateway.example.com/v1", # optional: a proxy or gateway
):
yield part

For Azure OpenAI, custom HTTP settings or a proxy, build the SDK client yourself and pass client=; see OpenAI. With your own SDK calls, DyUI never sees the key at all; see Bring your own SDK.

dyui run is the development server. Elsewhere, set the variables the way that tool expects:

Where How
Uvicorn uvicorn app:app --env-file .env (Uvicorn’s own loader, which also never overrides)
Docker docker run --env-file .env my-bot, or -e NVIDIA_API_KEY. Docker keeps quotes as part of the value, so leave values unquoted. See Docker.
Render, Fly, Railway The platform’s secrets or environment variables; see Render, Fly & Railway
CI, tests Your CI’s secret store, exposed as an environment variable

Don’t copy .env into an image: the .dockerignore on the Docker page leaves it out. DyUI never sends keys to the browser.

What you see What to do
“NVIDIA_API_KEY is not set (needed for ‘nvidia/’ models)…” in the chat DyUI found no key before calling the provider. Check that .env is next to app.py (or in the directory you run from), that the name is spelled exactly, and that dyui run printed loaded .env (… NVIDIA_API_KEY). Restart dyui run after editing .env.
“The model provider rejected the API key (401)” The key is wrong, revoked, or for another provider. An nvapi- key only works with nvidia/ models, sk-ant- only with anthropic/, and so on.
The shell has the key but the app doesn’t Variables only reach programs started from that terminal. After setx, open a new one. IDE run buttons have their own environment settings.
“The model provider’s rate limit was reached” A free-tier limit (HTTP 429). DyUI retries short waits by itself; see rate limits to make requests smaller.
MissingDependencyError: … pip install "dyui[openai]" Install the SDK extra the error names.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.