Skip to main content
EN ▾
Drop-in uncensored LLM APIhttps://api.grokaiuncensored.com/v1
Get your key

Grok AI API documentation: a beginner walkthrough

Grok AI API documentation, like most LLM API docs, is built from the same dozen ideas: a base URL, a key, a model name, a list of messages, and a few optional features. This walkthrough maps each idea to a concrete OpenAI-compatible call you can run against our endpoint, so the vendor docs stop looking foreign.

An open glass book unfolding into a glowing path from a key to a server cube to a chat bubble

Key takeaways

  • Every chat API reduces to base URL, key, model and messages.
  • Streaming, tool calling and JSON mode are optional parameters on the same request.
  • This endpoint uses base URL https://api.grokaiuncensored.com/v1 and model ID uncensored.
  • Read vendor docs for exact limits and prices; they differ between providers.

The vocabulary, in one table

We are an independent service and not the official xAI API, so for xAI's own parameters, models and limits you need xAI's documentation. xAI describes an API that works with OpenAI-style clients, so the concepts below carry over. Here is how each one looks on our endpoint.

Docs termWhat it meansHere
Base URLWhere requests are senthttps://api.grokaiuncensored.com/v1
API keyYour secret, sent as a Bearer tokenCreated on the API key page
ModelWhich model answersuncensored
MessagesThe conversation so farArray of role and content objects
Context windowMax tokens in prompt plus reply100,000 tokens
UsageToken counts for billingReturned on every response

Once you know these six rows, almost any provider's quickstart becomes a find-and-replace job.

Your first request, line by line

A request is an HTTP POST with a JSON body. Each part of this call corresponds to a row in the table.

curl https://api.grokaiuncensored.com/v1/chat/completions   -H "Authorization: Bearer YOUR_KEY"   -H "Content-Type: application/json"   -d '{
    "model": "uncensored",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Explain what a token is in two sentences."}
    ],
    "temperature": 0.7
  }'

The system message sets behavior, the user message is the question, and temperature controls randomness. The reply comes back in choices[0].message.content, with token counts in usage. Besides chat completions, the API offers POST /v1/responses and GET /v1/models.

In Python, the OpenAI SDK sends the same request after you set two values.

from openai import OpenAI

client = OpenAI(base_url="https://api.grokaiuncensored.com/v1", api_key="YOUR_KEY")
r = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Explain what a token is in two sentences."}],
)
print(r.choices[0].message.content)
print(r.usage)

Choosing sampling parameters

Docs list a long set of optional parameters. Five matter most. temperature controls randomness: low values such as 0.2 suit factual or structured tasks, higher values such as 0.9 suit creative writing. top_p is an alternative way to limit randomness; change one of the two, not both. stop ends generation at a string you choose. seed makes repeated runs closer to each other, which helps in tests. The presence and frequency penalties discourage repeated words and are useful for long stories that loop. All of these are passed through to the model.

Streaming: reading the reply as it arrives

Docs call this streaming or server-sent events. Add "stream": true and the reply arrives in small chunks instead of one block, which makes chat interfaces feel immediate.

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Write a four-line poem about rain."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Token usage is sent at the end of the stream. One practical detail: a streamed request holds one of your concurrency slots until the stream finishes, so a slow client reading a long reply keeps a slot busy.

Reading the response object

Docs spend pages on the response format, and it is simpler than it looks. A non-streamed reply is a JSON object with a few fields that matter.

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "uncensored",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "A token is a small chunk of text."},
      "finish_reason": "stop"
    }
  ],
  "usage": {"prompt_tokens": 24, "completion_tokens": 9, "total_tokens": 33}
}

The answer is in choices[0].message.content. The finish_reason tells you why generation ended: stop for a natural end, length when the output hit a token limit you set, and tool_calls when the model wants you to run a function. The usage block is what billing is computed from, at $0.15 per 1M input and $0.50 per 1M output tokens. This sample is illustrative, so field values in real replies will differ.

Tool calling: letting the model ask for data

