Unified.to
All articles

How to Get a Grok (xAI) and Groq API Key — and Connect It to Your Product


February 20, 2026

Updated May 2026

Grok and Groq are two different products that are frequently confused. This guide covers both.

Grok is xAI's family of large language models — the same models powering the Grok assistant on X and grok.com. You access them via the xAI API at api.x.ai.

Groq is an AI inference platform built on custom LPU (Language Processing Unit) hardware. It runs open and permissively licensed models — Llama, Whisper, and others — at speeds significantly faster than GPU-based alternatives. You access it via GroqCloud at api.groq.com.

They are independent companies. Neither owns the other. If you want xAI's Grok models, you need an xAI API key. If you want fast open-source model inference on Groq hardware, you need a Groq API key. Many teams use both.

This guide covers:

  • How to get a Grok (xAI) API key
  • How to get a Groq API key
  • How to connect either — or both — to your product through Unified's Generative AI API and MCP server

Part 1: How to Get a Grok (xAI) API Key

Prerequisites

No X Premium subscription required. The xAI API is a standalone developer product at console.x.ai. You sign up with an email, receive promotional credits, and pay per token after that. X Premium, SuperGrok, and the xAI API are completely separate billing tracks — subscribing to one has no effect on the others.

Step 1: Create an xAI account

Go to https://console.x.ai and sign up. You can register with:

  • Email and password
  • Google SSO
  • X account (linking your X account doesn't change API access or billing)

Signup is self-serve. There is no waiting period and no manual approval queue.

Step 2: Complete initial setup

On first login, the console will prompt you for:

  • Your name and optionally your organization
  • A short description of your intended use case
  • Acceptance of xAI's API terms and usage policies

New accounts receive promotional credits — typically around $25 — to trial the API. Check the xAI Console for the current offer, as promotional amounts are subject to change.

Note: xAI previously ran a data sharing program offering $150/month in API credits to teams that opted in. That program was discontinued in 2025 and is no longer available.

Step 3: Create your API key

In the console, navigate to API Keys in the left sidebar, or go directly to console.x.ai/team/default/api-keys.

Click Create API Key and configure:

  • Key name: use something descriptive — prod-backend, dev-grok, ci-pipeline
  • Team: keys are scoped to a single team; pick the right one if you're in multiple
  • Endpoint access: select which endpoints the key can call
  • Model access: select which Grok models the key can use

The key is shown once. Copy it immediately — xAI does not store the secret value.

Grok API keys start with xai- followed by a long alphanumeric string. If your key doesn't start with xai-, it isn't an xAI key.

Step 4: Store your key securely

export XAI_API_KEY="xai-..."

The official xAI SDK reads XAI_API_KEY automatically. Do not use GROK_API_KEY — that is a non-standard name that will break SDK integrations.

For production: use a secrets manager (AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager). Never commit keys to Git, even in private repos. Never paste keys into Slack, email, or shared docs.

Step 5: Configure billing and spending controls

Go to Billing → Payment Methods and add a credit card before your promotional credits expire (30 days after signup). Configure:

  • Hard monthly cap: the spend ceiling above which xAI stops accepting requests. Set this — a runaway loop without a cap is expensive.
  • Usage alerts: set notifications at 50%, 75%, and 90% of your cap
  • Auto-recharge: useful for production, risky for experimentation

xAI uses pay-as-you-go pricing with no minimum commitment.

Step 6: Test your API key

curl https://api.x.ai/v1/chat/completions \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.3",
    "messages": [
      {"role": "user", "content": "Hello, Grok!"}
    ]
  }'

A successful response returns Grok's reply in JSON. The API base URL is api.x.ai/v1 — don't confuse it with console.x.ai (the dashboard) or grok.com (the consumer chatbot).

Which Grok model should you use?

The current recommended models as of Q2 2026:

