chenyme/grok2apiPublic

Multi-account API gateway for Grok Build, Grok Web, and Grok Console

AI summary: A multi-account API gateway written in Go that unifies access to Grok Build, Grok Web, and Grok Console via OpenAI and Anthropic-compatible APIs.

Stars
7.2K
Forks
2.2K
Watchers
15
Open issues
13
Open PRs
3
Contributors
~81
Commits
1.2K
Branches
9

GoMITCreated Oct 10, 2025Last push todayLatest release v3.1.1

Star history

since Oct 12, 2025
02K4K6KOct 2025Jan 2026Apr 2026Aug 2026
7.2K stars as of Aug 8, 2026, tracked back to Oct 12, 2025. Historical curve reconstructed from public GitHub event archives, calibrated to the current total.

Contribution activity

commits per day, last 52 weeks
AugSepOctNovDecJanFebMarAprMayJunJulAugMonWedFri2025-08-10: 0 commits2025-08-11: 0 commits2025-08-12: 0 commits2025-08-13: 0 commits2025-08-14: 0 commits2025-08-15: 0 commits2025-08-16: 0 commits2025-08-17: 0 commits2025-08-18: 0 commits2025-08-19: 0 commits2025-08-20: 0 commits2025-08-21: 0 commits2025-08-22: 0 commits2025-08-23: 0 commits2025-08-24: 0 commits2025-08-25: 0 commits2025-08-26: 0 commits2025-08-27: 0 commits2025-08-28: 0 commits2025-08-29: 0 commits2025-08-30: 0 commits2025-08-31: 0 commits2025-09-01: 0 commits2025-09-02: 0 commits2025-09-03: 0 commits2025-09-04: 0 commits2025-09-05: 0 commits2025-09-06: 0 commits2025-09-07: 0 commits2025-09-08: 0 commits2025-09-09: 0 commits2025-09-10: 0 commits2025-09-11: 0 commits2025-09-12: 0 commits2025-09-13: 0 commits2025-09-14: 0 commits2025-09-15: 0 commits2025-09-16: 0 commits2025-09-17: 0 commits2025-09-18: 0 commits2025-09-19: 0 commits2025-09-20: 0 commits2025-09-21: 0 commits2025-09-22: 0 commits2025-09-23: 0 commits2025-09-24: 0 commits2025-09-25: 0 commits2025-09-26: 0 commits2025-09-27: 0 commits2025-09-28: 0 commits2025-09-29: 0 commits2025-09-30: 0 commits2025-10-01: 0 commits2025-10-02: 0 commits2025-10-03: 0 commits2025-10-04: 0 commits2025-10-05: 0 commits2025-10-06: 0 commits2025-10-07: 0 commits2025-10-08: 0 commits2025-10-09: 0 commits2025-10-10: 3 commits2025-10-11: 2 commits2025-10-12: 0 commits2025-10-13: 0 commits2025-10-14: 9 commits2025-10-15: 7 commits2025-10-16: 5 commits2025-10-17: 8 commits2025-10-18: 0 commits2025-10-19: 0 commits2025-10-20: 0 commits2025-10-21: 0 commits2025-10-22: 3 commits2025-10-23: 3 commits2025-10-24: 0 commits2025-10-25: 0 commits2025-10-26: 0 commits2025-10-27: 0 commits2025-10-28: 5 commits2025-10-29: 1 commit2025-10-30: 0 commits2025-10-31: 0 commits2025-11-01: 0 commits2025-11-02: 0 commits2025-11-03: 0 commits2025-11-04: 0 commits2025-11-05: 0 commits2025-11-06: 0 commits2025-11-07: 0 commits2025-11-08: 0 commits2025-11-09: 0 commits2025-11-10: 0 commits2025-11-11: 0 commits2025-11-12: 0 commits2025-11-13: 0 commits2025-11-14: 0 commits2025-11-15: 1 commit2025-11-16: 0 commits2025-11-17: 0 commits2025-11-18: 3 commits2025-11-19: 0 commits2025-11-20: 3 commits2025-11-21: 2 commits2025-11-22: 3 commits2025-11-23: 0 commits2025-11-24: 0 commits2025-11-25: 0 commits2025-11-26: 0 commits2025-11-27: 0 commits2025-11-28: 0 commits2025-11-29: 0 commits2025-11-30: 0 commits2025-12-01: 0 commits2025-12-02: 0 commits2025-12-03: 0 commits2025-12-04: 0 commits2025-12-05: 0 commits2025-12-06: 0 commits2025-12-07: 0 commits2025-12-08: 0 commits2025-12-09: 0 commits2025-12-10: 0 commits2025-12-11: 0 commits2025-12-12: 2 commits2025-12-13: 0 commits2025-12-14: 0 commits2025-12-15: 0 commits2025-12-16: 2 commits2025-12-17: 3 commits2025-12-18: 0 commits2025-12-19: 4 commits2025-12-20: 0 commits2025-12-21: 0 commits2025-12-22: 1 commit2025-12-23: 0 commits2025-12-24: 0 commits2025-12-25: 0 commits2025-12-26: 0 commits2025-12-27: 0 commits2025-12-28: 0 commits2025-12-29: 0 commits2025-12-30: 0 commits2025-12-31: 0 commits2026-01-01: 0 commits2026-01-02: 0 commits2026-01-03: 0 commits2026-01-04: 0 commits2026-01-05: 0 commits2026-01-06: 0 commits2026-01-07: 0 commits2026-01-08: 0 commits2026-01-09: 0 commits2026-01-10: 0 commits2026-01-11: 0 commits2026-01-12: 0 commits2026-01-13: 0 commits2026-01-14: 0 commits2026-01-15: 0 commits2026-01-16: 0 commits2026-01-17: 0 commits2026-01-18: 0 commits2026-01-19: 0 commits2026-01-20: 0 commits2026-01-21: 0 commits2026-01-22: 0 commits2026-01-23: 0 commits2026-01-24: 0 commits2026-01-25: 0 commits2026-01-26: 0 commits2026-01-27: 0 commits2026-01-28: 0 commits2026-01-29: 0 commits2026-01-30: 0 commits2026-01-31: 0 commits2026-02-01: 0 commits2026-02-02: 7 commits2026-02-03: 5 commits2026-02-04: 14 commits2026-02-05: 4 commits2026-02-06: 7 commits2026-02-07: 15 commits2026-02-08: 9 commits2026-02-09: 4 commits2026-02-10: 7 commits2026-02-11: 5 commits2026-02-12: 2 commits2026-02-13: 8 commits2026-02-14: 0 commits2026-02-15: 7 commits2026-02-16: 5 commits2026-02-17: 7 commits2026-02-18: 1 commit2026-02-19: 4 commits2026-02-20: 5 commits2026-02-21: 2 commits2026-02-22: 3 commits2026-02-23: 0 commits2026-02-24: 3 commits2026-02-25: 0 commits2026-02-26: 13 commits2026-02-27: 13 commits2026-02-28: 1 commit2026-03-01: 15 commits2026-03-02: 1 commit2026-03-03: 1 commit2026-03-04: 8 commits2026-03-05: 6 commits2026-03-06: 10 commits2026-03-07: 2 commits2026-03-08: 2 commits2026-03-09: 0 commits2026-03-10: 0 commits2026-03-11: 0 commits2026-03-12: 6 commits2026-03-13: 2 commits2026-03-14: 0 commits2026-03-15: 0 commits2026-03-16: 2 commits2026-03-17: 5 commits2026-03-18: 1 commit2026-03-19: 1 commit2026-03-20: 2 commits2026-03-21: 0 commits2026-03-22: 0 commits2026-03-23: 3 commits2026-03-24: 1 commit2026-03-25: 0 commits2026-03-26: 0 commits2026-03-27: 1 commit2026-03-28: 0 commits2026-03-29: 0 commits2026-03-30: 2 commits2026-03-31: 0 commits2026-04-01: 0 commits2026-04-02: 2 commits2026-04-03: 2 commits2026-04-04: 0 commits2026-04-05: 0 commits2026-04-06: 0 commits2026-04-07: 1 commit2026-04-08: 1 commit2026-04-09: 0 commits2026-04-10: 28 commits2026-04-11: 14 commits2026-04-12: 11 commits2026-04-13: 11 commits2026-04-14: 1 commit2026-04-15: 0 commits2026-04-16: 0 commits2026-04-17: 2 commits2026-04-18: 1 commit2026-04-19: 2 commits2026-04-20: 15 commits2026-04-21: 1 commit2026-04-22: 1 commit2026-04-23: 2 commits2026-04-24: 0 commits2026-04-25: 1 commit2026-04-26: 0 commits2026-04-27: 0 commits2026-04-28: 4 commits2026-04-29: 0 commits2026-04-30: 0 commits2026-05-01: 0 commits2026-05-02: 0 commits2026-05-03: 0 commits2026-05-04: 0 commits2026-05-05: 0 commits2026-05-06: 0 commits2026-05-07: 0 commits2026-05-08: 0 commits2026-05-09: 0 commits2026-05-10: 0 commits2026-05-11: 0 commits2026-05-12: 0 commits2026-05-13: 0 commits2026-05-14: 0 commits2026-05-15: 0 commits2026-05-16: 0 commits2026-05-17: 0 commits2026-05-18: 0 commits2026-05-19: 0 commits2026-05-20: 0 commits2026-05-21: 0 commits2026-05-22: 0 commits2026-05-23: 0 commits2026-05-24: 0 commits2026-05-25: 0 commits2026-05-26: 0 commits2026-05-27: 0 commits2026-05-28: 0 commits2026-05-29: 0 commits2026-05-30: 0 commits2026-05-31: 0 commits2026-06-01: 0 commits2026-06-02: 0 commits2026-06-03: 1 commit2026-06-04: 0 commits2026-06-05: 0 commits2026-06-06: 0 commits2026-06-07: 0 commits2026-06-08: 0 commits2026-06-09: 1 commit2026-06-10: 0 commits2026-06-11: 0 commits2026-06-12: 0 commits2026-06-13: 0 commits2026-06-14: 0 commits2026-06-15: 0 commits2026-06-16: 0 commits2026-06-17: 0 commits2026-06-18: 0 commits2026-06-19: 0 commits2026-06-20: 0 commits2026-06-21: 0 commits2026-06-22: 0 commits2026-06-23: 0 commits2026-06-24: 0 commits2026-06-25: 0 commits2026-06-26: 0 commits2026-06-27: 0 commits2026-06-28: 0 commits2026-06-29: 0 commits2026-06-30: 0 commits2026-07-01: 0 commits2026-07-02: 0 commits2026-07-03: 0 commits2026-07-04: 0 commits2026-07-05: 0 commits2026-07-06: 0 commits2026-07-07: 0 commits2026-07-08: 0 commits2026-07-09: 0 commits2026-07-10: 0 commits2026-07-11: 0 commits2026-07-12: 1 commit2026-07-13: 14 commits2026-07-14: 29 commits2026-07-15: 19 commits2026-07-16: 14 commits2026-07-17: 34 commits2026-07-18: 13 commits2026-07-19: 14 commits2026-07-20: 23 commits2026-07-21: 13 commits2026-07-22: 18 commits2026-07-23: 14 commits2026-07-24: 9 commits2026-07-25: 8 commits2026-07-26: 14 commits2026-07-27: 12 commits2026-07-28: 14 commits2026-07-29: 7 commits2026-07-30: 3 commits2026-07-31: 0 commits2026-08-01: 6 commits2026-08-02: 1 commit2026-08-03: 3 commits2026-08-04: 10 commits2026-08-05: 14 commits2026-08-06: 14 commits2026-08-07: 7 commits2026-08-08: 0 commits
722 commits in the last yearLessMore

