You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Project Discontinuation Notice
Due to limited personal bandwidth and multiple factors including increased official risk controls, this Grok2API project is now officially discontinued. The good news is that x-statsig-id can still be obtained or bypassed through other means. The repository will be archived and kept for learning and research reference only; there will be no further feature development, bug fixes, or technical support. Thank you all for your support along the way!
Tip
My New Project
I'd also like to recommend my new project, DEEIX-AI: DEEIX-Chat Lightweight AI Platform: an all-in-one enterprise AI platform for model routing, chat, files, tools, billing, identity, and operations — comprehensive yet extremely lightweight, with an idle runtime footprint of only 34 MB.
Note
This project is for learning and research only. Please comply with Grok's terms of use and all applicable local laws and regulations. Do not use it for illegal purposes.
Grok2API is a FastAPI-based Grok gateway that exposes Grok Web capabilities through OpenAI-compatible APIs. Core features:
git clone https://github.com/chenyme/grok2api
cd grok2api
cp .env.example .env
docker compose up -d
Vercel
Render
First Launch
Change app.app_key
Set app.api_key
Set app.app_url otherwise image and video URLs may return 403 Forbidden
WebUI
Routes
Page
Path
Admin login
/admin/login
Account management
/admin/account
Config management
/admin/config
Cache management
/admin/cache
WebUI login
/webui/login
Web Chat
/webui/chat
Masonry
/webui/masonry
ChatKit
/webui/chatkit
Authentication Rules
Scope
Config
Rule
/v1/*
app.api_key
No extra authentication when empty
/admin/*
app.app_key
Default value: grok2api
/webui/*
app.webui_enabled, app.webui_key
Disabled by default; if webui_key is empty, no extra verification is required
Configuration
Configuration Layers
Location
Purpose
Effective Time
.env
Pre-start configuration
At service startup
${DATA_DIR}/config.toml
Runtime configuration
Effective immediately after save
config.defaults.toml
Default template
On first initialization
Environment Variables
Variable
Description
Default
TZ
Time zone
Asia/Shanghai
LOG_LEVEL
Log level
INFO
LOG_FILE_ENABLED
Write local log files
true
ACCOUNT_SYNC_INTERVAL
Account directory incremental sync interval in seconds
30
ACCOUNT_SYNC_ACTIVE_INTERVAL
Active sync interval after account-directory changes are detected, in seconds
3
SERVER_HOST
Service bind address
0.0.0.0
SERVER_PORT
Service port
8000
SERVER_WORKERS
Granian worker count
1
HOST_PORT
Docker Compose published host port
8000
DATA_DIR
Local data root for accounts, locally cached media files, and cache indexes
./data
LOG_DIR
Local log directory
./logs
ACCOUNT_STORAGE
Account storage backend
local
ACCOUNT_LOCAL_PATH
SQLite path for local account storage
${DATA_DIR}/accounts.db
ACCOUNT_REDIS_URL
Redis DSN for redis mode
""
ACCOUNT_MYSQL_URL
SQLAlchemy DSN for mysql mode
""
ACCOUNT_POSTGRESQL_URL
SQLAlchemy DSN for postgresql mode
""
ACCOUNT_SQL_POOL_SIZE
Core connection pool size for SQL backends
5
ACCOUNT_SQL_MAX_OVERFLOW
Maximum overflow connections above pool size
10
ACCOUNT_SQL_POOL_TIMEOUT
Seconds to wait for a free connection from the pool
30
ACCOUNT_SQL_POOL_RECYCLE
Max connection lifetime in seconds before reconnect
1800
CONFIG_LOCAL_PATH
Runtime config file path for local config storage
${DATA_DIR}/config.toml
Runtime config can also be overridden with GROK_-prefixed environment variables. For example, GROK_APP_API_KEY overrides app.api_key, and GROK_FEATURES_STREAM overrides features.stream.