ModelBest for
grok-4.3Default recommendation. Strong reasoning, coding, and agentic tool use.
grok-4.20Flagship reasoning model. 2M token context. Best for complex, context-heavy tasks.
Deprecated Grok 4-era model IDs (grok-4, grok-4-fast, grok-4-1-fast-*) were temporarily redirected to newer models during the migration window but are scheduled to stop working after May 15, 2026. Migrate to grok-4.3 or grok-4.20 — calls to deprecated IDs will return errors after that date. Older slugs like grok-1 and grok-2 are no longer active. Consult xAI's Models page for the current list before building.

Real-time X and web data

Grok's real-time data access works through server-side search tools in the tools array of your request — the same shape as OpenAI function calling. There is no boolean flag like enable_x_context: true. Any guide suggesting otherwise is outdated.

Available tools and pricing as of Q2 2026:

ToolCost
Web Search (web_search)$5 per 1,000 successful calls
X Search (x_search)$5 per 1,000 successful calls
Code Execution (code_execution)$5 per 1,000 successful calls
File/Collections Search$2.50 per 1,000 calls
Image/video understandingToken-based only, no per-call fee

Migrating from OpenAI to Grok

The xAI API is OpenAI-compatible. The code change is two lines:

from openai import OpenAI

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

Then call client.chat.completions.create(model="grok-4.3", ...) and the rest of your OpenAI code works unchanged.

Is the Grok API free?

The first ~$25 in promotional credits is free for new accounts. After that, you pay per token. There is no permanent free tier. Once credits expire, you need a payment method on file.

Consumer products — grok.com (free tier chatbot), SuperGrok ($30/month), X Premium — are completely separate from API access and do not grant API credits.

xAI rate limits

xAI enforces per-model RPM and TPM limits that scale with your spend-based tier:

TierCumulative spend since Jan 1, 2026
Tier 0$0
Tier 1$50
Tier 2$250
Tier 3$1,000
Tier 4$5,000
EnterpriseCustom
Higher tiers unlock higher RPM and TPM limits per model. Check your exact limits on the Rate Limits page in the xAI Console — specific values are account-specific and subject to change.

Troubleshooting Grok API errors

401 Unauthorized — invalid API key The key is wrong, expired, or revoked. Check the header format (Authorization: Bearer xai-...), check for trailing whitespace, and regenerate at console.x.ai if needed.

404 model not found You're calling a deprecated or removed model slug. Migrate to grok-4.3 or grok-4.20.

429 rate_limit_exceeded You've exceeded your RPM or TPM limit for your current tier. Implement exponential backoff. Check your current limits in the console and request a tier upgrade if you're consistently hitting them.

402 payment_required Your promotional credits ran out and there's no payment method on file. Add one in the console under Billing.


Part 2: How to Get a Groq API Key

Groq is an inference platform, not a model provider. It runs open and permissively licensed models — Llama 3.x/4, Whisper, and others — on custom LPU hardware at speeds significantly faster than GPU-based alternatives (typically 300–1,000 tokens per second depending on model). If inference latency is a constraint for your application, Groq is worth evaluating alongside or instead of standard GPU-based providers.

Important: Groq runs open and permissively licensed models only. You cannot run GPT, Claude, or Gemini on Groq. If you need those models, you need their respective provider APIs.

Prerequisites

None beyond an email address. Groq has a free tier that requires no credit card.

Step 1: Create a Groq account

Go to https://console.groq.com and sign up. Verify your email before accessing the console. Signup takes about two minutes.

Step 2: Navigate to API Keys

In the console, go to API Keys in the left sidebar. Groq keys are scoped to your organization, not your individual user account. Only organization owners and users with the developer role can create or manage keys.

Step 3: Create your API key

Click Create API Key, give it a descriptive name (prod-llama, dev-whisper, ci-pipeline), and confirm.

The key is shown once. Copy it immediately — you cannot recover it. If you lose it, revoke it and generate a new one.

Groq API keys start with gsk_ followed by alphanumeric characters.

Step 4: Store your key securely

