Build with Grok API
Get an AI/ML API key and call Grok 4.7 with the OpenAI SDK. Grok Imagine for images and video works from the same account and balance.
Write a Python function that checks if a string is a palindrome.
Grok 4.7Grok 4.6Grok 4.5Grok 4.3
Here is a short version. It ignores case, spaces and punctuation:
def is_palindrome(text: str) -> bool:
chars = [c.lower() for c in text
if c.isalnum()]
return chars == chars[::-1]It compares the cleaned text with its reverse
Grok is typing
Trusted by our partners
- Adobe
- Washington State University
- NVIDIA
- ByteDance
- Alibaba
- Poolside
- MiniMax
- Open Claude
- RAGFlow
- Zero
Grok models and pricing
Pick one from xAI for text, images or video. Text prices are per 1M tokens, images per generation, video per second.
Grok benchmarks
Independent results for Grok 4.7 from Artificial Analysis.
Source: Artificial Analysis, as published on the Grok 4.7 model page. Data retrieved Nov 3, 2026.
Built with Grok
Generate images and video with Grok Imagine
Write a prompt and pick a model. Run it in the AI/ML API Playground or send a call with your API key.
Edit the prompt or write your own.

How to get your Grok API key
Create your AI/ML API account
Sign up with Google, GitHub or email. If you already have an account, log in.


Add credit
Open Billing and add funds. You pay as you go and each request draws on this balance.
Create your Grok API key
Open API keys and choose Create API Key. Name it, set a spending limit and store it on your server.
Send your first request
Open the Playground, pick a Grok model and type a message. To call it from code, use your key with the OpenAI SDK.
Write a haiku about the ocean.
Grok 4.7Grok 4.6Grok 4.5Grok 4.3
Salt wind on the swell,
a gull stitches sky to sea,
tide keeps its own timeGrok is typing
Call Grok with the OpenAI SDK
Set the AI/ML API base URL, your key and the model ID. The rest of your code stays the same.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.aimlapi.com/v1",
api_key=os.environ["AIMLAPI_API_KEY"],
)
prompt = "Write a haiku about the ocean."
response = client.chat.completions.create(
model="x-ai/grok-4-7",
messages=[{"role": "user", "content": prompt}],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.aimlapi.com/v1",
apiKey: process.env.AIMLAPI_API_KEY,
});
const prompt = "Write a haiku about the ocean.";
const response = await client.chat.completions.create({
model: "x-ai/grok-4-7",
messages: [{ role: "user", content: prompt }],
});
console.log(response.choices[0].message.content);curl https://api.aimlapi.com/v1/chat/completions \
-H "Authorization: Bearer $AIMLAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "x-ai/grok-4-7",
"messages": [{
"role": "user",
"content": "Write a haiku about the ocean."
}]
}'Compare Grok API providers
Grok API FAQ
-
Create an AI/ML API account, add credit, then open API keys and choose Create API Key. Pick a Grok model and send your first request. Follow the setup guide.
-
No. You get an AI/ML API key and call Grok through api.aimlapi.com. A key from the xAI Console works only with api.x.ai, and one can't replace the other.
-
No. Grok is the model family from xAI. Groq is a separate company that runs other open models on its own chips, and its keys don't work with Grok. See Grok models.
-
You pay as you go from your AI/ML API balance. Text bills by tokens, images by generation and video by second, and every rate is in the model table. See models and pricing.
-
No. Each Grok request is billed from your AI/ML API balance at the rates in the model table, so you pay only for the tokens, images or seconds you use. Check the rates.
-
For Grok text models, use the OpenAI client in Python or JavaScript with your AI/ML API key and
https://api.aimlapi.com/v1as the base URL. Image and video models use their documented endpoints. See supported SDKs. -
Yes. Grok Imagine Image 2.0 generates and edits images with up to five reference images, and the Grok Imagine video models animate a starting image. Explore Grok Imagine.
-
Store the key in a server-side environment variable. Keep it out of browser code and public repositories, and set permissions and a spending limit in your account. Manage your API keys.







