🤬😡
The following project is an unofficial xAI-Grok API. DestroyerDarkNess and I, Pentesting-28, were hired to reverse engineer https://grok.com and develop this project for 200 USDT. Unfortunately, the employer disappeared without paying even half of the agreed amount, so this project is incomplete (we didn't finish it).
⚠️👇🏻
What's missing???
- Cookies generators
- x-statsig-id generator
- Endpoint: https://grok.com/rest/app-chat/conversations/{conversationId}/responses
- Endpoint: https://grok.com/rest/app-chat/conversations/{conversationId}/load-responses
- Cloudflare Bypass (Optional)
🤩 If you found it useful, please leave a star to the repository. 💫
Unofficial client for the Grok API with CLI interface built on modular architecture and enterprise-level design patterns.
compressO-2025-10-16.22-47-30.mp4
This project follows a layered architecture with clear separation of concerns:
src/
├── config/ # Configuration and constants
│ ├── constants.js # URLs, endpoints and defaults
│ └── headers.js # Factory for HTTP headers
├── models/ # Domain models
│ ├── Model.js # Model entity
│ └── Conversation.js # Conversation entity
├── repositories/ # Repository Pattern (data access)
│ ├── ModelRepository.js
│ └── ConversationRepository.js
├── services/ # Service Layer (business logic)
│ └── GrokService.js
├── utils/ # Reusable utilities
│ ├── StreamReader.js # Event stream reader
│ └── Logger.js # Centralized logger
├── errors/ # Custom error classes
│ └── ConfigurationError.js
└── cli/ # CLI Interface (Facade Pattern)
├── CLI.js # Main entry point
├── MenuController.js # Menu controller
└── PromptHandler.js # Prompt handling
Encapsulates data access logic (API calls) in ModelRepository
and ConversationRepository
.
GrokService
coordinates multiple repositories and contains business logic.
The CLI
class provides a simplified interface for the end user.
HeadersFactory
creates different header configurations based on context.
All classes receive their dependencies via constructor, facilitating testing and maintainability.
Each class has a single reason to change.
- Node.js >= 18.0.0
- Web browser (Chrome, Firefox, Edge, etc.)
# Clone or download the project
cd Unofficial-Grok-API
# Run the application
node index.js
# Or using npm
npm start
The functioning of this API, especially the newChat endpoint, depends entirely on the cookies and headers you must extract from the Grok website.
- Open your browser and visit https://grok.com
- You can obtain credentials even without logging in (anonymous mode)
- Chrome/Edge: Press
F12
orCtrl+Shift+I
(Windows/Linux) /Cmd+Option+I
(Mac) - Firefox: Press
F12
orCtrl+Shift+I
(Windows/Linux) /Cmd+Option+I
(Mac)
- Click on the "Network" tab
- Make sure it's recording (the record button should be red)
- If you don't see any activity, reload the page (
F5
orCtrl+R
)
- In the filter, search for requests containing "grok.com" or "/rest/"
- Click on any request to the Grok API
- Go to the "Headers" tab
Find and copy these values from the "Request Headers" section:
Look for the cookie:
header and copy its complete value. It should contain:
x-anonuserid=
(Anonymous user ID)x-challenge=
(Security challenge)x-signature=
(Authentication signature)
Example:
x-anonuserid=af75eb1e-32d6-4652-8c27-76b8665124f1; x-challenge=g0kpQxSRI8fKa82%2FqRqwCLrzxJ6lWm6%2F973xbDXHXjU%2BgWx9lPN3zGfyjtkRVJv7l35qHVOJ21wPWGdOG%2BLjP758NHwOBdoU2yC%2BLoTxeUT646UaG8fSRo2xYLyCrKvYqO0DKwubeypt4LlG2JVE37uYGUGEaNeglBAt8Unrn0XDZ6Xfvt0%3D; x-signature=KZfrh7R6LjeqmOkb0dchB8sy4ddXgdeV7VId3ELP%2FCoTra40u6px58HFL56glStgN0NBSUCXljjBd4WhbJYQjg%3D%3D
Look for the x-statsig-id:
header and copy its complete value.
Example:
SSn1YC6nCn3AKbQ1W9LIHfwMwac5ZcRPaB0qD9oA3BYEQ1VErvlaWfqg/j8KM7Q2rZV9600/Y/BZVtQuFYUPku0hRT5aSg
Create a config.json
file from the example:
cp config.json.example config.json
Then edit config.json
with your values:
{
"cookie": "x-anonuserid=YOUR_VALUE; x-challenge=YOUR_VALUE; x-signature=YOUR_VALUE",
"statsigId": "YOUR_STATSIG_ID"
}
Important Note: These credentials may expire after some time. If you start receiving authentication errors:
- Repeat the above steps
- Obtain new credentials
- Update
config.json
After configuring credentials, test the application:
node index.js
Select option 1) List models
to verify the connection works correctly.
- Node.js >= 18.0.0
- No external dependencies required (uses native Node.js APIs)
- Cause: Invalid or expired credentials
- Solution: Re-obtain cookies and headers from grok.com
- Cause: Old Node.js version
- Solution: Update to Node.js >= 18.0.0
- Cause: Incorrect cookie or x-statsig-id
- Solution: Verify you copied the complete values without extra spaces
- Cause: The newChat endpoint requires valid credentials
- Solution: Make sure all three parts of the cookie are present:
x-anonuserid
x-challenge
x-signature
- Single Responsibility: Each module has a single responsibility
- Open/Closed: Extensible without modifying existing code
- Liskov Substitution: Implementations can be interchanged
- Interface Segregation: Specific interfaces per client
- Dependency Inversion: Depends on abstractions, not concretions
- Testable: Easy unit test creation with mocks
- Maintainable: Organized and easy-to-understand code
- Scalable: Simple to add new features
- Reusable: Independent and decoupled components
- Professional: Follows industry standards
- ARCHITECTURE.md - Detailed architecture diagrams and data flows
- EXTENDING.md - Complete guide for adding new features
- SECURITY.md - Best practices for secure credential handling
If you wish to contribute to the project:
- Fork the repository
- Create a branch for your feature (
git checkout -b feature/AmazingFeature
) - Follow the established design patterns
- Ensure credentials are not in the code
- Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the license specified in LICENSE.
This is an unofficial client for the Grok API. It is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Grok or xAI. Use at your own risk.