xai-auth

xAI Grok API authentication and setup. Use when configuring xAI API access, setting up API keys, or troubleshooting authentication issues.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "xai-auth" with this command: npx skills add adaptationio/skrillz/adaptationio-skrillz-xai-auth

xAI Grok API Authentication

Complete guide for setting up and managing xAI API authentication for Grok models with Twitter/X integration.

Quick Start

1. Get API Key

  1. Go to console.x.ai
  2. Sign in with your X (Twitter) account
  3. Navigate to "API Keys" section
  4. Click "Create API Key"
  5. Copy and save the key (starts with xai-)

2. Set Environment Variable

# Add to .bashrc, .zshrc, or .env
export XAI_API_KEY="xai-your-key-here"

3. Test Connection

curl https://api.x.ai/v1/models \
  -H "Authorization: Bearer $XAI_API_KEY"

Authentication Methods

Method 1: Environment Variable (Recommended)

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("XAI_API_KEY"),
    base_url="https://api.x.ai/v1"
)

Method 2: Direct Key

from openai import OpenAI

client = OpenAI(
    api_key="xai-your-key-here",
    base_url="https://api.x.ai/v1"
)

Method 3: Using xai-sdk

from xai_sdk import Client

client = Client(api_key=os.getenv("XAI_API_KEY"))

API Compatibility

xAI API is fully compatible with OpenAI SDK:

# Just change base_url - everything else works the same
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("XAI_API_KEY"),
    base_url="https://api.x.ai/v1"  # Only difference
)

response = client.chat.completions.create(
    model="grok-3-fast",  # Use Grok models
    messages=[{"role": "user", "content": "Hello!"}]
)

Free Credits

$150/Month Free Credits

  1. Go to console.x.ai
  2. Navigate to Settings → Data Sharing
  3. Enable data sharing opt-in
  4. Receive $150/month in API credits

Credit Usage

ActionCost
Grok 4.1 Fast (input)$0.20/1M tokens
Grok 4.1 Fast (output)$0.50/1M tokens
X Search / Web Search$5/1,000 calls
Code Execution$5/1,000 calls

Configuration File

Create .env.xai:

# xAI API Configuration
XAI_API_KEY=xai-your-key-here
XAI_BASE_URL=https://api.x.ai/v1
XAI_DEFAULT_MODEL=grok-3-fast

Error Handling

Common Errors

ErrorCauseSolution
no creditsNo credits on accountAdd credits or enable free tier
invalid_api_keyWrong or expired keyGenerate new key at console.x.ai
rate_limit_exceededToo many requestsImplement backoff, reduce frequency
model_not_foundInvalid model nameCheck available models

Python Error Handling

from openai import OpenAI, APIError, RateLimitError

client = OpenAI(
    api_key=os.getenv("XAI_API_KEY"),
    base_url="https://api.x.ai/v1"
)

try:
    response = client.chat.completions.create(
        model="grok-3-fast",
        messages=[{"role": "user", "content": "Hello"}]
    )
except RateLimitError:
    print("Rate limit hit, waiting...")
    time.sleep(60)
except APIError as e:
    print(f"API error: {e}")

Security Best Practices

  1. Never commit API keys to git
  2. Use environment variables instead of hardcoding
  3. Rotate keys regularly via console.x.ai
  4. Use separate keys for dev/prod environments
  5. Add to .gitignore:
    .env
    .env.*
    **/secrets.*
    

Rate Limits

ModelRequests/MinTokens/Min
Grok 4.1 Fast60100,000
Grok 43050,000
Grok 3 Mini100200,000

Endpoints

EndpointDescription
https://api.x.ai/v1/chat/completionsChat completions
https://api.x.ai/v1/modelsList available models
https://api.x.ai/v1/responsesAgent Tools API

Related Skills

  • xai-models - Model selection guide
  • xai-x-search - Twitter/X search
  • xai-sentiment - Sentiment analysis

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

finnhub-api

No summary provided by upstream source.

Repository SourceNeeds Review
General

auto-updater

No summary provided by upstream source.

Repository SourceNeeds Review
General

todo-management

No summary provided by upstream source.

Repository SourceNeeds Review