Grok API Documentation

Buy credits, generate a key, and call Grok through a simple endpoint. If you've used the OpenAI API before, you already know this one.

grokapi.io is an independent proxy and reseller for Grok. Endpoints below point at our proxy; responses originate from Grok models.

Introduction

The Grok API exposes a REST interface modeled on the OpenAI specification. You authenticate with a bearer token and receive standard JSON responses, so the official OpenAI SDKs and most HTTP clients work with minimal changes.

Base URL

BASEhttps://api.grokapi.io/v1

Authentication

The API uses bearer token authentication. Create a key from your dashboard after topping up credits, then pass it on every request:

# HTTP headers
Authorization: Bearer sk-grok-your-key
Content-Type: application/json

Keep keys secret. Treat API keys like passwords — never embed them in client-side code or commit them to a repository. Rotate or revoke a leaked key instantly from your dashboard.

Quickstart

Python

from openai import OpenAI

client = OpenAI(api_key="sk-grok-your-key", base_url="https://api.grokapi.io/v1")

resp = client.chat.completions.create(
    model="grok-4",
    messages=[{"role": "user", "content": "Explain RAG in one sentence."}],
)
print(resp.choices[0].message.content)

cURL

curl https://api.grokapi.io/v1/chat/completions \
  -H "Authorization: Bearer sk-grok-your-key" \
  -H "Content-Type: application/json" \
  -d '{"model": "grok-4", "messages": [{"role":"user","content":"Hello!"}]}'

Chat completions

POST/v1/chat/completions

Creates a model response for a conversation. Core parameters:

  • modelgrok-4 or grok-3. Required.
  • messages — array of { role, content } objects. Required.
  • temperature, max_tokens, stream — optional.

Streaming

Set stream: true to receive tokens as server-sent events, terminated by data: [DONE] — identical to the OpenAI streaming format.

Models

GET/v1/models
Model IDName
grok-4Grok 4
grok-3Grok 3

Errors

Conventional HTTP status codes are used, with an OpenAI-style error body: { "error": { "message", "type", "code" } }.

CodeMeaning
400Malformed request
401Invalid or missing API key
402Insufficient credits — top up your balance
429Rate limit exceeded
500 / 503Upstream or proxy error — retry with backoff

Rate limits

Rate limits scale with your plan and balance. When you exceed a limit you'll receive a 429 with a Retry-After header — back off and retry. Need a custom limit? Contact us.

Ready to build? Get your API key and make your first call in minutes.