Pass the API key as a command-line flag
api keys and auth
// what it does
The --api-key flag (short -k) supplies the key for a single run and takes priority over GROK_API_KEY and the settings file. Useful for testing a second key or acting as another account without editing your environment.
// shell
$ grok --api-key xai-your-key$ grok -k xai-your-key -p "list open TODOs"// gotcha
A key passed on the command line lands in your shell history and is visible via ps to other users on the machine. On shared hosts prefer the environment variable or the user-settings file.