Grok API

Grok API quick start

Updated:

View as Markdown

Welcome! This guide covers the basics of using Grok API, from creating an account to making your first request.

Step 1: Create an account

Register with GrokAPI. We will credit $0.25 to your balance so you can test the API immediately.

Step 2: Generate an API key

Create a key in your account, copy it once, and export it as the XAI_API_KEY environment variable.

Bash
export XAI_API_KEY="sk-YOUR_API_KEY"

Or add the key to a .env file in your project:

.env
XAI_API_KEY=sk-YOUR_API_KEY

Step 3: Install an SDK

Choose your language and install the official OpenAI SDK. It works with GrokAPI by changing the base URL.

pip install openai

Step 4: Make your first request

Send a request to Grok 4.5 through the Responses API. SDK clients use the base URL ending in /v1; raw HTTP requests use the full /v1/responses endpoint.

curl https://api.llm-gate.tech/v1/responses \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.5",
    "input": "Explain why this function returns the wrong median: function median(a){a.sort();return a[a.length/2]}"
  }'

Use your existing infrastructure

Already use an OpenAI-compatible client? Keep your current code and replace only the API key, base URL, and model.

Connection settings

.env
XAI_API_KEY=sk-YOUR_API_KEY
BASE_URL=https://api.llm-gate.tech/v1
MODEL=grok-4.5

Or connect an AI agent

If you write code with an agent rather than through an SDK, you do not need any of the above: the agent takes the same key and base URL in its own settings. Each guide has the exact fields with the interface shown.

You may also be interested