Signals and awards

derived from tracked data
  • Very active

    722 commits in 52 weeks

  • Permissive license

    MIT

  • Continuous integration

    Automated checks passing

What grok2api does

Grok2API acts as a comprehensive gateway that abstracts away the complexities of managing multiple Grok accounts across different provider interfaces. It provides independent account pools and exposes standardized OpenAI and Anthropic-compatible APIs for seamless integration with existing tools. The system handles intelligent routing, model discovery, and bounded failover to ensure stable and resilient access. Built in Go, it features a React-based administration console to manage configurations, monitor audit trails, and oversee remote quota synchronizations. It simplifies the integration of advanced Grok capabilities like image generation and asynchronous video tasks without needing direct API manipulation.

Software engineers, DevOps professionals, and organizations looking to scale and standardize their access to Grok APIs. It is ideal for those managing multiple accounts or integrating Grok into standard OpenAI-compatible ecosystems.

  • Multi-Provider Unification: Bridges Grok Build, Grok Web, and Grok Console under a single unified architecture.
  • Compatible API Endpoints: Exposes both OpenAI and Anthropic-compatible APIs to support a wide range of existing software integrations.
  • Intelligent Routing: Supports model discovery, provider pinning, sticky sessions, and quota guards for optimized request handling.
  • Media Processing Pipeline: Handles image generation, image editing, and asynchronous video jobs with local archiving.
  • Built-in Administration Console: A React frontend for managing accounts, sync statuses, billing, and runtime settings.
  • Egress Management: Integrates proxy pools, SOCKS routing, and FlareSolverr for robust external connectivity.

