#Agent lost it's OpenAI key secret randomly and gateway failed

1 messages · Page 1 of 1 (latest)

lone lodge
marsh fieldBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

valid tuskBOT
#

Looks like the gateway isn’t “randomly losing” an OpenClaw secret — it’s configured to read OPENAI_API_KEY from the gateway environment, and the systemd service doesn’t have that env var after restart/update. The paste shows SecretRefResolutionError: Environment variable "OPENAI_API_KEY" is missing or empty, plus the gateway service is failed/stopped. (pastebin.com)

Fix it by making the key visible to the daemon, not just your shell:

mkdir -p ~/.openclaw
nano ~/.openclaw/.env

Add:

OPENAI_API_KEY=sk-...

Then:

#
openclaw gateway restart
openclaw models status
openclaw status

OpenClaw docs specifically recommend ~/.openclaw/.env for systemd/launchd gateways because services often don’t inherit your shell env. (docs.openclaw.ai)

Alternative: rerun onboarding:

openclaw onboard --auth-choice openai-api-key

The security audit warnings are worth cleaning up later, but they’re not the crash cause here.

lone lodge
#

but it was working for 2 days and just poof, and i have 2 screenshots control ui app and the PuTTy tunnel config

valid tuskBOT
#

Yep — that “worked for 2 days then poof” pattern usually means the gateway restarted and lost an env var that only existed in the old shell/session.

PuTTY tunnel/control UI screenshots probably matter for connecting to the dashboard, but the current hard failure is earlier:

Environment variable "OPENAI_API_KEY" is missing or empty
Gateway service: stopped (state failed)

So I’d check:

openclaw gateway status
openclaw models status
systemctl --user cat openclaw-gateway
#

Then make the key daemon-persistent:

mkdir -p ~/.openclaw
nano ~/.openclaw/.env

Add:

OPENAI_API_KEY=sk-...

Then: