grok2api  by jiujiu532

Grok API gateway for OpenAI/Anthropic

Created 3 weeks ago

New!

893 stars

Top 40.1% on SourcePulse

GitHubView on GitHub
Project Summary

<2-3 sentences summarising what the project addresses and solves, the target audience, and the benefit.> This project provides a FastAPI-based gateway that exposes Grok's capabilities through an OpenAI-compatible API. It targets developers and power users seeking to integrate Grok into applications, offering a standardized interface and advanced features like multi-account management and content generation APIs. The primary benefit is simplifying programmatic access to Grok's advanced AI models.

How It Works

Grok2API leverages FastAPI to create endpoints mirroring OpenAI's API structure, including /v1/chat/completions and /v1/messages (Anthropic compatible). It supports streaming responses, explicit reasoning output, and function tool passing. A key architectural choice is its robust multi-account pooling system, which manages diverse Grok accounts (paid and free console.x.ai tiers) with features like hierarchical selection, quota synchronization, and automatic maintenance. This approach abstracts Grok's underlying complexities, providing a unified and reliable access layer.

Quick Start & Requirements

Deployment is primarily via Docker Compose, offering both a standard direct-connect version and an "anti-ban" version integrating WARP, Privoxy, and FlareSolverr for Cloudflare-protected IPs. The standard Docker image is ghcr.io/jiujiu532/grok2api:latest. A single Docker container and local source installation (Python 3.13+, uv) are also supported. The anti-ban version requires server capabilities NET_ADMIN and SYS_MODULE (KVM/XEN virtualization). Setup via Docker Compose is typically under 10 minutes.

Highlighted Details

  • OpenAI/Anthropic Compatibility: Exposes core chat, completions, and messages APIs.
  • Content Generation: Supports text-to-image, image editing, text-to-video, and image-to-video generation.
  • Multi-Account Management: Advanced pooling for paid and free (console.x.ai) accounts, including quota sync and auto-maintenance.
  • Built-in Interfaces: Features an Admin backend, Web Chat UI, Masonry image generator, and ChatKit voice interface.
  • Caching: Local caching for generated images and videos.
  • Anti-Ban Deployment: Integrated WARP, Privoxy, and FlareSolverr for robust access.

Maintenance & Community

This repository is a secondary build based on chenyme/grok2api. Community discussions and support are linked via Linux.do.

Licensing & Compatibility

The project is released under the MIT license, permitting commercial use and integration into closed-source applications without significant restrictions.

Limitations & Caveats

The project is explicitly stated for "learning and research exchange only." The anti-ban deployment has specific server virtualization requirements (NET_ADMIN, SYS_MODULE), excluding OpenVZ/LXC. Users may encounter Cloudflare challenges if not utilizing the anti-ban setup or proper proxy configurations.

Health Check
Last Commit

18 hours ago

Responsiveness

Inactive

Pull Requests (30d)
6
Issues (30d)
13
Star History
900 stars in the last 26 days

Explore Similar Projects

Feedback? Help us improve.