Where teams use it

Enterprise API Distribution

Teams can pool multiple Grok accounts and distribute API keys internally with managed quotas.

Standardized Tool Integration

Developers can drop in Grok2API as a drop-in replacement for OpenAI endpoints in applications like Codex or Claude Code.

Media Generation Infrastructure

Applications requiring programmatic generation of images and video can leverage Grok's media capabilities via standard requests.

High-Availability Inference

Production environments can utilize bounded failover and sticky sessions to maintain uptime during provider instability.

Getting started: git clone https://github.com/chenyme/grok2api.git

README

main branch

Grok2API

A multi-account API gateway for Grok Build, Grok Web, and Grok Console

English | 简体中文

Go React Docker

chenyme%2Fgrok2api | Trendshift

Tip

Check out DEEIX-AI / DEEIX-Chat, a lightweight, integrated AI platform for model routing, chat, files, tools, billing, identity, and operations.

Note

This project is for technical research and learning purposes only. Please comply with Grok's official terms of use and local laws when using it; otherwise, you will be solely responsible for all consequences!

Sponsors

Want to sponsor this project?

Krill AI Krill AI provides fast, stable API access to GPT, Claude, Gemini, and leading Chinese models, with enterprise customization, invoicing, 7×16 support, and optimized WebSocket connections for faster first-token latency. Register through the exclusive link and use code “grok2api” for 23% off your first Codex package.
DEEIX AI / DEEIX Chat DEEIX-Chat is an open-source, self-hostable AI Chat platform for individuals, teams, and enterprises that need stable, long-term, unified access to multiple models. It brings models, conversations, files, tool calling, and administration together in one deployable and extensible system. Click here to start deploying.
RightCode Right Code is an enterprise-grade AI Agent distribution platform that primarily provides stable access services for Claude Code, Codex, Gemini, and other models. It supports invoicing and dedicated one-to-one assistance for enterprises and teams. Thanks to Right Code for providing token support. Click here to register and get started.
FennoAI FennoAI provides enterprise-grade OpenAI/Anthropic-compatible APIs for Codex, Claude Code, and OpenCode, processing hundreds of billions of tokens daily with global business settlement and invoicing. Through the Grok2API exclusive offer, USD 1.99 unlocks USD 50 in Coding Plan credits, plus referral commissions up to 20%.
Qiniu Cloud AI Qiniu Cloud AI, Qiniu Cloud’s (02567.HK) enterprise MaaS platform, offers protocol-compatible access to 150+ global models for text, image, audio, video, and files, serving 1.69+ million users. Grok2API registrations through the exclusive link receive 12 million free enterprise tokens or 3 million developer tokens.

Overview

Grok2API is a Go gateway with a built-in React admin console. It manages independent Grok Build, Grok Web, and Grok Console account pools and exposes unified OpenAI- and Anthropic-compatible APIs.

Architecture

flowchart LR
    %% Color definitions
    classDef access fill:#e1f5fe,stroke:#01579b
    classDef core fill:#fff3e0,stroke:#e65100
    classDef providers fill:#f3e5f5,stroke:#4a148c
    classDef infra fill:#e8f5e9,stroke:#1b5e20
    classDef upstream fill:#fce4ec,stroke:#880e4f

    subgraph Access["Access Domain"]
        direction LR
        Clients["API Clients"]
        Admin["React Admin"]
    end

    subgraph Core["Gateway Core Domain"]
        direction LR
        Management["Management Services<br/>Accounts · Models · Keys · Settings"]
        Sync["Account Sync<br/>Credentials · Quota · Models"]
        Gateway["Gateway Service<br/>Protocols · Routing · Selection · Retry"]
        Audit["Audit Service<br/>Usage · Client Billing"]
        Management --> Sync
        Gateway -.-> Audit
    end

    subgraph Providers["Provider Channel Domain"]
        direction LR
        Registry["Provider Registry"]
        Build["Grok Build<br/>OAuth · Dynamic Models · Billing"]
        Web["Grok Web<br/>SSO · Remote Quota · Media"]
        Console["Grok Console<br/>SSO · Local Window · Stateless"]
        Registry --> Build
        Registry --> Web
        Registry --> Console
    end

    subgraph Infra["Shared Infrastructure Domain"]
        direction LR
        Egress["Egress Manager<br/>Scopes · Proxy Pool · Fallback · Clearance"]
        Database[("SQLite / PostgreSQL")]
        Runtime[("Memory / Redis")]
    end

    Upstream["🌐 Grok Upstream"]

    %% Cross-domain calls
    Clients --> Gateway
    Admin --> Management
    Gateway --> Registry
    Sync --> Registry
    Build -->|grok_build| Egress
    Web -->|grok_web / asset| Egress
    Console -->|grok_console| Egress
    Egress --> Upstream
    Management --> Database
    Audit --> Database
    Gateway <--> Runtime

    %% Application styles
    class Clients,Admin access
    class Management,Sync,Gateway,Audit core
    class Registry,Build,Web,Console providers
    class Egress,Database,Runtime infra
    class Upstream upstream
