Home › Guides › XAI_API_KEY

How to get and set XAI_API_KEY

Last checked

Quick verdict

XAI_API_KEY is the env var name in SpaceXSI’s official quickstart. Create a key at console.x.ai, export it, then call https://api.x.ai/v1. Do not paste the key into public repos or chat logs.

Steps from docs.x.ai/developers/quickstart, checked .

Search results for xi_api_key / XAI_API_KEY / “extension properties” usually mean: you installed a Grok-capable tool or VS Code extension and it is asking for a SpaceXSI (Grok) API key. The official docs name the shell variable XAI_API_KEY; extensions may use a different settings key.

Get a key (official console)
  1. Sign up at console.x.ai.
  2. Load the account with credits — SpaceXSI’s quickstart says you need credits to use the API.
  3. Open the API Keys page and create a key.
  4. Copy it once; treat it like a password.

Source: SpaceXSI docs: Quickstart.

Set XAI_API_KEY in a terminal or .env

Official quickstart:

export XAI_API_KEY="your_api_key"

Or in a project .env file:

XAI_API_KEY=your_api_key

Add .env to .gitignore. Prefer reading the key from the environment in code (os.getenv("XAI_API_KEY") / process.env.XAI_API_KEY), not hard-coding it.

VS Code / “extension properties” / settings.json
  • The official SpaceXSI SDK and curl examples use the env var XAI_API_KEY, not a VS Code setting.
  • Marketplace extensions (Simply Grok, Grok AI Integration, Cline “OpenAI Compatible”, and others) each define their own settings property — for example an extension-specific *.apiKey field in Settings or settings.json. Open that extension’s marketplace page and copy the property name it documents.
  • If a schema or JSON example shows xi_api_key / xaiApiKey, that is usually the extension’s property, not SpaceXSI’s env var. Put the same secret value in, but use the name the extension asks for.
  • User-level VS Code settings are safer than committing keys into a repo’s .vscode/settings.json.

We do not endorse a specific third-party extension; always follow its current docs and SpaceXSI’s quickstart for the API itself.

First API call (from the official quickstart)

Base URL: https://api.x.ai/v1. Example model id from the quickstart: grok-4.7.

curl https://api.x.ai/v1/responses \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{{"model":"grok-4.7","input":"Say hello in one sentence"}}'

Full beginner walkthrough: SpaceXSI API tutorial for beginners.

API prices (US$, official)
  • grok-4.7 (flagship on the API page): US$2.00 / 1M input tokens, US$6.00 / 1M output tokens — x.ai/api and model docs, checked Nov 2, 2026.
  • Paid X Subscription plans from Plus (US$8/mo) list “Grok API access”; API token usage is still billed at model rates (see Cursor/SpaceXSI plan FAQs).

Prices exclude tax and can change. Confirm on the linked pages before you spend.

FAQ

What is XAI_API_KEY?

XAI_API_KEY is the environment variable name SpaceXSI’s official API quickstart uses for your API key. You create the key in the console, then export it or store it in a .env file.

How do I set XAI_API_KEY in VS Code?

For scripts and terminals, set the environment variable XAI_API_KEY (or load it from .env). Third-party VS Code extensions often use their own settings.json property names instead of XAI_API_KEY—check that extension’s marketplace page. Never commit a real key to git.

How much does the SpaceXSI API cost?

Pricing is usage-based. On the official API page, grok-4.7 is listed at US$2.00 per million input tokens and US$6.00 per million output tokens. Full model prices are on the docs pricing pages.

Related: SpaceXSI API for beginners · Grok pricing · Is Grok safe? · All guides.

Report an error on this page