grok2api_python  by xLmiler

API for Grok, implemented in Python

Created 6 months ago
521 stars

Top 60.4% 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 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
2
Star History
24 stars in the last 30 days

Explore Similar Projects

Starred by Pawel Garbacki Pawel Garbacki(Cofounder of Fireworks AI), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
2 more.

gpt4free by xtekky

0.1%
65k
API package for multi-provider LLM requests (GPT-4.1, Gemini 2.5, Deepseek R1)
Created 2 years ago
Updated 5 days ago
Feedback? Help us improve.