GrokForge
Full-model OpenAI-compatible Grok API gateway — single binary, ready to run
English · 简体中文
What is this
GrokForge wraps all Grok web capabilities (chat, reasoning, image generation/editing, video generation) into a standard OpenAI API format (a.k.a. 2api gateway). You can seamlessly connect any OpenAI-compatible client (ChatGPT Next Web, LobeChat, Open WebUI, Cursor, bots, etc.) to Grok models.
Go rewrite + Next.js admin panel, compiled into a single binary, SQLite out of the box, zero external dependencies.
Highlights
Single binary deployment — Frontend embedded via go:embed, just copy and run
Modern admin panel — Next.js + shadcn/ui, one-stop Dashboard / Token / API Key / Settings / Usage / Cache management
Dual-pool token routing — ssoBasic / ssoSuper grouped by model, 3 selection algorithms + priority tiers + auto fallback
Three independent quotas — Chat / Image / Video metered and recovered separately
Hot-reload config — Admin panel changes take effect immediately, no restart needed
Structured logging — slog + file rotation, JSON / Text formats
Bilingual UI — Admin panel supports English and Chinese
Features
Core
OpenAI Chat Completions API — Streaming / non-streaming, fully compatible
Chain-of-thought reasoning — <think> tag output, reasoning_effort control
Tool Calling — Hermes-style tool calls with parallel_tool_calls support
Multimodal input — Image URL / base64, auto download, decode and resize
Image generation / editing — WebSocket channel, multiple images, various sizes
Video generation — Multiple aspect ratios and resolutions
Model listing — GET /v1/models dynamically returns models, hot-configurable
Token Management
Dual-pool routing — ssoBasic / ssoSuper grouped by model, auto fallback
3 selection algorithms — high_quota_first / random / round_robin
Priority tiers — Higher priority tokens are selected first
Three quota categories — Chat / Image / Video independently metered and recovered
Auto refresh — Periodic session refresh, auto rebuild on failure
Token state machine — active / cooling / disabled / expired four-state transitions
Security & Reliability
API Key management — CRUD + model whitelist + daily limit + rate limit
Exponential backoff retry — Jitter + budget control + session auto-reset
Cloudflare defense — FlareSolverr integration, instant 403 refresh + debounce
Secure authentication — Constant-time comparison, empty AppKey rejects access
Admin Panel
Dashboard — Stats cards + quota progress + usage trend charts
Token management — Batch import / enable / disable / delete, status filtering, health indicators
API Key management — Create / disable / expire / regenerate keys
System settings — General + Models dual tabs, hot-reload on save
Usage stats — Aggregate overview + per-request logs (with TTFT)
Cache management — Image / video stats, preview / download / batch cleanup
Playground — Chat / Image / Video generation online, multi-turn conversation with Markdown rendering
Supported Models
Chat Models
Model
Description
grok-3
Grok 3 Standard
grok-3-mini
Grok 3 Lite
grok-3-thinking
Grok 3 Chain-of-Thought
grok-4
Grok 4 Standard
grok-4-heavy
Grok 4 Enhanced
grok-4-mini
Grok 4 Lite
grok-4-thinking
Grok 4 Chain-of-Thought
grok-4.1-expert
Grok 4.1 Expert
grok-4.1-fast
Grok 4.1 Fast
grok-4.1-mini
Grok 4.1 Lite
grok-4.1-thinking
Grok 4.1 Chain-of-Thought
grok-4.20-beta
Grok 4.20 Beta
Media Models
Model
Description
grok-imagine-1.0
Image generation
grok-imagine-1.0-fast
Fast image generation
grok-imagine-1.0-edit
Image editing (supports reference images)
grok-imagine-1.0-video
Video generation
Models can be dynamically added/removed via the admin panel without restarting.
Quick Start
30-Second Setup
# 1. Download & start
./grokforge -config config.toml
# 2. Open admin panel and add your Grok Token
# http://localhost:8080
# 3. Test
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4",
"messages": [{"role": "user", "content": "Hello!"}],
"stream": true
}'
Build from Source
Prerequisites : Go 1.24+, Node.js 18+
git clone https://github.com/crmmc/grokforge.git
cd grokforge
# Copy config template
cp config.defaults.toml config.toml
# One-command build (frontend + backend)
make build
# Run
./bin/grokforge
The build output is a single binary with the frontend embedded via go:embed.
Configuration
GrokForge uses TOML configuration. See config.defaults.toml for the full template.
Minimal Config
[app]
app_key = "your-admin-password" # Admin password (REQUIRED: empty value rejects all admin requests)
port = 8080 # Server port
[proxy]
base_proxy_url = "" # Optional: proxy URL
After startup, add Grok Tokens in the admin panel. All other settings can be modified online.
Config Priority
Admin panel (DB) > config.toml > Built-in defaults
Admin panel changes take effect immediately without restart.
Core Settings
Application [app]
Key
Default
Description
app_key
""
Admin password (empty rejects all admin requests)
loginKey
""
Static login key for /v1 access (empty uses API Key database)
port
8080
Server port
host
"0.0.0.0"
Listen address
db_driver
"sqlite"
Database driver: sqlite / postgres
db_path
"data/grokforge.db"
SQLite file path
db_dsn
""
PostgreSQL connection string
log_level
"info"
Log level: debug/info/warn/error
log_json
false
JSON format logs
request_timeout
60
Default timeout for non-LLM routes (seconds)
temporary
true
Temporary conversation mode
thinking
true
Enable chain-of-thought by default
stream
true
Streaming response by default
filter_tags
[...]
Special tags to filter
Proxy [proxy]
Key
Default
Description
base_proxy_url
""
Upstream proxy (HTTP/HTTPS/SOCKS5)
asset_proxy_url
""
Asset proxy (image downloads, etc.)
cf_clearance
""
Cloudflare clearance cookie
browser
"chrome_146"
TLS fingerprint browser profile
enabled
false
Enable CF auto-refresh
flaresolverr_url
""
FlareSolverr service URL
refresh_interval
3600
CF refresh interval (seconds)
Retry Policy [retry]
Key
Default
Description
max_tokens
5
Maximum tokens to try
per_token_retries
2
Maximum retries per token before switching
reset_session_status_codes
[403]
Status codes that trigger session reset
retry_backoff_base
0.5
Backoff base delay (seconds)
retry_backoff_factor
2.0
Backoff multiplier
retry_backoff_max
20.0
Maximum single delay (seconds)
retry_budget
60.0
Total retry budget (seconds)
Token Management [token]
Key
Default
Description
fail_threshold
5
Consecutive failure threshold (marks expired)
usage_flush_interval_sec
30
Interval for flushing usage stats to DB
cool_check_interval_sec
30
Interval for checking cooldown recovery
Architecture
┌─────────────────────────────────────────────────┐
│ Client │
│ (ChatGPT Next Web / LobeChat / curl / ...) │
└─────────────────────┬───────────────────────────┘
│ OpenAI API
▼
┌─────────────────────────────────────────────────┐
│ GrokForge │
│ │
│ ┌───────────┐ ┌───────────┐ ┌────────────┐ │
│ │ httpapi │ │ Admin │ │ Static │ │
│ │ (OpenAI) │ │ API │ │ Frontend │ │
│ └─────┬─────┘ └─────┬─────┘ └────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────────────────────────────┐ │
│ │ flow (orchestration) │ │
│ │ chat / image / video / model routing │ │
│ └──────┬──────────┬──────────┬────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────┐ ┌─────────┐ ┌──────────┐ │
│ │ token │ │ xai │ │ store │ │
│ │ (pool) │ │(upstream)│ │(persist) │ │
│ └──────────┘ └─────────┘ └──────────┘ │
│ │ │
└────────────────────┼────────────────────────────┘
│
▼
┌─────────────┐
│ grok.com │
│ (SSE / WS) │
└─────────────┘
Three-tier architecture: httpapi (protocol translation) → flow (business orchestration) → xai / token / store (infrastructure)
Unidirectional dependencies, no circular references.
Request Flow
sequenceDiagram
participant C as Client
participant H as httpapi
participant F as flow
participant T as token
participant X as xai
participant G as grok.com
C->>H: POST /v1/chat/completions
H->>H: Auth check + param parsing
H->>F: Route to chat/image/video flow
F->>T: Request available Token (dual-pool + algorithm selection)
T-->>F: Return Token
F->>X: Build upstream request
X->>G: SSE / WebSocket request
G-->>X: Streaming response
X-->>F: Parse + transform
F-->>H: OpenAI format output
H-->>C: SSE stream / JSON response
Note over F,T: Auto retry on failure<br/>Switch Token + Session reset
Admin Panel
Admin panel URL: http://your-host:8080
The admin panel includes:
Dashboard — System status at a glance: Token count, API Key count, call volume, quota progress, trend charts
Token Management — Batch import / enable / disable / delete, status filtering, quota editing, priority settings, manual refresh
API Key — Create and manage API keys, model whitelist, daily limit, rate limit
Settings — Global config online editing, changes take effect immediately
Usage Stats — Aggregate overview + per-request logs (including TTFT, token consumption metrics)
Cache — Image / video cache browsing, preview, download, cleanup
Playground — Chat / Image / Video generation online, multi-turn conversation with Markdown rendering
API Examples
Chat Completion (Streaming)
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4",
"messages": [{"role": "user", "content": "Explain quantum computing in one sentence"}],
"stream": true
}'
Chain-of-Thought Model
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4-thinking",
"messages": [{"role": "user", "content": "Prove that √2 is irrational"}],
"reasoning_effort": "high"
}'
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4",
"messages": [{"role": "user", "content": "What is the weather in Beijing today?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}]
}'
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-4",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image"},
{"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}
]
}]
}'
Image Generation
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-1.0",
"messages": [{"role": "user", "content": "A shiba inu in a spacesuit walking on the moon"}]
}'
Video Generation
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-1.0-video",
"messages": [{"role": "user", "content": "A cat dancing on a piano"}]
}'
Client Integration
GrokForge is compatible with all OpenAI API clients — just point the API URL to GrokForge:
Client
Configuration
ChatGPT Next Web
Settings → API URL = http://your-host:8080
LobeChat
Settings → OpenAI → API URL = http://your-host:8080/v1
Open WebUI
Admin → Connections → OpenAI API = http://your-host:8080/v1
Cursor
Settings → Models → OpenAI Base URL = http://your-host:8080/v1
Any OpenAI SDK
base_url="http://your-host:8080/v1"
FAQ
How to get a Grok Token?
Log in to grok.com
Open browser DevTools (F12)
Find the sso or sso-rw cookie value in Application → Cookies
Import it in the admin panel
What's the difference between Basic and Super pools?
Basic pool (ssoBasic) : Free-tier Grok account tokens, standard models (no heavy/expert-exclusive models)
Super pool (ssoSuper) : Paid SuperGrok account tokens, all models including grok-4-heavy and other premium models
Models are configured per pool with format model_name#cost (e.g. grok-4-thinking#4, cost defaults to 1)
GrokForge automatically selects tokens from the matching pool based on the requested model
When the preferred pool has no available tokens, it falls back to the other pool
What to do about 403 errors?
Usually triggered by Cloudflare protection. Solutions:
Configure proxy : Set base_proxy_url with a clean IP
FlareSolverr : Configure flaresolverr_url, GrokForge auto-refreshes CF cookies
Manual update : Update cf_clearance cookie in the admin panel
How long until token quotas recover?
Depends on the recovery mode:
auto mode (default): Auto-replenish at configured intervals (default 120 minutes)
upstream mode : Sync real quotas from Grok's rate-limits API
Tokens enter cooling status when quotas are exhausted and automatically switch back to active after recovery.
How to share with multiple users?
Create API Keys in the admin panel, assign one per user
Set Model Whitelist to restrict available models
Set Daily Limit to control daily usage per user
Set Rate Limit to prevent burst requests
Which databases are supported?
SQLite (default): Zero config, data stored in data/grokforge.db
PostgreSQL : Recommended for production, set db_driver = "postgres" and db_dsn
Both databases have identical functionality with auto-migration on startup.
Tech Stack
Layer
Technology
Backend
Go 1.24 · chi · GORM · slog
Frontend
Next.js · shadcn/ui · Tailwind CSS · Recharts
Storage
SQLite (default) · PostgreSQL (optional)
Build
Make · go:embed (frontend embedded in binary)
Project Structure
grokforge/
├── cmd/grokforge/ # Entry point
├── internal/
│ ├── httpapi/ # HTTP layer (OpenAI compat + Admin API)
│ │ └── openai/ # OpenAI protocol implementation
│ ├── flow/ # Business orchestration (chat / image / video)
│ ├── token/ # Token pool management (routing / selection / quota / refresh)
│ ├── xai/ # Upstream communication (SSE / WebSocket)
│ ├── store/ # Persistence (GORM + migrations)
│ ├── config/ # Config management (TOML + DB override + hot-reload)
│ ├── cfrefresh/ # Cloudflare defense (FlareSolverr integration)
│ ├── cache/ # Cache management (image / video local cache)
│ └── logging/ # Log management (slog + file rotation)
├── web/ # Next.js frontend
│ └── src/app/ # Page routes
├── config.defaults.toml # Config template
└── Makefile # Build script
Acknowledgements
grok2api — Original Python project that proved the concept
chi — Lightweight HTTP router
GORM — Go ORM
shadcn/ui — UI component library
Star History
License
MIT
Disclaimer : This project is for educational and research purposes only. Users must comply with the terms of service of relevant platforms. Any consequences arising from the use of this project are the sole responsibility of the user.