grok2api_python  by xLmiler

API for Grok, implemented in Python

created 5 months ago
490 stars

Top 63.8% on sourcepulse

GitHubView on GitHub
Project Summary

This project provides a Python-based API wrapper for Grok, designed for developers and researchers needing to integrate Grok's AI capabilities into their applications. It offers a standardized OpenAI-compatible API, supporting text generation, image generation, search, and reasoning, with features like automatic Cloudflare bypass and true streaming.

How It Works

The API acts as a proxy, translating requests into the format expected by Grok's official website. It employs Docker for deployment and includes mechanisms to automatically bypass Cloudflare's "shield" protection, provided the user's IP is not flagged. For image generation, it integrates with PicGo or TUMY image hosting services to handle image uploads and streaming. The system supports multiple Grok accounts with automatic round-robin and load balancing.

Quick Start & Requirements

  • Install/Run: Via Docker. Example: docker run -it -d --name grok2api_python -p 3000:3000 -e SSO=your_sso yxmiler/grok2api_python:latest
  • Prerequisites: Docker, Grok SSO cookie (required unless IS_CUSTOM_SSO is true), optional CF_CLEARANCE cookie, optional image hosting API keys (PicGo/TUMY) for streaming image generation.
  • Setup: Minimal setup if using pre-built Docker image and providing necessary environment variables.
  • Docs: GrokPythonService (for Hugging Face deployment)

Highlighted Details

  • Supports text generation, image generation (grok-2-imageGen, grok-3-imageGen), search (grok-2-search, grok-3-search), deep search (grok-3-deepsearch), and reasoning (grok-3-reasoning).
  • Features true streaming for all supported functions.
  • Includes automatic Cloudflare bypass and configurable proxy support (HTTP/Socks5).
  • Handles context window limitations by converting long conversations to files.

Maintenance & Community

  • The project is maintained by xLmiler. No specific community links (Discord/Slack) or roadmap are provided in the README.

Licensing & Compatibility

  • The README does not explicitly state a license. The project is intended for "learning and research purposes." Commercial use is not specified.

Limitations & Caveats

  • Cloudflare bypass effectiveness depends on the IP's status; flagged IPs may encounter a 5-second shield that cannot be bypassed. The CF_CLEARANCE cookie is IP-bound.
  • Image generation requires separate image hosting API keys.
  • The project is for educational/research purposes; adherence to Grok's terms of service is advised.
Health Check
Last commit

2 weeks ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
5
Star History
62 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.