Loading

The Gateway routes requests through the Provider Registry. Account Sync refreshes credentials, quota, and models. Each Provider keeps independent account state and uses an isolated egress scope; usage, audits, and client billing are finalized after the request.

Core capabilities

Area Capabilities
APIs Responses, Chat Completions, Anthropic Messages, Images, and asynchronous Videos
Clients Codex, Claude Code, OpenAI-compatible SDKs, and Anthropic-compatible SDKs
Accounts Bulk import/export, quota sync, credential renewal, conversion, tools, and cleanup
Routing Model discovery, Provider pinning, sticky sessions, quota/concurrency guards, and bounded failover
Sessions Stored responses, compact, prompt-cache affinity, and optional reasoning replay
Media Image generation/editing, video jobs, local archiving, and URL/Base64/SSE output
Egress HTTP/SOCKS/Resin, subscriptions, probes, proxy pools, allocation, fallback, and FlareSolverr
Operations Dashboard, model routes, client keys, audits, runtime settings, and media libraries

Provider boundaries

Provider Authentication Models Main capabilities
Grok Build OAuth / Device OAuth Discovered per account Responses, Chat, Messages, compact, stored responses, paid-account video
Grok Web SSO Built-in, filtered by tier Responses, Chat, Messages, stored responses, images, image editing, video
Grok Console SSO Built-in Stateless Responses, Chat, Messages, images, image editing, video

Each Provider keeps its own credentials, quota, health, cooldown, concurrency, and model capabilities. Failover stays within the selected Provider.

Quick start

Official images support linux/amd64 and linux/arm64.

git clone https://github.com/chenyme/grok2api.git
cd grok2api
cp config.example.yaml config.yaml

Generate secrets and place them in config.yaml:

openssl rand -hex 32
openssl rand -base64 32
secrets:
  jwtSecret: "replace-with-the-generated-hex-value"
  credentialEncryptionKey: "replace-with-the-generated-base64-key"

bootstrapAdmin:
  username: "admin"
  password: "replace-with-a-strong-password"

Start the service:

docker compose pull
docker compose up -d
docker compose logs -f grok2api

Open http://127.0.0.1:8000. The image already includes the frontend; SQLite data and local media are stored in the Compose volume.

Run from source

cp config.example.yaml config.yaml
make run

For frontend development:

cd frontend
pnpm install
pnpm dev

