Skip to content

EveripediaNetwork/grokit

Repository files navigation

Logo

Unofficial Python client for Grok models


PyPi License

Installation

pip install grokit

Usage

Import the Grokit class and create an instance:

from grokit import Grokit

# You can set the X_AUTH_TOKEN and X_CSRF_TOKEN environment variables instead
grok = Grokit(
    auth_token='***',
    csrf_token='***',
)

Generate Text

response = grok.generate('Who are you?', model_id='grok-2-mini')
print(response)

Stream Text

for chunk in grok.stream('Who are you?', model_id='grok-2'):
    print(chunk, end='', flush=True)

Generate Images

JPEG binary

image_data = grok.image('An astronaut riding a horse.')

with open('image.jpg', 'wb') as f:
    f.write(image_data)

image URL

image_url = grok.image_url('An astronaut riding a horse.')
print(image_url)

Credentials

To obtain the necessary credentials for using Grokit, follow these steps:

  1. Log in to x.com with a Premium account.

  2. Open your browser's Developer Tools.

  3. Navigate to the Network tab in the Developer Tools.

  4. Load x.com/i/grok in your browser.

  5. In the Network tab, look for the first request.

  6. Click on this request to view its details.

  7. In the Headers section, find the "Cookie" header under Request Headers.

  8. From the cookie string, extract the following values:

    • ct0: This is your csrf token
    • auth_token: This is your auth token