TL;DR
- Grok 4.7 is xAI's text model for coding and agentic work, live on HiAPI: open the model page and chat directly; new accounts get 200 free credits.
- Pricing is $0.84 input / $2.52 output per 1M tokens (cached input $0.21), about 42% of the official rate. A 2K-in + 1K-out call costs about $0.0042; at ~$0.0084 per medium request (3K total tokens), $10 covers roughly 1,200 requests.
- Fastest path:
POST https://api.hiapi.ai/v1/chat/completionswithmodel: "grok-4.7"; existing OpenAI SDK code only needs a new base URL and model ID.
What Grok 4.7 is, and what's new
Released on September 21, 2026, Grok 4.7 is xAI's current default recommendation, aimed at coding, agentic tasks, and knowledge work. Its self-reported Terminal-Bench 4.0 score jumped from 20.3% (4.6) to 38.0%. Four things matter for integrators:
- Coding and agentic work are the headline. Long-horizon planning is the focus.
- Four reasoning tiers.
reasoning_efforttakeslow/medium/high/xhigh, defaulthigh; the thinking trace comes back inreasoning_content. - JSON mode + tool calling.
response_format: {"type": "json_object"}forces valid JSON, and function calling follows the standard OpenAI tools format, so structured extraction and agent loops work out of the box. - 500K context. Whole repos and long documents fit in one request.
A real output: pandas data analysis
Actual Grok 4.7 output from a live run on HiAPI (prompt linked below). The task: analyze an e-commerce orders dataset (monthly GMV, top-20 users by spend, new-user first-order trends) with created_at stored as a string. The model finished in 18.5 seconds, code complete and runnable, and handled the string-date conversion unprompted:
# ---------- 0. Dates: convert strings to datetime ----------
df["created_at"] = pd.to_datetime(df["created_at"], errors="coerce")
df = df.dropna(subset=["created_at", "amount", "user_id"])
# keep only valid orders (adjust status values to your business)
df_valid = df[df["status"] == "paid"].copy()
# ---------- 1. Monthly GMV and order count ----------
df_valid["month"] = df_valid["created_at"].dt.to_period("M")
monthly = (
df_valid.groupby("month", as_index=False)
.agg(GMV=("amount", "sum"), order_count=("order_id", "count"))
.sort_values("month")
)
That run: 3,440 input / 1,427 output tokens, about $0.007. Want the same result? Run this exact prompt on the model page →
Two ways to get started
Route 1: browser, 3 steps, zero code
- Open the Grok 4.7 model page and sign in (new accounts get 200 free credits).
- Paste your prompt, or use this link to have it prefilled.
- Hit send.
Route 2: API, 3 steps, into your app
- Create an API key in the HiAPI console.
- Replace
YOUR_HIAPI_API_KEYin the curl below and run it. - Keep
modelasgrok-4.7, swapmessagesfor your real input, done.
curl: your first call
curl https://api.hiapi.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_HIAPI_API_KEY" \
-d '{
"model": "grok-4.7",
"messages": [
{"role": "system", "content": "You are a senior backend engineer."},
{"role": "user", "content": "Explain what a database connection pool is in two sentences."}
],
"reasoning_effort": "high",
"max_tokens": 2000
}'
In the response, choices[0].message.content holds the answer and reasoning_content holds the thinking trace; usage.completion_tokens_details.reasoning_tokens tells you how many tokens the reasoning burned.
Python: non-streaming + streaming
import requests
resp = requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={"Authorization": "Bearer YOUR_HIAPI_API_KEY"},
json={
"model": "grok-4.7",
"messages": [
{"role": "user", "content": "Write a Python function that merges two sorted lists into one sorted list."}
],
"reasoning_effort": "medium",
"max_tokens": 4000,
},
timeout=120,
)
resp.raise_for_status()
data = resp.json()
print(data["choices"][0]["message"]["content"])
Two things to know: delta.reasoning_content chunks (the thinking) arrive first, then delta.content (the answer); usage appears only in the final chunk (empty choices), followed by data: [DONE]:
import json
import requests
with requests.post(
"https://api.hiapi.ai/v1/chat/completions",
headers={"Authorization": "Bearer YOUR_HIAPI_API_KEY"},
json={
"model": "grok-4.7",
"messages": [{"role": "user", "content": "Plan a Redis-based online presence system."}],
"reasoning_effort": "high",
"stream": True,
},
stream=True,
timeout=300,
) as resp:
resp.raise_for_status()
for line in resp.iter_lines(decode_unicode=True):
if not line or not line.startswith("data:"):
continue
payload = line[len("data:"):].strip()
if payload == "[DONE]":
break
chunk = json.loads(payload)
if not chunk["choices"]:
print("\nusage:", chunk["usage"]) # only the final chunk carries usage
continue
delta = chunk["choices"][0]["delta"]
if delta.get("reasoning_content"):
print(delta["reasoning_content"], end="", flush=True)
elif delta.get("content"):
print(delta["content"], end="", flush=True)
Parameter reference
| Field | Required | Values | Notes |
|---|---|---|---|
| model | yes | grok-4.7 | Use this exact ID |
| messages | yes | OpenAI-format message array | system / user / assistant / tool roles all supported |
| reasoning_effort | no | low / medium / high / xhigh, default high | Thinking trace returned in reasoning_content |
| max_tokens | no | positive integer | Output cap, includes reasoning tokens; set it too low and the thinking gets truncated first |
| response_format | no | {"type": "json_object"} | Forces valid JSON output for structured extraction |
| tools | no | OpenAI function-calling array | Tool calling, multi-turn tool results supported |
| stream | no | true / false, default false | SSE streaming; usage arrives in the final chunk |
Errors you will actually hit
The most common migration trap: grok-4.7 does not support frequency_penalty, presence_penalty, or stop. Pass one and the request 400s. reasoning_effort only accepts the four values low / medium / high / xhigh; a wrong value comes back verbatim as reasoning_effort: is outside allowed values. Fields outside the protocol are rejected too — when we probed with an unregistered field, the API returned request.zz: unregistered public parameter.
The fix: drop those three parameters and write the tier correctly. For other 4xx, check error.code first.
Before you ship
- Reasoning tokens bill as output tokens. A
high-effort answer can burn tens of thousands of reasoning tokens, all charged at $2.52/M. Dropreasoning_efforttolowormediumfor routine tasks; it is your biggest cost lever. Audit it viausage.completion_tokens_details.reasoning_tokens. - The 200K line reprices the whole request. Past 200K prompt tokens, the entire request bills at the long-context tier: $1.68 in / $5.04 out / $0.42 cached, double the regular rate. Keep routine traffic below it; don't stuff a whole repo into every call.
- Cached reads cost a quarter of the input price. Repeated long system prompts and stable multi-turn prefixes hit the cache automatically; cached reads cost $0.21/M. Keep prefixes stable in agent loops and the bill shrinks.
FAQ
Grok 4.7 or Grok 4.6? Identical pricing ($0.84/$2.52). Pick 4.7 for complex coding and agentic work (xAI's default); keep 4.6 for simple tasks to save tokens. Full breakdown in Grok 4.7 vs Grok 4.6.
Does it support streaming? Yes, standard SSE. Usage only arrives in the final chunk; earlier chunks carry none.
Do I pay extra for reasoning_content? No extra switch, but its reasoning tokens bill as output; higher tiers, thicker bills.
Is 500K the input limit? 500K is the combined input-plus-output window. Inputs approaching 200K trigger the long-context tier (see above).
Keep going: cost math in Grok 4.7 API pricing, five copy-paste prompt recipes in Grok 4.7 prompt recipes, and the previous generation in Grok 4.6 API guide. Copy the pandas prompt above and make your first call on the model page.





