Skip to main content

🪐 Grok Unofficial API Wrapper

A simple Python wrapper for interacting with Grok's unofficial API, providing easy access to creating conversations, sending follow-up messages, and checking rate limits.

Requirements

  • Python 3.x

Installation

pip3 install grok-api

Authentication Setup

You can initialize authentication either through a cookie dictionary or a cookie string.

Note: The sso cookie is always required. Other cookies (x-anonuserid, x-challenge, x-signature) may also be required depending on your authentication state.

(EASIEST) Using a Cookie String:

from grok_api import GrokAPI, GrokAPIAuth

COOKIE_STRING = "[INSERT_COOKIE_STRING_HERE]"

auth = GrokAPIAuth(cookie_string=COOKIE_STRING)
api = GrokAPI(auth)

To locate your cookie string using a browser, ensure you're logged in to Grok. Locate the Network tab, filter for models, refresh your page. There should be a models entry -- click on that, and scroll down until you find the Cookie Request Header (shown below):

cookiestring.png

Using a Cookie Dictionary:

from grok_api import GrokAPI, GrokAPIAuth

COOKIES = {
    "sso":             "[INSERT_SSO_HERE]",
    "x-anonuserid":    "[INSERT_X_ANONUSERID_HERE]",  # not always required
    "x-challenge":     "[INSERT_X_CHALLENGE_HERE]",   # ...
    "x-signature":     "[INSERT_X_SIGNATURE_HERE]",   # not always required
}

auth = GrokAPIAuth(cookies=COOKIES)
api = GrokAPI(auth)

Creating a Conversation

Initiate a new conversation and stream response tokens:

prompt = "Explain quantum computing."

for tok in api.create_conversation(prompt):
    print(tok, end='', sep='')

Sending a Follow-up Message

Continue an existing conversation:

followup_message = "Can you simplify that explanation?"

for tok in api.send_followup(followup_message):
    print(tok, end='', sep='')

Fetching Rate Limits

Check your current API usage and limits:

import json

limits = api.fetch_rate_limits()
print(json.dumps(limits, indent=4))

SuperGrok Usage Limits

Request Type Limit
Grok 3 Base 100 messages every 2 hours
Grok 3 Thinking 30 messages every 2 hours

Important Notes

  • Replace placeholders like [INSERT_SSO_HERE] with your actual cookies.
  • Keep your cookies secure and never expose them publicly.
  • Ensure cookie strings are valid and contain all necessary authentication components.

License

This project is provided as-is without warranty. Use responsibly and adhere to Grok's Terms of Service.

Metadata

Release files for grok-api 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grok-api 0.1.1
File Size Uploaded Provenance Actions
grok_api-0.1.1.tar.gz 4.9 kB Without provenance Details for grok_api-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grok-api 0.1.1
File Interpreter ABI Platform Actions
grok_api-0.1.1-py3-none-any.whl Python 3 none any Details for grok_api-0.1.1-py3-none-any.whl

Total release size: 9.9 kB

Release files / grok_api-0.1.1.tar.gz

Download URL grok_api-0.1.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7ed9cc4ecdd59b69c1e14e2582ebfef601bdd0685aa4e21c0bacd9252f90447b
BLAKE2b-256 checksum
How to use checksums
2a54a9d922ad7095271174e730ca7156664f1c07c4b625e12bd94cd1c9282958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / grok_api-0.1.1-py3-none-any.whl

Download URL grok_api-0.1.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0b2690fd6a35075059c0df4dc2322ab3ff90bc8b68145bf67e51f2b0e5be857
BLAKE2b-256 checksum
How to use checksums
c426a3224c936d5b88e09fbcad207cf45e5fec2368419f1ceff8f42fd2737535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for grok-api 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page