Back to API Keys Guide
$25 Free Credits

How to Get an xAI Grok API Key

Step-by-step guide for Grok 2 and Grok Beta

2-3 minutes
$25 free credits
No credit card required initially
$25 Free Credits for New Accounts

xAI offers generous free credits for new API users:

  • $25 in free API credits upon signup
  • No credit card required to get started
  • Credits don't expire (unlike some providers)

This is enough for hundreds of AI ethical assessments!

Before You Start
  • A valid email address
  • Phone number for verification (may be required)
Note: xAI is the company behind Grok, founded by Elon Musk. The API is separate from the Grok chatbot on X (Twitter).

Step-by-Step Instructions

1

Go to xAI Console

Visit the xAI developer console at:

console.x.ai
2

Create Your Account

Sign up using:

  • Email: Enter your email and create a password
  • X (Twitter): Sign up with your X account
  • Google: Sign up with your Google account

You may receive a verification email. Click the link to verify your account.

3

Verify Your Identity (if required)

xAI may ask for phone verification depending on your region and account type. If prompted, enter your phone number and the verification code.

4

Navigate to API Keys

  1. Once logged in, go to the API Keys section
  2. Or navigate directly to: console.x.ai/api-keys
5

Create Your API Key

  1. Click "Create API Key" or "+ New Key"
  2. Give your key a name (e.g., "AI Assess Tech Testing")
  3. Click "Create"
Important! Your API key will only be shown once. Copy it immediately and store it somewhere safe. You cannot view the full key again after closing this dialog.
6

Copy Your API Key

Your API key will look something like this:

xai-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456789...

Click the copy button to copy it to your clipboard.

Check Your Free Credits

New xAI accounts receive $25 in free credits. To check your balance:

  1. Go to your xAI Console dashboard
  2. Look for the "Credits" or "Usage" section
  3. View your remaining balance

A single AI Health Check assessment costs approximately $0.02-0.05 with Grok 2, so your free credits will cover many assessments.

Using Your API Key with AI Assess Tech

Now that you have your API key, you can use it with AI Assess Tech:

Option 1: Demo Tool (aiassessmenttool.com)

  1. Go to aiassessmenttool.com
  2. Select "xAI Grok" as your provider
  3. Paste your API key in the API Key field
  4. Choose your model (Grok 2 or Grok Beta)
  5. Click "Start Assessment"

Option 2: SDK Integration

import { AIAssessClient } from '@aiassesstech/sdk';

const client = new AIAssessClient({
  healthCheckKey: process.env.AIASSESS_KEY
});

const result = await client.assess(async (question) => {
  const response = await fetch('https://api.x.ai/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.XAI_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      model: 'grok-2',
      messages: [{ role: 'user', content: question }]
    })
  });
  
  const data = await response.json();
  return data.choices[0].message.content;
});
API Compatibility: Grok's API is compatible with the OpenAI SDK format. You can also use the OpenAI SDK by changing the base URL to https://api.x.ai/v1.
xAI Grok Pricing (as of 2026)
ModelInput (per 1M tokens)Output (per 1M tokens)Est. Cost per Assessment
Grok 2 Recommended$2.00$10.00~$0.15
Grok 2 Mini$0.20$1.00~$0.02
Grok Beta$5.00$15.00~$0.25

Prices are approximate and may change. Check x.ai/api for current rates.

Troubleshooting

"Invalid API Key" error

Make sure you copied the entire key including the "xai-" prefix. Check for any extra spaces before or after the key.

"Rate limit exceeded" error

xAI has rate limits based on your account tier. Wait a minute and try again, or check your account for rate limit details.

"Insufficient credits" error

Your free credits may have been used up. Add a payment method in the xAI Console to continue using the API.

"Model not found" error

Make sure you're using a valid model name like grok-2 orgrok-beta. Model names are case-sensitive.

Ready to Test Your AI?

Now that you have your xAI Grok API key, you can run your first AI ethical assessment: