grok2api  by chenyme

FastAPI-based API for multimodal AI interactions

Created 1 month ago
395 stars

Top 72.8% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a FastAPI-based API gateway for Grok, enabling advanced features like streaming conversations, image generation and editing, web search, video generation, and deep thinking. It targets developers seeking to integrate Grok's capabilities into their applications, offering a unified interface, efficient concurrency management, and automatic load balancing, thereby simplifying access to Grok's functionalities.

How It Works

The API is built using FastAPI, adhering to the latest web call formats and offering full compatibility with OpenAI's API structure. It supports streaming dialogues, image generation/editing, web search, and video generation. A key design element is its "number pool" system for concurrent calls and automatic load balancing across managed accounts. To circumvent Grok's 403 restrictions on direct media links, the system automatically caches images and videos locally, requiring a correctly configured base_url for proper display.

Quick Start & Requirements

Deployment is primarily handled via Docker Compose using the ghcr.io/chenyme/grok2api:latest image. Key environment variables include STORAGE_MODE (options: file, mysql, redis) and DATABASE_URL (required for MySQL or Redis storage). Users can access a management interface at /login and /manage for configuration and monitoring.

Highlighted Details

  • OpenAI API Compatibility: Fully mimics OpenAI's API endpoints, including /v1/chat/completions and /v1/models, facilitating easy integration with existing tools and libraries.
  • Media Caching: Automatically caches generated images and videos locally to overcome 403 errors on direct Grok links, ensuring reliable media access.
  • Account & Quota Management: Supports both free "Basic" accounts (80 calls/20 hours) and "Super" accounts (quota TBD), with system-level load balancing and real-time usage monitoring via the admin console.
  • Model Variety: Offers access to multiple Grok models (grok-3-fast, grok-4-fast, grok-4-expert, grok-4-heavy, grok-imagine-0.9), each with distinct capabilities and associated costs.

Maintenance & Community

The project acknowledges inspiration from LINUX DO, VeroFess/grok2api, and xLmiler/grok2api_python. No specific community channels (like Discord or Slack) or active maintainer information are provided in the README.

Licensing & Compatibility

The project is explicitly stated to be for "learning and research only," implying it may not be suitable for commercial use without further clarification or a formal license agreement. Compatibility is high for OpenAI API clients.

Limitations & Caveats

The project is intended strictly for learning and research purposes. Grok's direct image and video links are prone to 403 errors, necessitating the use of the built-in caching mechanism. A specific x_statsig_id is required for anti-bot measures, with a default value provided for broad compatibility. Quotas for "Super" accounts remain undetermined.

Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
3
Issues (30d)
22
Star History
174 stars in the last 30 days

Explore Similar Projects

Starred by Tobi Lutke Tobi Lutke(Cofounder of Shopify), Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), and
27 more.

open-webui by open-webui

0.5%
117k
Self-hosted AI platform for local LLM deployment
Created 2 years ago
Updated 23 hours ago
Feedback? Help us improve.