#how can i change api key?

1 messages · Page 1 of 1 (latest)

verbal sundial
#

how can i change api key?

atomic vaultBOT
#

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

verbal sundial
#

@fringe sage

fringe sageBOT
# verbal sundial how can i change api key?

Change it on the gateway host (the machine running openclaw gateway) and then restart the gateway.

Most common way (daemon-safe): edit ~/.openclaw/.env

  1. Open ~/.openclaw/.env and replace the key, e.g.
    • Anthropic: ANTHROPIC_API_KEY=...
    • OpenAI: OPENAI_API_KEY=...
  2. Restart the gateway:
    openclaw gateway restart
    
  3. Verify:
    openclaw models status
    # optional (live probe):
    openclaw models status --probe
    
#

Docs: https://docs.openclaw.ai/gateway/authentication

Alternative: re-run the wizard (stores keys for you)

openclaw onboard
# or non-interactive:
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
openclaw onboard --openai-api-key "$OPENAI_API_KEY"

Docs: https://docs.openclaw.ai/providers/anthropic and https://docs.openclaw.ai/providers/openai

If you’re in multi-agent / remote mode

  • Auth is per-agent (stored under ~/.openclaw/agents/<agentId>/agent/auth-profiles.json)
  • If your client is “remote”, the key must be changed on the remote gateway machine, not your laptop.

Which provider are you trying to update (Anthropic / OpenAI / OpenRouter / something else)?

verbal sundial
fringe sageBOT
#

If it says “no such file or directory”, that usually just means the folder/file doesn’t exist yet (that’s fine — you can create it).

On Ubuntu terminal:

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

Then add one line (don’t post your key in Discord):

  • For Anthropic:
    ANTHROPIC_API_KEY=sk-ant-...
    
  • For OpenAI:
#
  OPENAI_API_KEY=sk-...

Save, then restart + verify:

openclaw gateway restart
openclaw models status

If you still can’t find it, you might be:

  • editing the wrong machine (remote mode = edit the gateway host), or
  • running the gateway under a different user/state dir.

Run these and paste the output (redact any tokens/keys):

#

I’m here — no need to ping.

If you ran nano ~/.openclaw/.env and it still says “no such file”, paste the exact error text.

Also please run these on the same machine/user that runs the gateway, and paste the output (redact any tokens/keys):

openclaw --version
openclaw gateway status
echo "STATE_DIR=$OPENCLAW_STATE_DIR"
ls -la ~/.openclaw

Most common gotcha: you’re editing ~/.openclaw for your user, but the gateway is running as a different user (or on a different host in remote mode).

#
openclaw --version
openclaw gateway status
echo "$OPENCLAW_STATE_DIR"
ls -la ~/.openclaw
#

In Ubuntu terminal, if it says “No such file or directory”, you just need to create the folder/file first:

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

Then add your key (example):

  • Anthropic:
ANTHROPIC_API_KEY=sk-ant-...
  • OpenAI:
#
OPENAI_API_KEY=sk-...

Save, then restart + verify:

openclaw gateway restart
openclaw models status

If you already did this and still get the error, paste the exact command you typed and the exact error output (don’t paste the actual key). Most common gotcha is a typo in the path (missing the leading . in .openclaw or .env).

fringe sageBOT
# verbal sundial How to access that in the ubuntu terminal?

On Ubuntu, ~/.openclaw/.env is just a normal hidden file in your home directory. You edit it like any other file.

1) Create the directory + file (if missing), then edit

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

Add your key on its own line (example):

  • ANTHROPIC_API_KEY=sk-ant-...
    or
  • OPENAI_API_KEY=sk-...

Save in nano: Ctrl+O, Enter, then Ctrl+X.

2) Restart gateway + verify

#
openclaw gateway restart
openclaw models status

If it STILL says “no such file or directory”

Two common causes:

  1. Typo in the path (must be .openclaw with the dot):
ls -la ~
ls -la ~/.openclaw
  1. The gateway is running as a different Linux user (so ~/.openclaw is different).
    Check which user runs it: