Self-hosted service
chenyme/grok2api avatar
chenyme/grok2api

Grok2API: A Multi-Account Gateway That Turns Grok Logins into OpenAI and Anthropic Endpoints

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

7,654 stars2,297 forksGoMIT

At a glance

What is it?
Grok2API is a Go gateway with a React admin console that pools Grok Build, Grok Web, and Grok Console accounts and exposes unified OpenAI- and Anthropic-compatible APIs. It targets developers who need to route clients like Codex and Claude Code through multiple Grok accounts, but its complexity and upstream dependence demand careful evaluation.
Who is it for?
Adopt Grok2API if you operate multiple Grok accounts and need a single gateway to expose OpenAI- and Anthropic-compatible endpoints to clients like Codex and Claude Code. Skip it if you rely on official API terms or need minimal operational overhead.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 14, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What Grok2API Actually Solves

Grok2API addresses a specific pain: developers who want to use Grok models through standard OpenAI or Anthropic SDKs, but who do not have official API access or who need to spread load across multiple Grok accounts. The README describes it as a multi-account API gateway for Grok Build, Grok Web, and Grok Console. It maintains separate account pools for each provider, each with its own credentials, quota, health, cooldown, concurrency, and model capabilities. The gateway then exposes unified APIs: Responses, Chat Completions, Anthropic Messages, Images, and asynchronous Videos. The intended clients are Codex, Claude Code, OpenAI-compatible SDKs, and Anthropic-compatible SDKs. This is not a general-purpose proxy. It is specifically built for people who have Grok subscriptions or console access and want to turn those into developer-facing endpoints. The project is written in Go with a React admin console, and it is MIT licensed. The README includes a prominent note that the project is for technical research and learning only, and that users must comply with Grok's official terms of use and local laws. That note is a signal: the gateway works by leveraging account-level access, not an official paid API.

How the Gateway Routes Requests Across Account Pools

The architecture separates access, core, and provider domains. API clients and the React admin sit in the access domain. The core domain contains management services for accounts, models, keys, and settings, plus an account sync component that refreshes credentials, quota, and models. The provider registry is the routing hub. Each provider keeps independent account state and uses an isolated egress scope. Usage, audits, and client billing are finalized only after the request completes. That means the gateway can track which account served which request, and it can apply quota and concurrency guards per account. Routing features include model discovery, provider pinning, sticky sessions, quota and concurrency guards, and bounded failover. Sticky sessions matter for conversation continuity: if a client sends a multi-turn conversation, the gateway can pin it to the same account. Bounded failover means that when one account fails, the gateway can try another, but only within a single route. The README notes that when one public model ID aggregates multiple routes, the gateway may select another schedule. That is a subtle but important detail: a single model name can map to multiple underlying account routes, and the gateway decides which one to use. This is not a simple round-robin proxy. It is a stateful router that tracks account health and quota.

Provider Differences: Build, Web, and Console Are Not the Same

The three providers have different authentication and capabilities, and that affects what you can expect. Grok Build uses OAuth or Device OAuth, and its models are discovered per account. It supports Responses, Chat, Messages, compact, stored responses, and paid-account video. Grok Web uses SSO, has built-in models filtered by tier, and supports Responses, Chat, Messages, stored responses, images, image editing, and video. Grok Console also uses SSO, has built-in models, and adds stateless Responses, Chat, Messages, images, image editing, video, TTS, STT, and Realtime. The key word for Console is stateless. That means Console does not maintain conversation state across requests, which is a limitation if you need multi-turn context. Build and Web support stored responses, which likely means the gateway can retrieve previous responses. The README also mentions prompt-cache affinity under sessions, which suggests the gateway tries to keep requests on the same account to reuse caches. For a developer, this means you cannot assume all three providers behave identically. A model that works on Build may not exist on Web, and Console's stateless nature may break certain clients. The gateway's admin console lets you manage these differences, but the operator must understand them.

Getting It Running: Build, Container, and Configuration

