High severity beginner · Fix: 2-5 min

wandb.errors.UsageError

wandb.errors.UsageError: You must run `wandb login` before using wandb in non-interactive mode

What this error means
Weights & Biases (wandb) requires authentication via `wandb login` before usage in non-interactive environments, otherwise it raises a UsageError.

Stack trace

traceback
wandb.errors.UsageError: You must run `wandb login` before using wandb in non-interactive mode
  File "/usr/local/lib/python3.9/site-packages/wandb/sdk/wandb_init.py", line 123, in _init
    raise UsageError("You must run `wandb login` before using wandb in non-interactive mode")
QUICK FIX
Set the WANDB_API_KEY environment variable with your API key before running wandb to bypass interactive login.

Why it happens

wandb requires an API key to authenticate users before logging runs. In non-interactive environments like CI/CD or servers without a terminal, the automatic login prompt cannot run, causing this error if no API key is pre-configured.

Detection

Detect this error by catching wandb.errors.UsageError during wandb.init() calls and checking for the login prompt message in logs before failure.

Causes & fixes

1

No wandb API key configured in environment or config file in a non-interactive environment

✓ Fix

Set the WANDB_API_KEY environment variable with your API key before running your script, e.g. export WANDB_API_KEY='your_api_key'

2

Running wandb.init() in a CI/CD pipeline or server without prior login

✓ Fix

Use `wandb login --relogin` in a setup step or configure the API key environment variable in the pipeline before execution

3

Attempting to login interactively in a headless or non-interactive environment

✓ Fix

Avoid interactive login prompts by pre-setting the API key or using wandb.login(key='your_api_key') programmatically

Code: broken vs fixed

Broken - triggers the error
python
import wandb
wandb.init(project="my-project")  # triggers UsageError in non-interactive env without login
Fixed - works correctly
python
import os
import wandb
os.environ["WANDB_API_KEY"] = "your_api_key_here"  # Set API key to avoid login error
wandb.init(project="my-project")  # now works without interactive login
Added WANDB_API_KEY environment variable to authenticate wandb non-interactively, preventing the login prompt error.

Workaround

Wrap wandb.init() in try/except wandb.errors.UsageError, then programmatically call wandb.login(key=os.environ.get('WANDB_API_KEY')) if available to authenticate before retrying.

Prevention

Always configure the WANDB_API_KEY environment variable or use wandb.login(key=...) in your deployment pipelines and non-interactive environments to ensure authentication without manual login.

Python 3.6+ · wandb >=0.10.0 · tested on 0.15.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.