Skip to main content

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

Project description

🪐 Unofficial Grok API Wrapper

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

Features

  • Create new conversations with Grok
  • Send follow-up messages within existing conversations
  • Fetch rate limit information for base and reasoning (thinking) requests

Requirements

  • Python 3.x
  • requests library

Installation

pip install requests

Usage

Note: Obtain cookies (sso, x-anonuserid, x-challenge, x-signature) securely from your browser after logging into Grok. Never share or expose these cookies publicly.

Authentication Setup

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

Using a Cookie Dictionary:

from grok_api_wrapper import GrokAPIWrapper, GrokAPIAuth

COOKIES = {
    "sso":             "[INSERT_SSO_HERE]",
    "x-anonuserid":    "[INSERT_X_ANONUSERID_HERE]",
    "x-challenge":     "[INSERT_X_CHALLENGE_HERE]",
    "x-signature":     "[INSERT_X_SIGNATURE_HERE]",
}

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

Using a Cookie String:

from grok_api_wrapper import GrokAPIWrapper, GrokAPIAuth

COOKIE_STRING = "[INSERT_COOKIE_STRING_HERE]"

auth = GrokAPIAuth(cookie_string=COOKIE_STRING)
api = GrokAPIWrapper(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.1.tar.gz (4.9 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.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file grok-api-0.0.1.tar.gz.

File metadata

  • Download URL: grok-api-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for grok-api-0.0.1.tar.gz
Algorithm Hash digest
SHA256 369c73f76b7b79c88db442ed57af46d8a8778228f488b0aa0df023ba950afcb2
MD5 0394885053908796de938a8bf16178f5
BLAKE2b-256 e80cf53ea111b0b78720af9f7926fd5d89b34132dc0e75f53711f63e052c09ad

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for grok_api-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a18fcad6b34b81cf02bce512b0e7e47e41904de13864115cfacc55534df3ccc8
MD5 59bc5cb43c4505879694d9290b84f706
BLAKE2b-256 3d4a205d5c20146d91deea890b0954290e6ba17edfafdcb3a81e4b18782a42b6

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