The repository contains a backend written in Go and a frontend written in React, as indicated by the go.mod and package.json files. There is also a container image published on GitHub Container Registry (ghcr.io/chenyme/grok2api). The README does not include explicit installation commands in the cleaned excerpt, but the presence of a container image and a frontend build suggests two paths: run the prebuilt container, or build from source. For the container, you would pull the image and run it with appropriate environment variables, though the specific variables are not listed in the material. For building from source, you would need Go for the backend and Node.js for the frontend, then build the frontend and serve it via the backend. The admin console is where you manage accounts, models, keys, and settings. Account sync refreshes credentials and quota, so you likely need to provide Grok account credentials or OAuth tokens. The README mentions bulk import and export of accounts, which is useful for operators with many accounts. The gateway supports HTTP, SOCKS, and various tunnels (Trojan, VLESS, Shadowsocks, VMess) for egress, plus proxy pools and FlareSolverr. That means you can route Grok traffic through different network paths, which is relevant if you need to avoid IP-based rate limits. The configuration is not trivial, but the admin UI is designed to handle it.

Where It Can Break: Stateless Console, Failover, and Upstream Terms

The most obvious limitation is that Grok Console is stateless, so any client that relies on conversation history will not work correctly with that provider. The README does not explain how the gateway handles that, whether it injects history into each request or simply fails. Another limitation is the bounded failover. When one account fails, the gateway may try another, but only within the same route. If all accounts in a route are exhausted, the request fails. The README also mentions that when a model ID aggregates multiple routes, the gateway may select another schedule, which introduces non-determinism. For a developer, that means the same request could hit different accounts on different attempts, and if those accounts have different quotas or capabilities, the response could vary. The bigger risk is upstream: Grok2API relies on undocumented or semi-official endpoints for Grok Build, Web, and Console. Those endpoints can change without notice, and Grok's terms of use may prohibit this kind of access. The README itself warns users to comply with terms and local laws, and it disclaims responsibility. That is not a technical bug, but it is a real operational risk. If Grok changes authentication or rate limits, the gateway may stop working until a new release appears. The project has recent releases (v3.1.5 in August 2026), which suggests active maintenance, but that does not guarantee stability.

Alternatives: Official APIs and Other Gateways

The direct alternative is to use Grok's official API, if one exists. That gives you a stable contract, no account management, and no terms-of-service risk. The trade-off is cost and availability: official APIs may not offer the same models or may be more expensive than what you get from a Grok subscription. Another alternative is to use a commercial API relay that already supports Grok, such as the sponsors mentioned in the README (APIMart, PackyCode, Right Code, FennoAI, Qiniu Cloud AI). These services provide OpenAI- or Anthropic-compatible endpoints for multiple models, including Grok, and they handle the upstream integration for you. The difference is that they are closed, hosted services. You do not control the accounts or the egress. Grok2API gives you self-hosting and account-level control, but you take on the maintenance and the risk. There are also other open-source gateways like LiteLLM or one-api that support multiple providers, but they typically use official API keys, not account credentials. Grok2API's distinctive approach is that it works with Grok Build, Web, and Console accounts, which are not normally exposed as APIs. That is both its value and its liability.

Maintenance, Licensing, and Operational Cost

Grok2API is MIT licensed, which means you can use, modify, and redistribute it freely, including in commercial products, as long as you preserve the license notice. There is no copyleft obligation. The project has a container image and a frontend, so deployment is not trivial. You need to manage the Go backend, the React frontend, and the database or storage that the gateway uses for accounts, audits, and media libraries. The README mentions local archiving for media, so you need to provision disk space. The egress features (proxy pools, tunnels) add operational complexity: you need to configure and maintain those proxies if you use them. Account sync is a recurring process, and it can fail if Grok changes its authentication flow. That means you need to monitor the gateway for sync errors and quota exhaustion. The recent release cadence (three releases in August 2026) suggests the maintainer is actively fixing issues, but you should pin a version and test upgrades. There is no mention of a migration path between versions in the README, so you should assume breaking changes are possible. The admin console is a React app, so you need Node.js for development, but the container image likely bundles the built frontend.

Editorial conclusion

Adopt Grok2API if you operate multiple Grok accounts and need a single gateway to expose OpenAI- and Anthropic-compatible endpoints to clients like Codex and Claude Code. Skip it if you rely on official API terms or need minimal operational overhead. Before deploying, verify the current account sync behavior for Grok Console, test failover with your specific model IDs, and confirm that the egress tunnels (Trojan, VLESS, Shadowsocks, VMess) match your network policies. The project is MIT licensed and actively released, but it carries real risk: it depends on undocumented Grok endpoints that can change without notice.

Official sources

  1. Official README
  2. Project repository
  3. Release notes
Community notes

Community notes