export GROQ_API_KEY="gsk_..."

The Groq SDK and the OpenAI SDK (when pointed at Groq's base URL) both read GROQ_API_KEY automatically.

For production: use a secrets manager. Never commit keys to Git, even in private repos.

Step 5: Test your API key

curl https://api.groq.com/openai/v1/chat/completions \
  -H "Authorization: Bearer $GROQ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama-3.3-70b-versatile",
    "messages": [
      {"role": "user", "content": "Explain what an LPU is in two sentences."}
    ]
  }'

A successful response returns the model output in JSON.

Migrating from OpenAI to Groq

Groq's API is OpenAI-compatible. The change is two lines:

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["GROQ_API_KEY"],
    base_url="https://api.groq.com/openai/v1",
)

Then call client.chat.completions.create(model="llama-3.3-70b-versatile", ...) — the rest of your OpenAI code works unchanged.

Which Groq model should you use?

Groq hosts open and permissively licensed models only. Current production options include:

ModelSpeedBest for
llama-3.1-8b-instant~840 TPSHigh-volume, cost-sensitive workloads
llama-3.3-70b-versatile~394 TPSQuality reasoning and generation
meta-llama/llama-4-scout-17b-16e-instructHigh TPMLong context tasks
whisper-large-v3Speech-to-text
Check console.groq.com for the current model catalog — Groq adds models regularly.

Is Groq free?

Yes. Groq has a permanent free tier with no credit card required. Free tier limits vary by model and account — typical defaults are in the range of 30 RPM and a few thousand TPM. Check Console → Limits for your exact per-model caps.

Paid tiers (Developer, Enterprise) unlock higher rate limits and volume discounts. Rate limit subscriptions can be purchased for specific increases without upgrading the full tier.

Groq service tiers

Groq supports three service tiers you can pass in requests:

  • on_demand****: standard rate limits, reliable throughput
  • flex****: higher throughput, best-effort — will fail fast with HTTP 498 if capacity is unavailable
  • auto****: Groq picks the best available tier for you automatically

For most production workloads, auto is the sensible default.

Groq rate limits

Rate limits apply at the organization level — not per user. They are enforced as RPM, TPM, RPD, and TPD. You can customize limits per project from the organization baseline. If you need higher limits, you can purchase rate limit subscriptions or request custom increases from the console. Check Console → Limits for your exact per-model caps.

Troubleshooting Groq API errors

401 Unauthorized Key is invalid, revoked, or copied incorrectly. Check the Authorization: Bearer gsk_... format, check for trailing whitespace, and regenerate at console.groq.com if needed.

404 model not found The model string is wrong or the model is no longer available on Groq. Check the current model catalog in the console.

429 Too Many Requests You've exceeded your RPM or TPM limits. Implement exponential backoff and respect the Retry-After header. Consider switching to flex service tier for higher throughput on bursty workloads.

498 Flex Tier Capacity Exceeded Groq-specific: you're on the flex tier and capacity is unavailable. Add jittered backoff and retry. Groq does not charge for requests that return 498.

500 / 502 / 503 Server-side errors. Retry the request. Contact support if the issue persists.


Using Grok or Groq through Unified

If you're building an AI product, neither Grok nor Groq is likely to be your only model provider long term. Most teams end up supporting multiple providers for fallback, cost routing, performance tradeoffs, and enterprise customer preference.

Unified's Generative AI API gives you a standardized interface across supported LLM providers — including both xAI Grok and Groq — with consistent objects for Models, Prompts, and Embeddings. You integrate once and swap providers by changing a connection ID, not your application code.

What you build against

The GenAI API standardizes three core objects across providers:

  • Model — capabilities including max tokens and temperature support
  • Prompt — messages, temperature, max_tokens, responses, tokens_used
  • Embedding — content, dimensions, embeddings array, tokens_used

