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.

AI/ML API
Model: Grok 4.7Grok 4.6Grok 4.5Grok 4.3
Choose a Grok model

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 models on AI/ML API with list prices and context window
Model Type Use it for Input Output Context
Grok 4.7 x-ai/grok-4-7 Text Text, code and reasoning $2 $6 500K
Grok 4.6 x-ai/grok-4-6 Text Text generation and reasoning $2 $6 500K
Grok 4.5 x-ai/grok-4-5 Text Chat, code and tool calls $2 $6 500K
Grok 4.3 x-ai/grok-4-3 Text Long-document chat and analysis $1.25 $2.50 1M
Grok Imagine Image 2.0 x-ai/grok-imagine-image-2.0 Image Image generation and editing, up to 5 reference images $0 $0.04 / generation –
Grok Imagine x-ai/grok-imagine-image Image Text-to-image generation $0 $0.02 / generation –
Grok Imagine Video 1.5 Preview x-ai/grok-imagine-video-1.5-preview Video Image-to-video, up to 1080p $0 $0.08 / second –
Grok Imagine Video x-ai/grok-imagine-video Video Image-to-video, up to 720p $0 $0.05 / second –

Grok benchmarks

Independent results for Grok 4.7 from Artificial Analysis.

Intelligence#15 / 50
35.3Index v5.0
Humanity's Last Exam#34 / 458
43.1%Score
Speed#128 / 219
85.7Output tokens / second
IntelligenceIndex v5.0
  1. 36.4Spark 1.3
  2. 36.2Haiku 5.5
  3. 35.3Grok 4.7
  4. 31.7GLM-5.3
  5. 30.5Gemini 3.8 Flash
SpeedOutput tokens / second
  1. 93Grok 4.3
  2. 87.2V4 Pro 0813
  3. 85.7Grok 4.7
  4. 75.7Grok 4.6
  5. 57.6Grok 4.5
Grok 4.7 against earlier versions
BenchmarkGrok 4.7 XhighGrok 4.6 XhighGrok 4.5 HighGrok 4.3 High
Humanity's Last ExamExpert-written questions across academic subjects43.1%44.1% (best of the four)42.7%37.2%
Terminal-Bench 4.0Agentic tasks completed in a command line25.8% (best of the four)17.2%10.6%0%
AA-LCRReasoning across documents of about 100K tokens76.7%81% (best of the four)79.3%73%
SciCodePython tasks drawn from scientific research57.4% (best of the four)53%55%48.3%

Source: Artificial Analysis, as published on the Grok 4.7 model page. Data retrieved Nov 3, 2026.

Built with Grok

DogeDesigner@cb_doge

Grok 4.7 turned a simple prompt into this interactive 3D jet engine visualizer in minutes. This is insane. 🔥

Jet engine visualizer

@cb_dogeGrok 4.7

An interactive 3D model of a high-bypass turbofan. You can explode it into parts, cut a section and watch the airflow, stage by stage from the fan to the nozzle.

X Freeze@XFreeze

Grok Build with Grok 4.7 made this I basically asked it to build an interactive 3D journey from a human cell all the way down to DNA It handled the 3D scenes, animations, transitions and the entire experience The crazy part is I had to go out while it was still working, so I told it to keep going, record the finished result and send me the video on Telegram Then I just left it running... When it finished, Grok literally sent me the video on Telegram

From a cell to DNA

@XFreezeGrok 4.7

An interactive 3D journey that starts at a human cell, moves into its nucleus and chromosomes, and ends on a turning DNA double helix. Grok built the scenes, the animations and the transitions.

X Freeze@XFreeze

I gave Grok 4.7 just 4 images of the Statue of Liberty in Grok Build... And it built an entire interactive 3D scene from them You can orbit around it, zoom in and inspect the whole thing from different angles

Statue of Liberty in 3D

@XFreezeGrok 4.7

An interactive 3D scene of Liberty Island, built from four photos of the statue. You can orbit around it, zoom in and look at it from every side.

Joey@aijoey

Told Grok 4.6 I wanted schematics for a black carbon fiber mech keyboard that's 3d rotatable. I wasn't even sure what vocabulary to say. It built a 75% in the browser with three.js. Carbon weave on the case. you drag to spin it, explode the stack, and the keycaps lift off the switches.

Carbon fiber keyboard

@aijoeyGrok 4.6

A 75% mechanical keyboard in Three.js with a carbon weave case. You drag to spin it, explode the stack into layers and watch the keycaps lift off the switches.

Techartist@techartist_

Would the future look like this? Made a 3D cyberpunk urban district with flying and self driving cars. Code -> Grok 4.6 using Three.js

Neon cyberpunk district

@techartist_Grok 4.6

A 3D cyberpunk district in Three.js with flying and self-driving cars. A control panel switches the time of day and moves the camera between the overview, the street and the skyline.

Techartist@techartist_

Building robotics with Grok 4.6: made a dog of glass and metal entirely with code. Now the hard part: teaching it to walk. Flat terrain for now; rough terrain next. Three.js + TSL/WebGPU + Rapier.

Glass and metal robot dog

@techartist_Grok 4.6

A robot dog made entirely with code that walks on flat ground with real physics. It runs in Three.js with WebGPU shaders and the Rapier physics engine.

Zhuo Tao@runzhuotao

Just ran Grok 4.5 through a voxel-style map benchmark as well. Surprisingly great results. #blender #threejs #gamedev #voxel

Voxel map dioramas

@runzhuotaoGrok 4.5

Three voxel dioramas from one benchmark run: a jungle with a river and a stepped temple, a desert town with palm trees, and a village with autumn trees.

DogeDesigner@cb_doge

Used Grok 4.7 to create this Colosseum render in Blender. Grok is ridiculously good at Blender and makes complex 3D work feel so much easier. The combination feels like a cheat code. Really impressed with the realism and how much of the process it handled.

Colosseum in Blender

@cb_dogeGrok 4.7

A render of the Colosseum and the city blocks around it, modelled in Blender with Grok 4.7 doing most of the work.

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.

Model
Example image: a ginger cat asleep on three stacked hardcover books in a rainy bookshop window at dusk, with gold OPEN LATE lettering on the glass.

How to get your Grok API key

  1. Create your AI/ML API account

    Sign up with Google, GitHub or email. If you already have an account, log in.

    Screenshot of the AI/ML API sign-up page: Create your account, with Continue with Google, Continue with GitHub and an email field.Screenshot of the AI/ML API sign-up page: Create your account, with Continue with Google, Continue with GitHub and an email field.
  2. Add credit

    Open Billing and add funds. You pay as you go and each request draws on this balance.

  3. 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.

  4. 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.

    AI/ML API
    Model: Grok 4.7Grok 4.6Grok 4.5Grok 4.3
    Choose a Grok model

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 access through AI/ML API, OpenRouter and xAI
OpenRouter xAI
Models from other providers on the same keyYes. 70+ providersYes. 80+ providersNo. Grok models only
Automatic model routingYes. Jev RouterYes. Auto RouterNot stated
Fees on top of model pricesYes. 0% markupNo. 5.5% on credit purchasesDirect pricing
Pay with cryptoYes. YesYes. USDC, 5% feeNot stated
Pay with PayPalYes. YesNo. Not yetNot stated
Grok 4.7 list price per 1M tokens, input / output$2 / $6$2 / $6$2 / $6

Grok API FAQ

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. For Grok text models, use the OpenAI client in Python or JavaScript with your AI/ML API key and https://api.aimlapi.com/v1 as the base URL. Image and video models use their documented endpoints. See supported SDKs.

  7. 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.

  8. 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.

Get your Grok API key