Keys / xAI

XAI_API_KEY

The xAI API key your app calls Grok models with. Each key belongs to one team.

Starts with
xai-
Expires
you choose, or never
API
create, list, update, rotate and delete, with a management key

Get it

Create one on console.x.ai/team/default/api-keys. The steps aren't recorded yet.

Set it

XAI_API_KEY=xai-...

The xAI Python SDK reads it from this variable when you don't pass a key. Or keep it out of .env with keypin: keypin run -- npm run dev

Replace it

  1. Rotate the key with the Management API. Set oldSecretExpireTime to keep the old secret working for up to 7 days; it defaults to 24 hours.
  2. Deploy the new secret everywhere that reads XAI_API_KEY before the old one stops working.
  3. Without a management key, create a new key with the same models, endpoints and limits in the console, deploy it, then delete the old one.

Set rotate_every on the key in keypin.toml and a rotated date on its vault item, and keypin status shows when it's due.

Sources, checked 2026-11-16