Step-by-step guide for Grok 2 and Grok Beta
xAI offers generous free credits for new API users:
This is enough for hundreds of AI ethical assessments!
Visit the xAI developer console at:
console.x.aiSign up using:
You may receive a verification email. Click the link to verify your account.
xAI may ask for phone verification depending on your region and account type. If prompted, enter your phone number and the verification code.
Your API key will look something like this:
xai-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456789...Click the copy button to copy it to your clipboard.
New xAI accounts receive $25 in free credits. To check your balance:
A single AI Health Check assessment costs approximately $0.02-0.05 with Grok 2, so your free credits will cover many assessments.
Now that you have your API key, you can use it with AI Assess Tech:
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;
});https://api.x.ai/v1.| Model | Input (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.
Make sure you copied the entire key including the "xai-" prefix. Check for any extra spaces before or after the key.
xAI has rate limits based on your account tier. Wait a minute and try again, or check your account for rate limit details.
Your free credits may have been used up. Add a payment method in the xAI Console to continue using the API.
Make sure you're using a valid model name like grok-2 orgrok-beta. Model names are case-sensitive.
Now that you have your xAI Grok API key, you can run your first AI ethical assessment: