Grok API in 2026: How to Get a Key, Pricing, and Free Credits
Guide

Grok API in 2026: How to Get a Key, Pricing, and Free Credits

How to use the Grok API: create an xAI Console key, make a first call, grok-4.7 pricing, rate limit tiers, tool fees, and how startups get free Grok credits.

To use the Grok API, create an account at console.x.ai, generate a key on the API Keys page, load prepaid credits, and call https://api.x.ai/v1 with a model such as grok-4.7. The API accepts the OpenAI and Anthropic SDKs, and grok-4.7 costs $2 per million input tokens and $6 per million output tokens. API usage is not free, but the Console Playground is, and venture-backed startups can apply for credits. This guide covers setup, every text model rate, rate limit tiers, tool fees that catch people out, and how to pay less.

Grok, the Grok API and Groq

Grok is the assistant and model family from SpaceXSI, the company formerly known as xAI. You will still see xAI on the docs, the SDK and the Console. The Grok chat app and the API are billed separately: the API is charged per token through the Console, so you need a Console account and API credits to build with it.

Do not confuse Grok with Groq, a separate company that runs other models on its own inference hardware. A Groq key will not work on the Grok API, or the other way round. Groq is covered in our free AI API comparison because it has a free tier.

How to Get a Grok API Key

Step 1: Create a Console account. Sign up at console.x.ai. Use your company email, especially if you may apply for startup credits, because the program does not approve personal addresses.

Step 2: Test in the Playground. Every Console account includes a Playground, so you can try the latest models before you add billing or write any code.

Step 3: Create a key. Open the API Keys page and create a key named after where it will run, such as "production" or "staging". Keys are shown once at creation, so copy yours into a secrets manager straight away.

Step 4: Set an environment variable. The SDK and the docs examples use XAI_API_KEY.

export XAI_API_KEY="your_api_key"

Step 5: Load credits. Credits are prepaid and usage is deducted from your balance. By default your invoiced billing limit is $0, so requests are rejected as soon as prepaid credits run out. That is a useful safety net, but it can also take production down. For live traffic, set up auto top-up, which has a $5 minimum top-up and an optional monthly cap.

Five steps to start with the Grok API: create a Console account, test in the free Playground, create an API key, set XAI_API_KEY, and load prepaid credits

This short walkthrough shows where to find the API Keys page in the Console and how to create a key.

Your First Grok API Call

Point your existing SDK at https://api.x.ai/v1 and use your Console key. SpaceXSI says most integrations need no other changes. Here is a request with the OpenAI Python SDK:

import os
from openai import OpenAI

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

response = client.responses.create(
    model="grok-4.7",
    input="Explain what an API key is in one sentence.",
)

print(response.output_text)

And the same request with curl:

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

Grok is also available through cloud catalogs, including Azure AI Foundry, Oracle's OCI Generative AI and Google's Vertex Model Garden. On those platforms you authenticate with your cloud credentials instead of a Console key, and usage lands on your cloud bill.

Grok API Pricing

The key is free and usage is billed per million tokens. These are SpaceXSI's listed rates for prompts under 200,000 tokens as of November 2026:

ModelContextInput / 1MCached input / 1MOutput / 1M
grok-4.7500K$2.00$0.50$6.00
grok-4.6500K$2.00$0.50$6.00
grok-4.5500K$2.00$0.30$6.00
grok-4.31M$1.25$0.20$2.50
grok-4.20-0309 (reasoning, non-reasoning, multi-agent)1M$1.25$0.20$2.50
grok-build-0.1256K$1.00$0.20$2.00

Watch the 200K line. Once a prompt reaches 200,000 tokens, every token in that request bills at double the rate. On grok-4.7, a 199,000-token prompt with 2,000 tokens of output costs about $0.41. A 250,000-token prompt with the same output costs about $1.02. Trim context in long-running agents before it crosses the line.

For a sense of scale on grok-4.7, a short exchange of 500 input and 200 output tokens costs about $0.002, and a long agent session with 50,000 input and 15,000 output tokens costs about $0.19 before caching. Triaging 10,000 support tickets at 3,000 input and 700 output tokens each on grok-4.3 costs about $55. For a side-by-side with cheaper options, see the workload table in our DeepSeek API guide.

Ways to pay less, or more for speed:

OptionEffect on token costUse it for
Prompt cachingCached input at the lower rate aboveLong stable system prompts and agents
Batch API20% off the models above, except grok-build-0.1Work that can wait, usually done within 24 hours
Priority Processing2x standard ratesLatency-sensitive requests
US regional endpoint1.1x standard rates; grok-4.7 and grok-4.6 onlyInference that must run in the US

Tool Fees and Other Costs

Server-side tools are billed on top of tokens, and because the model decides how many calls to make, the cost scales with how complex the question is. Set budgets and test on real prompts before you enable them in production.

ToolCost
Web search$5 per 1,000 calls
X search$5 per 1,000 posts, $10 per 1,000 profiles (billed per item returned)
Code execution$5 per 1,000 calls
File attachment search$5 per 1,000 calls
Collections search (RAG)$2.50 per 1,000 calls
Remote MCP toolsTokens only

