The API is not a better chat tab. It is how software you own asks Grok. Applied taught you the job. This pathway teaches the pipe.
Why this matters
People finish Applied and ask “what’s next?” as if the next door is always more product. For most desks, Applied was the end. You already have a week that works on grok.com.
The API is for a different job: a script, a site backend, a shop tool that must call Grok without you sitting in the composer. That costs credits. That needs a key. That can leak if you paste the key into a lesson artifact or a public repo.
If you do not want to run a command on a machine you control, stop. Stay on Applied or Build. You do not owe xAI a billing account.
Teach
Three surfaces, one family of models:
| Surface | Who types | Where the work lives |
|---|
| grok.com / apps | You | Their servers, their UI |
| Grok Build | You, in a folder | Your disk; the agent uses tools |
| API | Your program | Your process; you send HTTP |
Docs live at docs.x.ai. Sign up at accounts.x.ai. Keys are created on console.x.ai. Load credits before you expect a 200. Free chat on grok.com is not the same wallet.
The first request (official Responses API). Do not invent a host.
export XAI_API_KEY="xai-…" # your key, never committed
curl https://api.x.ai/v1/responses \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"model\":\"grok-4.6\",\"input\":\"In one sentence: what is 17 times 4?\"}"
grok-4.6 is the current default on the public docs. Model names move. If the console lists another chat/completions model, use what the live docs say. Do not copy a blog’s grok-beta from 2024.
Python, if you already have it (OpenAI-compatible):
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")
resp = client.responses.create(model="grok-4.6", input="In one sentence: what is 17 times 4?")
print(resp.output_text)
The key lives in the environment, not in the script, not in this LMS, not in a screenshot.
Worked example
A clerk wants Monday’s “what did we promise?” to run without opening grok.com. They create a key, put it in the user environment on their PC, run the curl above with a one-line input from last week’s job card. They get a sentence. They do not paste xai- into Slack to prove it worked. They paste Authorization: Bearer xai-•••• and the JSON output text.
Your turn
Do this on your machine, not only in grok.com.
I will create an xAI API key and make one Responses call.
Rules:
- Key from console.x.ai. Credits loaded or I write “no credits yet” and stop after the 401/402 body.
- I export XAI_API_KEY. I do not put the raw key in the artifact.
- I call POST https://api.x.ai/v1/responses with model grok-4.6 (or the live docs model) and a one-line input from a real job I have.
- I paste: (1) the curl or script with the key redacted, (2) the status code, (3) the model’s output text or the error body, (4) this stamp: “This call was made from my machine. The key is not in this paste.”
If I only screenshot grok.com, I failed.
Artifact to paste
Redacted request + status + output or error + the stamp sentence.
Rubric
- Pass: Host is api.x.ai. Key is not visible. One real input. Stamp present.
- Fail: Key in the paste. ChatGPT URL. A grok.com screenshot. Invented endpoint.
Common failure
Treating the API as “Grok but for developers to chat.” You now have a secret that spends money. Next lesson is how that secret dies if it hits a browser bundle.
What’s next
Secrets stay on the server. Then one useful job through the pipe. Then a script you will actually run.