Common patterns this unlocks

  • Run the same prompt across Grok and Groq to compare output quality and latency
  • Route requests to Groq for latency-sensitive workloads, Grok for reasoning-heavy tasks
  • Generate embeddings consistently across providers for RAG pipelines
  • Keep your product code stable while changing providers underneath

Use Grok or Groq as the reasoning layer, Unified MCP as the action layer

LLM calls are only one piece of a production AI feature. The harder part is letting the model take authorized action against customer SaaS tools — reading CRM deals, fetching files, updating records, writing notes.

Unified's MCP server connects any Unified connection to LLM providers and clients that support MCP — including Grok and Groq via their OpenAI-compatible endpoints. The tools available depend on the integration's support and the connection's requested permissions.

MCP URLs (regional):

  • https://mcp-api.unified.to/mcp
  • https://mcp-api-eu.unified.to/mcp

Using Grok tool-calling with Unified MCP:

  1. Fetch tools in Grok's expected format: GET /tools?type=grok
  2. Send those tools to the xAI chat completion call with tool_choice: "auto"
  3. When Grok returns tool_calls, call Unified: POST /tools/{tool_id}/call
  4. Return results back to Grok as role: "tool" messages

MCP safety controls:

  • hide_sensitive=true — reduces PII in tool results
  • permissions=... — restricts what the connection can do
  • tools=... — limits the tool set the model can access
  • defer_tools — lowers tool token usage

Key takeaway

If all you need is an LLM response, calling Grok or Groq directly is fine.

If you're building a product that needs multiple model providers, fallback routing, and authorized SaaS actions against customer integrations, the clean architecture is:

  • Unified Generative AI API for model access across providers
  • Unified MCP server for authorized tool calling into customer integrations
  • Your app for product logic and user experience

That's the difference between an LLM demo and an AI feature shipped.

→ Start your 30-day free trial

→ Book a demo


FAQ

What's the difference between Grok and Groq? Grok (with a k) is xAI's family of large language models — the AI behind the Grok assistant on X. Groq (with a q) is an inference platform that runs open and permissively licensed models on custom LPU hardware at very high speeds. They are separate companies with separate APIs, separate keys, and separate billing.

Do I need X Premium to use the Grok API? No. The xAI API is a standalone product at console.x.ai. You sign up with an email and pay xAI directly. X Premium, SuperGrok, and the xAI API have completely separate billing. Older guides claiming X Premium is required for API access are out of date.

Is the Grok API free? New accounts receive around $25 in promotional credits, which expire 30 days after signup. After that, it's pay-per-token with no permanent free tier. Check the xAI Console for the current promotional offer.

Is the Groq API free? Yes. Groq has a permanent free tier with no credit card required. Limits vary by model — check Console → Limits for your exact caps. Paid tiers unlock higher limits and volume discounts.

Can I use the OpenAI SDK with Grok or Groq? Yes for both. Both APIs are OpenAI-compatible. Point the OpenAI client at https://api.x.ai/v1 with XAI_API_KEY for Grok, or at https://api.groq.com/openai/v1 with GROQ_API_KEY for Groq. The rest of your OpenAI code works without changes.

What models does Groq run? Open and permissively licensed models only — Llama 3.1, Llama 3.3, Llama 4, Whisper, and others. Groq does not run GPT, Claude, or Gemini. For those, you need the respective provider APIs.

What's the difference between SuperGrok and the Grok API? SuperGrok is a consumer chatbot subscription on grok.com. The Grok API is for developers building applications programmatically. They share the same underlying models but use separate billing, separate rate limits, and separate accounts.

How do I get real-time X data through the Grok API? Use the x_search tool in the tools array of your API request. There is no boolean flag to enable X data — any guide suggesting otherwise is outdated.

What is HTTP 498 from Groq? A Groq-specific error meaning the Flex tier is at capacity. Your request was not processed and you will not be charged. Add jittered backoff and retry, or switch to on_demand service tier for more reliable throughput.

What happened to the $150 xAI data sharing program? xAI discontinued it in 2025. It is no longer available.

All articles