X search is the one to watch. It charges for every post returned, including parent and quoted posts, not per search. A search returning 200 posts costs $1 before tokens.

Beyond text, grok-imagine-image starts at $0.02 per image, grok-imagine-image-2.0 at $0.04, and video from $0.02 per second on grok-imagine-video-1.5-lite. Voice costs $0.08 per minute for speech-to-speech and $15 per million characters for text-to-speech. Stored files cost $0.025 per GiB per day and collections $0.10. SpaceXSI also bills requests its system judges to violate its usage guidelines, including a $0.05 fee when one is caught before generation in the Responses API.

Rate Limits and Tiers

Each model has limits on requests per second and tokens per minute, and going over returns a 429 error. Your tier rises automatically with cumulative API spend since January 1, 2026, counting prepaid credit purchases and paid invoices. Tiers never go back down.

TierSpend to reach it
Tier 0$0 (default)
Tier 1$50
Tier 2$250
Tier 3$1,000
Tier 4$5,000
EnterpriseOn request

The default tier is already generous on the flagship: grok-4.7 goes from 150 requests per second and 50 million tokens per minute at Tier 0 to 500 and 100 million at Tier 4. grok-4.3 starts lower, moving from 37 requests per second and 10 million tokens per minute to 208 and 85 million. Cached tokens count toward your token limit even though they bill at a lower rate. You can request higher limits in the Console without extra spend.

Is the Grok API Free?

No. API usage is billed per token, and the key itself is the only free part apart from the Console Playground, which lets you test models before adding billing. Beyond that, there are two legitimate ways to use the API without paying for it yourself.

Decision diagram for Grok API credits: venture-backed with a live product should apply to Grok for Startups; teams with cloud credits can check whether they cover Grok in their cloud's model catalog; everyone else can test in the free Playground, then pay per token

Grok for Startups. Startups with venture backing, a live product and a company email that matches their website can apply for one credit balance across Grok, Grok Build, Grok Bot and the Grok API. SpaceXSI sizes each grant by funding, revenue and current AI spend, and aims for about six months of realistic usage. You get 20% on approval, and the other 80% is released automatically after onboarding. It is one grant per company. Eligibility, expiry and rejection reasons are on our Grok for Startups page.

Cloud credits. Grok is offered through Azure AI Foundry, OCI Generative AI and Vertex Model Garden. If you already hold Microsoft for Startups or Google for Startups credits, check your program's terms to see whether they cover third-party models before relying on this route.

What does not exist: a public promo code or a free Grok API key from a third-party site. Keys posted online belong to someone else's account and get revoked. If you need a free API to prototype and do not qualify for credits, our free AI API comparison lists the providers with real free tiers.

Frequently Asked Questions

How do I get a Grok API key?

Create an account at console.x.ai, open the API Keys page and create a key. It is shown once, so save it right away as an environment variable called XAI_API_KEY. Load prepaid credits before you make real API calls.

Is the Grok API free?

No. Creating a key is free and the Console Playground lets you test models before adding billing, but API usage is billed per token. Venture-backed startups can apply to Grok for Startups for credits.

How much does the Grok API cost?

As of November 2026, grok-4.7 costs $2 per million input tokens and $6 per million output tokens, with cached input at $0.50. grok-4.3 costs $1.25 and $2.50. Rates double for the whole request once a prompt reaches 200,000 tokens.

Can I use the OpenAI SDK with the Grok API?

Yes. Set the base URL to https://api.x.ai/v1 and use your Console key. SpaceXSI says the OpenAI and Anthropic SDKs both work this way and that most integrations need no other changes.

Are Grok and Groq the same?

No. Grok is the model family from SpaceXSI, formerly xAI. Groq is a separate inference company that runs other models on its own hardware. They use different accounts and different API keys.

What happens when my Grok API credits run out?

With the default $0 invoiced billing limit, requests are rejected as soon as prepaid credits are gone. To avoid downtime, turn on auto top-up in the Console or request monthly invoiced billing.

How do startups get free Grok API credits?

Apply to Grok for Startups at x.ai/startups. You need venture backing, a live product and a company email that matches your website. Credits are sized by funding, revenue and AI spend, with 20% released on approval and 80% after onboarding.

Next Steps

Sign up with your company email, try your real prompts in the free Playground, then create a key and run a small test. Set auto top-up with a monthly cap before you go live, and keep prompts under the 200,000-token line where you can. If you are venture-backed with a live product, apply for credits on our Grok for Startups page before you spend your own money, and compare other programs in the AI credits index.

Brady Heinrich Written by Brady Heinrich, Founder of Credit for Startups

Related Articles

Join 7,000+ startup founders

Get monthly updates on new credits, perks, and funding opportunities. Join founders who've already discovered over $10M in startup resources.

Monthly Refreshes
Get curated updates on new funding opportunities, exclusive deals, and early access to upcoming startup resources.
No spam
Just valuable funding opportunities and resources. One email per month, and you can unsubscribe anytime.