Skip to main content

A simple Python wrapper for interacting with the unofficial Grok API.

Project description

🪐 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grok_api-0.0.7.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grok_api-0.0.7-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file grok_api-0.0.7.tar.gz.

File metadata

  • Download URL: grok_api-0.0.7.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for grok_api-0.0.7.tar.gz
Algorithm Hash digest
SHA256 810d8be7578a9a1145dd640dab4843ad9b3aea21e5be1fef0692244368b78b92
MD5 4c10f520e1dd9fe20437a369572e4040
BLAKE2b-256 c3334508a91752429f612416dbfe70823afb3d25dd01641e83deb1983299711c

See more details on using hashes here.

File details

Details for the file grok_api-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: grok_api-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for grok_api-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 4e51ba783d2e449e587175dd53566443b41ad09324b759c5e4c6c54d3a9defd7
MD5 f83c67ab20c836e444a4d02b59922f03
BLAKE2b-256 64e39f3291459229cf8ebcbcdf37b3b2b8df1efd0e6aeb4aa85e7ca7c7952a78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page