Set your Grok API key with an environment variable
api keys and auth
// what it does
Grok CLI reads GROK_API_KEY at startup. Export it in the current shell for a one-off, or append it to ~/.zshrc so every new terminal inherits it. xAI keys begin with xai- and are created in the API Keys section of console.x.ai.
// shell
$ export GROK_API_KEY=xai-your-key$ echo 'export GROK_API_KEY=xai-your-key' >> ~/.zshrc// gotcha
The key's secret value is shown only once when you create it in the xAI console — lose it and you must generate a new one. Keep it out of version control; a leaked xai- key bills tokens to your account until you rotate it.