Docs sections titled function calling or tools describe a loop. You describe functions, the model replies with a request to call one, you run it, and you send the result back with the role tool.

import json

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get the current temperature for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]
messages = [{"role": "user", "content": "How warm is it in Oslo?"}]

r = client.chat.completions.create(
    model="uncensored", messages=messages, tools=tools, tool_choice="auto")
msg = r.choices[0].message

if msg.tool_calls:
    call = msg.tool_calls[0]
    city = json.loads(call.function.arguments)["city"]
    result = {"city": city, "temp_c": 4}   # replace with a real lookup
    messages.append(msg)
    messages.append({"role": "tool", "tool_call_id": call.id,
                     "content": json.dumps(result)})
    final = client.chat.completions.create(
        model="uncensored", messages=messages, tools=tools)
    print(final.choices[0].message.content)

The model never runs your code. It only asks, and you decide what to execute.

JSON mode and structured output

When the docs talk about structured output, the simplest tool is JSON mode: response_format set to {"type": "json_object"}. It makes the reply valid JSON.

r = client.chat.completions.create(
    model="uncensored",
    response_format={"type": "json_object"},
    messages=[{"role": "user",
               "content": "Return JSON with keys name and genre for a fantasy novel idea."}],
)
print(r.choices[0].message.content)

Describe the keys you want in the prompt. JSON mode guarantees syntax, not your schema, so validate the parsed result in your code.

Limits, errors and where to go next

Every docs site has a rate-limits page. Here a full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60. Going over returns HTTP 429 with the code rate_limited or concurrency, and temporary overload returns 429 with Retry-After: 5. The request body can be up to 8 MB.

Responses carry X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency. Log the request ID when something fails; it is the first thing to quote when you ask for help on the support page.

Next steps: read the full API docs, get an API key and claim $0.50 of trial credit, and check the pricing of $0.15 per 1M input and $0.50 per 1M output tokens. For a broader view of building with models that answer without refusals, see how to use uncensored AI in your app.

Reading any provider's docs in fifteen minutes

You do not need to read documentation in order. A faster path is to find answers to six questions, in this order: what is the base URL, how requests are authenticated, which model IDs exist, what are the rate limits, how is usage priced, and what do errors look like. Then run one working request before reading anything else.

Next, search the docs for the features you will actually use: streaming, tools, JSON output, system prompts. Skip fine-tuning, batch endpoints and embeddings pages if you only need chat; this API does not offer fine-tuning or embeddings. When something in the docs conflicts with what you observe in a live response, trust the response and report the difference.

Beginner mistakes and their fixes

MistakeWhat you seeFix
Forgetting the historyThe model forgets earlier turnsSend all prior messages on every request; the API keeps no memory
Wrong base URL path404 errorsInclude /v1 in the base URL and let the SDK add the rest
Key in front-end codeKey leaks, balance drainsCall the API from your server and keep the key in env variables
Parsing JSON by handBroken output now and thenUse JSON mode, then validate the parsed object
Ignoring 429Random failures at peakBack off, honor Retry-After and limit concurrency
Setting a very low max_tokensReplies cut mid-sentenceRaise it or leave it unset; it is optional

The first row deserves emphasis. A chat API is stateless: every request must contain the conversation so far. That is also why long chats cost more per turn, which the pricing page helps you estimate.

Frequently asked questions

Is this Grok's official documentation?

No. This is documentation for an independent OpenAI-compatible endpoint. For xAI's own models and parameters, read xAI's docs.

Which SDK should a beginner use?

The official OpenAI SDK for Python or Node. Set the base URL to https://api.grokaiuncensored.com/v1 and use the model ID uncensored.

Does the API support streaming and tools?

Yes. It supports SSE streaming, tool calling with tool_choice and role tool results, and JSON mode.

How large can a request be?

The context window is 100,000 tokens for prompt plus completion, and the request body can be up to 8 MB.

Get your API key

Sign up, copy the key, update your base URL. That’s it.

Start with trial credit

Use email and password to get your key instantly.