Quickstart: First Request
Start by pointing your client to our base URL. Use https://api.grockapi.com/v1 and set your API key in the header. The model identifier is always uncensored. This works with any OpenAI-compatible SDK.
Authentication requires a valid Bearer token. Pass it as Authorization: Bearer YOUR_API_KEY. If the key is missing or invalid, you receive a 401 error immediately.
Make your first call to test connectivity. The request body must include the model name and a messages array.
Supported Parameters and Modes
Configure generation behavior using standard parameters. You can adjust temperature for creativity or top_p for nucleus sampling. Use the stop parameter to define specific sequences that halt generation.
Set seed for deterministic outputs during debugging. Presence and frequency penalties help reduce repetition. The model supports up to 100,000 tokens in the context window.
Max output is limited to 16,000 tokens per request. Leave max_tokens unset to use the default 2,048 output limit. Errors and refusals do not consume credit.
Streaming and Token Usage
Enable streaming by setting stream: true. The API returns chunks via Server-Sent Events (SSE). Each chunk contains partial content and metadata.
Token usage details appear in the final chunk. This allows you to track costs accurately in real time. The last chunk includes the complete usage statistics for the request.
Handle stream closure properly to avoid resource leaks. Always process the final chunk to get accurate billing data.
Function Calling (Tools)
Define tools in your request body. Specify tool names, descriptions, and parameter schemas. The model responds with tool calls when appropriate.
Use the tool_choice parameter to force or allow specific behaviors. You can set it to auto, required, or specific tool IDs.
Process tool calls in your application logic. Send the tool output back to the model to continue the conversation. This enables complex multi-step workflows without external parsing.
JSON Mode and Constraints
Force structured output by setting response_format to json_object. The model will return valid JSON without markdown code blocks.
This mode is ideal for parsing data into applications. Ensure your schema is clear to improve accuracy. Invalid JSON structures may cause parsing errors in your client.
Combine JSON mode with temperature controls for consistent formatting. Use stop sequences to prevent trailing characters after the closing brace.
Rate Limits and Quotas
Each API key is limited to 300 requests per minute. You can run up to 8 concurrent requests simultaneously. The maximum request body size is 8 MB.
A 429 error indicates you have exceeded the rate limit. Wait before retrying or reduce your concurrency. One active key exists per account; generating a new key replaces the old one.
Monitor your usage via the final streaming chunk or response headers. Errors like 402 (no credit) or 401 (invalid key) are free and do not count against your quota.
cURL
curl https://api.grockapi.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "calculate the sum of two and three"}]
}'Python
from openai import OpenAI
client = OpenAI(base_url="https://api.grockapi.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.grockapi.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);Streaming
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)