Set up the gateway

  1. Sign in with the bootstrap administrator.
  2. Connect a Build, Web, or Console account.
  3. Wait for its quota and model capabilities to sync.
  4. Review the public routes under Model Routes.
  5. Create a client key under Client Keys.
  6. Call a /v1/* endpoint with that key.

After first sign-in, change the administrator password and remove bootstrapAdmin from the configuration. Never rotate credentialEncryptionKey after credentials have been stored.

Account operations

Provider Connect or import Export
Build Device OAuth, JSON/JSONL Re-importable account file
Web Pasted/TXT SSO, JSON/JSONL Re-importable account file
Console Pasted/TXT SSO, JSON/JSONL Re-importable account file

Imports accept UTF-8 BOM. Bulk quota sync, Build credential renewal, Web→Build/Console conversion, account tools, and cleanup report live progress.

Web account tools can accept the terms, set a random birthday corresponding to an age of 20–40, and enable NSFW. Completed steps are recorded and skipped on later runs.

Automatic deletion of old reauthRequired accounts is available but disabled by default. Active inference leases and video jobs are protected.

Tip

To migrate from the Python version, export Grok Web SSO tokens as TXT and import them under Grok Web. Old pool metadata and databases are not compatible.

Models and routing

Build models are discovered from each account's actual capabilities. Web and Console use built-in catalogs. The Model Routes page shows Provider-qualified routes, endpoint capabilities, and supporting-account counts; clients should treat the currently serviceable results from GET /v1/models as authoritative.

Grok Build

Build does not use one global static model list. Account synchronization reads the upstream /models endpoint, and different accounts, subscription tiers, or staged rollouts may expose different models. Routing retains these per-account capabilities instead of replacing the global catalog with one account's response.

Model Type Availability Gateway surfaces
Conversation models returned by upstream /models (for example, grok-4.5) Conversation Returned by the selected account Chat Completions, Responses, Messages, compact, stored responses
grok-composer-2.5-fast Conversation Grok Build OAuth accounts Chat Completions, Responses, Messages; supplemented from the OAuth session contract when a sparse upstream catalog omits it
grok-imagine-video-1.5 Video Super/paid Build accounts Videos; not assigned to Free or unknown-entitlement accounts

Conversation requests are translated to the Build Responses protocol while preserving the tool, reasoning, multi-turn, and prompt-cache compatibility required by Codex and Claude Code. Build currently exposes no image generation or image editing routes.

Grok Web

Web uses a built-in catalog filtered by account tier; higher tiers inherit lower-tier models.

Model Type Minimum tier Gateway surfaces
grok-chat-fast Conversation Basic Chat Completions, Responses, Messages
grok-chat-auto Conversation Super Chat Completions, Responses, Messages
grok-chat-expert Conversation Super Chat Completions, Responses, Messages
grok-chat-heavy Conversation Heavy Chat Completions, Responses, Messages
grok-imagine-image-lite Image Basic Images Generations
grok-imagine-image-quality-lite Image Super Images Generations
grok-imagine-image-edit Image Edit Super Images Edits
grok-imagine-video Video Super Videos

Grok Console

Console uses the catalog built into the current release. Conversation forwarding is stateless, while image and video models use the standard xAI resource APIs.

Model Type Gateway surfaces
grok-4.20-0309-non-reasoning Conversation Chat Completions, Responses, Messages
grok-4.20-0309-reasoning Conversation Chat Completions, Responses, Messages; the model reasons but the upstream rejects configurable reasoningEffort
grok-4.20-multi-agent-0309 Conversation Chat Completions, Responses, Messages
grok-4.5 Conversation Chat Completions, Responses, Messages
grok-4.3 Conversation Chat Completions, Responses, Messages
grok-build-0.1 Conversation Chat Completions, Responses, Messages
grok-imagine-image Image, Image Edit Images Generations, Images Edits
grok-imagine-image-quality Image, Image Edit Images Generations, Images Edits
grok-imagine-video Video Videos

Generation and editing capabilities for the same Console image model are grouped into one logical model row; no separate -edit model copy is required.

Public names normally omit the Provider. Internally, routes use Build/, Web/, or Console/; qualified names can pin a request to one source.

Web can be weakly linked one-to-one with matching Build and Console accounts. Links share only an anonymous egress identity and provenance display. They never merge credentials, quota, health, cooldown, concurrency, capabilities, or billing.

Codex, Claude Code, and prompt caching

Responses and Messages support streaming, tools, reasoning, multi-turn sessions, and compaction. Stable client session signals are preserved for Grok Build prompt-cache affinity. Cache hits still require a compatible upstream account and an unchanged prompt prefix.

Responses and Chat Completions report OpenAI-style total input. Messages reports Anthropic-style uncached input and cache reads separately. Audits retain total and cached input for billing reconciliation.

API

Inference endpoints use a client key:

Authorization: Bearer g2a_xxx_xxx
Method Path Purpose
GET /healthz, /readyz Liveness and readiness
GET /v1/models Serviceable models
POST /v1/responses Responses JSON/SSE
POST /v1/responses/compact Compact a supported Response session
GET, DELETE /v1/responses/{id} Read or delete a stored response
POST /v1/chat/completions Chat Completions JSON/SSE
POST /v1/messages Anthropic Messages JSON/SSE
POST /v1/images/generations, /v1/images/edits Generate or edit images
POST, GET /v1/videos/* Create and inspect video jobs
GET /v1/media/images/{asset_id}, /v1/media/videos/{asset_id} Read archived media

Stored responses and compact depend on the selected Provider. The signed-in admin console provides live examples at /docs; Swagger is available only when server.swaggerEnabled: true.

Client keys support model allowlists and optional RPM, concurrency, spend, and expiry limits.

curl http://127.0.0.1:8000/v1/responses \
  -H "Authorization: Bearer g2a_xxx_xxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model",
    "input": "Explain quantum tunneling in three sentences.",
    "stream": true
  }'

Egress and Cloudflare

Egress nodes are scoped to Build, Web, Console, or Web assets. The admin console supports:

  • HTTP, HTTPS, SOCKS4/4A, SOCKS5/5H, and Resin
  • Subscription and text/Base64 import
  • Batch probes, filtering, deletion, assignment, and balancing
  • Fallback per scope: none, direct, or a fixed node
  • Proxy-pool mode without global cooldown after one connection failure
  • Immediate recovery probes after fixed-proxy transport failures, with per-node coalescing and bounded waiting for fast retry
  • Optional Egress Quality Guard for active per-node model probes, guarded quarantine, and recovery; enable it with the built-in quality-guard Compose profile

To enable the guard, add a qualityGuard section to config.yaml, then start the profile. The main service creates and reuses a non-exportable system probe identity automatically:

qualityGuard:
  enabled: true
  model: "grok-4.5"
docker compose --profile quality-guard up -d --build

Existing preview deployments that still contain clientKeyID can upgrade directly. The field is accepted for compatibility but ignored and can be removed; any manually created probe key is intentionally left untouched.

After changing this configuration, run docker compose --profile quality-guard restart grok2api egress-quality-guard to reload the base settings; policy edits made in the admin page still hot-reload.

The normal docker compose up -d command does not start the guard or generate probe traffic. The sidecar receives a narrowly scoped internal credential from the main service and never stores or uses the administrator password. See the linked guide before enabling automatic quarantine.

Resin usernames can contain {account}:

socks5h://Default.{account}:RESIN_PROXY_TOKEN@resin:2260

The placeholder becomes a stable anonymous identity. Linked Web, Build, and Console accounts can share it; raw tokens and email addresses are not used.

For managed Web/Console Cloudflare Clearance:

docker compose --profile flaresolverr up -d

Then select FlareSolverr under Runtime Settings → Media & Network → Clearance and use http://flaresolverr:8191.

The egress layer retries only connection failures known to occur before request submission. It does not replay submitted generation requests, authentication failures, exhausted quotas, or upstream rate limits.

When a fixed proxy enters cooldown after a transport failure, grok2api starts an independent connectivity probe immediately. Concurrent failures share one probe. A later request bound to that node waits for at most five seconds, reloads persisted node state after a healthy probe, and continues without waiting for the full cooldown. An unhealthy probe preserves the cooldown. Proxy-pool leases use fresh tunnels, so one rotating exit failure never cools the whole pool. See Immediate egress failure probe and bounded retry for the design and safety invariants.

Configuration and deployment

config.yaml contains startup settings; Provider and operational settings are managed in the admin console and hot-reload unless marked otherwise.

Deployment Database Runtime store Media
Single instance SQLite Memory Local directory
Multiple instances PostgreSQL Redis Shared read/write directory

Multi-instance deployments require a unique deployment.instanceID per replica, one shared clusterID, and sharedMedia: true only after the media directory is shared correctly.

PostgreSQL credentials can be injected without storing them in config.yaml:

GROK2API_DATABASE_URL='postgresql://user:password@host:5432/grok2api?sslmode=require' docker compose up -d

A non-empty GROK2API_DATABASE_URL overrides database.postgres.dsn and automatically selects the postgres driver. An empty value is ignored. Supported URL schemes are postgres:// and postgresql://; SQLAlchemy's postgresql+asyncpg:// form is rejected with a migration hint. The application does not implicitly read the generic DATABASE_URL; platforms that provide it can map it explicitly with GROK2API_DATABASE_URL: "${DATABASE_URL}". Database configuration precedence is built-in defaults, config.yaml, then GROK2API_DATABASE_URL. The current CLI has no database override.

Important optional settings:

  • audit.ledgerMode: observe reports ledger faults; enforce can pause new inference to protect billing integrity.
  • routing.accountIsolatedConnections: partitions outbound TCP/HTTP pools by account for external L4 or connection-hash load balancers. It is off by default because it increases connections, TLS handshakes, memory, and file-descriptor usage.
  • routing.segmentedSelectorEnabled: optimizes large account pools while retaining full-planner fallback and atomic guards.
  • Build response-header timeout and exact-match 403 invalidation rules are hot-reloadable.
  • Sync latest version applies the validated Grok Build client version and User-Agent.

Production checklist

  • Use HTTPS and enable auth.secureCookies.
  • Keep Swagger disabled on public deployments.
  • Use strong, backed-up secrets; never commit credentials, cookies, exports, or databases.
  • Back up config.yaml, the database, and media storage.
  • Use PostgreSQL, Redis, and shared media for multiple instances.
  • Put a reverse proxy and access controls in front of public deployments.

Development

cd backend
go test ./...
go test -race ./...
go vet ./...
go build ./cmd/grok2api
cd frontend
pnpm install --frozen-lockfile
pnpm lint
pnpm build

Regenerate Swagger after changing public API annotations:

make swagger

Documentation

View on GitHub

Recent activity

commits and pull requests

Releases and announcements

26 total
  1. v3.1.1v3.1.1Aug 5, 2026

    ## What's Changed * feat: align DPoP protocol, real usage quotas, and 24h recovery probing by @chenyme in https://github.com/chenyme/grok2api/pull/853 * feat: support bare JSON array credential import by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/854 * fix(test): skip POSIX permission assertions on Windows by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/855 **Full Changelog**: https://github.com/chenyme/grok2api/compare/v3.1.0...v3.1.1

  2. v3.1.0v3.1.0Aug 4, 2026

    ## What's Changed * fix(media): 修复 Windows 下视频上传提交因只读句柄 fsync 失败 by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/829 * fix(test): 修复直传文件名净化测试的跨平台断言 by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/831 * feat: improve Build account detection and routing failover by @night2049 in https://github.com/chenyme/grok2api/pull/832 * feat: add compact date-time formatting and update audit display by @chenyme in https://github.com/chenyme/grok2api/pull/833 * feat: filter accounts by egress node or subscription source by @MMortise in https://github.com/chenyme/grok2api/pull/834 * feat: harden egress quality guard and recovery by @lij768423-svg in https://github.com/chenyme/grok2api/pull/837 * fix: harden Grok Build 0.2.119 protocol compatibility by @chenyme in https://github.com/chenyme/grok2api/pull/843 * fix: handle fixed reasoning for Grok Console 4.20 by @chenyme in https://github.com/chenyme/grok2api/pull/844 * feat: support session-sticky routing across duplicate model targets by @chenyme in https://github.com/chenyme/grok2api/pull/845 * feat(egress): isolate upstream TCP pools by account by @buddhism5080 in https://github.com/chenyme/grok2api/pull/841

  3. v3.0.11v3.0.11Jul 29, 2026

    ## What's Changed * feat(accounts): support selective and paginated credential exports by @AmPlace in https://github.com/chenyme/grok2api/pull/797 * perf: reduce database I/O with deferred credential hydration by @chenyme in https://github.com/chenyme/grok2api/pull/800 * feat: streamline egress proxy management and dual-stack cleanup by @chenyme in https://github.com/chenyme/grok2api/pull/801 * feat: add response performance metrics and billing breakdowns by @chenyme in https://github.com/chenyme/grok2api/pull/804 * fix(responses): normalize schema-declared integer tool arguments by @AmPlace in https://github.com/chenyme/grok2api/pull/807 * feat: add batch account concurrency control by @AmPlace in https://github.com/chenyme/grok2api/pull/809 * fix: update Grok Build Free quota fallback to 500k by @AmPlace in https://github.com/chenyme/grok2api/pull/810 * fix: rotate explicit Build proxy pools per request by @AmPlace in https://github.com/chenyme/grok2api/pull/811 * feat: add client key routing scopes with fail-closed enforcement by @chenyme in https://github.com/chenyme/grok2api/pull/813 * fix(frontend): repair mobile admin layout regressions by @kirafishy in https://git

  4. v3.0.10v3.0.10Jul 27, 2026

    ## What's Changed * feat: introduce webVisibleStreamPhase to manage client-visible output and suppress late reasoning by @chenyme in https://github.com/chenyme/grok2api/pull/780 * fix(gateway): classify Build safety and quota failures by @AmPlace in https://github.com/chenyme/grok2api/pull/781 * fix(routing): remove maxAttempts hard upper limit of 10 by @jun9100 in https://github.com/chenyme/grok2api/pull/782 * feat(accounts): 跨 Provider 账号关联管理——可选的关联删除、绑定筛选与清理 by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/790 * feat: 支持按 API Key 开关的思考等级模型别名(如 grok-4.5-low) by @starsdream666 in https://github.com/chenyme/grok2api/pull/785 * feat: 改进出口代理双栈探测与可观测性 by @put-go in https://github.com/chenyme/grok2api/pull/787 * fix: avoid cooling proxy nodes on canceled requests by @chenyme in https://github.com/chenyme/grok2api/pull/794 * fix: preserve pre-upstream selection diagnostics by @chenyme in https://github.com/chenyme/grok2api/pull/795 * fix: 允许FlareSolverr清除而不使用挑战Cookie by @put-go in https://github.com/chenyme/grok2api/pull/788 **Full Changelog**: https://github.com/chenyme/grok2api/compare/v3.0.9...v3.0.10

  5. v3.0.9v3.0.9Jul 25, 2026

    ## What's Changed * chore: update recommended build version to 0.2.111 and enhance OAuth client functionality by @chenyme in https://github.com/chenyme/grok2api/pull/768 * fix(cli): normalize nullable function parameter roots by @RuruoB in https://github.com/chenyme/grok2api/pull/766 * feat: 创作控制台聊天支持单条消息重生成/修改/删除与停止生成 by @starsdream666 in https://github.com/chenyme/grok2api/pull/767 * feat(account): 完善 SSO 失效——补齐 403 正文明确封号(导入 / 额度 / Web && Console 对话) by @Huan-zhaojun in https://github.com/chenyme/grok2api/pull/774 * 放宽「同一 Provider + 同一 upstream 只能有一条路由」的限制,使管理端可创建: by @woodnaonly in https://github.com/chenyme/grok2api/pull/772 * feat: implement batch quota reset functionality for Build accounts by @chenyme in https://github.com/chenyme/grok2api/pull/778 * feat: updated egress binding UI by @chenyme in https://github.com/chenyme/grok2api/pull/779 ## New Contributors * @RuruoB made their first contribution in https://github.com/chenyme/grok2api/pull/766 * @woodnaonly made their first contribution in https://github.com/chenyme/grok2api/pull/772 **Full Changelog**: https://github.com/chenyme/grok2api/compare/v3.0.8...v3.0.9

Commits per week

last 52 weeks
1240Week of 2025-08-10: 0 commitsWeek of 2025-08-17: 0 commitsWeek of 2025-08-24: 0 commitsWeek of 2025-08-31: 0 commitsWeek of 2025-09-07: 0 commitsWeek of 2025-09-14: 0 commitsWeek of 2025-09-21: 0 commitsWeek of 2025-09-28: 0 commitsWeek of 2025-10-05: 5 commitsWeek of 2025-10-12: 29 commitsWeek of 2025-10-19: 6 commitsWeek of 2025-10-26: 6 commitsWeek of 2025-11-02: 0 commitsWeek of 2025-11-09: 1 commitsWeek of 2025-11-16: 11 commitsWeek of 2025-11-23: 0 commitsWeek of 2025-11-30: 0 commitsWeek of 2025-12-07: 2 commitsWeek of 2025-12-14: 9 commitsWeek of 2025-12-21: 1 commitsWeek of 2025-12-28: 0 commitsWeek of 2026-01-04: 0 commitsWeek of 2026-01-11: 0 commitsWeek of 2026-01-18: 0 commitsWeek of 2026-01-25: 0 commitsWeek of 2026-02-01: 52 commitsWeek of 2026-02-08: 35 commitsWeek of 2026-02-15: 31 commitsWeek of 2026-02-22: 33 commitsWeek of 2026-03-01: 43 commitsWeek of 2026-03-08: 10 commitsWeek of 2026-03-15: 11 commitsWeek of 2026-03-22: 5 commitsWeek of 2026-03-29: 6 commitsWeek of 2026-04-05: 44 commitsWeek of 2026-04-12: 26 commitsWeek of 2026-04-19: 22 commitsWeek of 2026-04-26: 4 commitsWeek of 2026-05-03: 0 commitsWeek of 2026-05-10: 0 commitsWeek of 2026-05-17: 0 commitsWeek of 2026-05-24: 0 commitsWeek of 2026-05-31: 1 commitsWeek of 2026-06-07: 1 commitsWeek of 2026-06-14: 0 commitsWeek of 2026-06-21: 0 commitsWeek of 2026-06-28: 0 commitsWeek of 2026-07-05: 0 commitsWeek of 2026-07-12: 124 commitsWeek of 2026-07-19: 99 commitsWeek of 2026-07-26: 56 commitsWeek of 2026-08-02: 49 commitsAug 10, 2025Aug 2, 2026
722 commits in the last 52 weeks.

When work happens

weekday and hour
SunMonTueWedThuFriSat036912151821Sun 0:00 — 8 commitsSun 1:00 — 1 commitsSun 2:00 — 1 commitsSun 3:00 — 4 commitsSun 4:00 — 0 commitsSun 5:00 — 0 commitsSun 6:00 — 0 commitsSun 7:00 — 0 commitsSun 8:00 — 0 commitsSun 9:00 — 1 commitsSun 10:00 — 9 commitsSun 11:00 — 5 commitsSun 12:00 — 4 commitsSun 13:00 — 5 commitsSun 14:00 — 4 commitsSun 15:00 — 5 commitsSun 16:00 — 6 commitsSun 17:00 — 7 commitsSun 18:00 — 8 commitsSun 19:00 — 2 commitsSun 20:00 — 2 commitsSun 21:00 — 2 commitsSun 22:00 — 2 commitsSun 23:00 — 3 commitsMon 0:00 — 4 commitsMon 1:00 — 4 commitsMon 2:00 — 1 commitsMon 3:00 — 1 commitsMon 4:00 — 1 commitsMon 5:00 — 0 commitsMon 6:00 — 4 commitsMon 7:00 — 2 commitsMon 8:00 — 0 commitsMon 9:00 — 3 commitsMon 10:00 — 12 commitsMon 11:00 — 7 commitsMon 12:00 — 2 commitsMon 13:00 — 5 commitsMon 14:00 — 8 commitsMon 15:00 — 8 commitsMon 16:00 — 8 commitsMon 17:00 — 5 commitsMon 18:00 — 4 commitsMon 19:00 — 4 commitsMon 20:00 — 4 commitsMon 21:00 — 4 commitsMon 22:00 — 8 commitsMon 23:00 — 4 commitsTue 0:00 — 1 commitsTue 1:00 — 3 commitsTue 2:00 — 2 commitsTue 3:00 — 0 commitsTue 4:00 — 0 commitsTue 5:00 — 0 commitsTue 6:00 — 2 commitsTue 7:00 — 1 commitsTue 8:00 — 2 commitsTue 9:00 — 7 commitsTue 10:00 — 10 commitsTue 11:00 — 9 commitsTue 12:00 — 3 commitsTue 13:00 — 8 commitsTue 14:00 — 10 commitsTue 15:00 — 13 commitsTue 16:00 — 9 commitsTue 17:00 — 6 commitsTue 18:00 — 9 commitsTue 19:00 — 2 commitsTue 20:00 — 5 commitsTue 21:00 — 11 commitsTue 22:00 — 2 commitsTue 23:00 — 7 commitsWed 0:00 — 8 commitsWed 1:00 — 6 commitsWed 2:00 — 1 commitsWed 3:00 — 0 commitsWed 4:00 — 6 commitsWed 5:00 — 1 commitsWed 6:00 — 7 commitsWed 7:00 — 2 commitsWed 8:00 — 0 commitsWed 9:00 — 2 commitsWed 10:00 — 4 commitsWed 11:00 — 6 commitsWed 12:00 — 3 commitsWed 13:00 — 3 commitsWed 14:00 — 3 commitsWed 15:00 — 2 commitsWed 16:00 — 9 commitsWed 17:00 — 12 commitsWed 18:00 — 3 commitsWed 19:00 — 2 commitsWed 20:00 — 7 commitsWed 21:00 — 2 commitsWed 22:00 — 8 commitsWed 23:00 — 7 commitsThu 0:00 — 1 commitsThu 1:00 — 4 commitsThu 2:00 — 4 commitsThu 3:00 — 3 commitsThu 4:00 — 3 commitsThu 5:00 — 1 commitsThu 6:00 — 0 commitsThu 7:00 — 0 commitsThu 8:00 — 5 commitsThu 9:00 — 4 commitsThu 10:00 — 6 commitsThu 11:00 — 8 commitsThu 12:00 — 1 commitsThu 13:00 — 4 commitsThu 14:00 — 4 commitsThu 15:00 — 9 commitsThu 16:00 — 4 commitsThu 17:00 — 9 commitsThu 18:00 — 8 commitsThu 19:00 — 4 commitsThu 20:00 — 3 commitsThu 21:00 — 4 commitsThu 22:00 — 2 commitsThu 23:00 — 5 commitsFri 0:00 — 9 commitsFri 1:00 — 4 commitsFri 2:00 — 3 commitsFri 3:00 — 1 commitsFri 4:00 — 1 commitsFri 5:00 — 0 commitsFri 6:00 — 0 commitsFri 7:00 — 0 commitsFri 8:00 — 0 commitsFri 9:00 — 3 commitsFri 10:00 — 11 commitsFri 11:00 — 15 commitsFri 12:00 — 15 commitsFri 13:00 — 14 commitsFri 14:00 — 7 commitsFri 15:00 — 13 commitsFri 16:00 — 17 commitsFri 17:00 — 7 commitsFri 18:00 — 7 commitsFri 19:00 — 1 commitsFri 20:00 — 8 commitsFri 21:00 — 4 commitsFri 22:00 — 5 commitsFri 23:00 — 4 commitsSat 0:00 — 2 commitsSat 1:00 — 1 commitsSat 2:00 — 2 commitsSat 3:00 — 0 commitsSat 4:00 — 0 commitsSat 5:00 — 1 commitsSat 6:00 — 2 commitsSat 7:00 — 0 commitsSat 8:00 — 3 commitsSat 9:00 — 3 commitsSat 10:00 — 4 commitsSat 11:00 — 3 commitsSat 12:00 — 4 commitsSat 13:00 — 10 commitsSat 14:00 — 7 commitsSat 15:00 — 1 commitsSat 16:00 — 3 commitsSat 17:00 — 2 commitsSat 18:00 — 1 commitsSat 19:00 — 1 commitsSat 20:00 — 6 commitsSat 21:00 — 2 commitsSat 22:00 — 7 commitsSat 23:00 — 4 commits
Commit volume by weekday and hour (UTC). Larger dots mean more commits.

Who is committing

last 52 weeks
Maintainer commits831 (71%)
Community commits346 (29%)

1,177 commits in total over the last year.

DateListRankStars gained
Aug 8, 2026daily#5+55
  • avelino/awesome-go

    A curated list of awesome Go frameworks, libraries and software

    180.5K stars · Go

  • farion1231/cc-switch

    A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

    125.6K stars · Rust

  • kubernetes/kubernetes

    Production-Grade Container Scheduling and Management

    124.4K stars · Go

  • asgeirtj/system_prompts_leaks

    Extracted system prompts from Anthropic - Claude Fable 5, Opus 5, Claude Design, Claude Code. OpenAI - ChatGPT GPT-5.6-Sol, Codex. Google - Gemini 3.5 Flash, 3.1 Pro, Antigravity. xAI - Grok, Cursor, Copilot, VS Code, Perplexity, and more. Updated regularly.

    62.5K stars · JavaScript

  • usememos/memos

    Open-source, self-hosted note-taking tool built for quick capture. Markdown-native, lightweight, and fully yours.

    62.1K stars · Go

  • hashicorp/terraform

    Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

    49.4K stars · Go