Grok2API Egress Enhancements: a proxy recovery and quality guard patch set
Grok2API & CPA egress quality guard with proxy recovery, quarantine, migration, and operations UI
At a glance
- What is it?
- This repository does not ship a gateway. It ships patches, a Python sidecar and a CPA plugin that add fast proxy recovery and heuristic egress quality control to chenyme/grok2api, and it assumes you already run that upstream project.
- Who is it for?
- Adopt it if you already run chenyme/grok2api with multiple residential egress nodes and you are willing to carry a fork or a patch stack. Skip it for a single account behind one stable static proxy, where the README itself says the plugin can be left out.
- 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 7 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 November 25, 2026, and from our analysis. They are not legal advice.
Star history
- lij768423-svg/grok2api-egress-enhancements319 ★ · +4
| Repository | 2026-09-17 | 2026-11-25 |
|---|---|---|
| lij768423-svg/grok2api-egress-enhancements | 315 | 319 |
4 Stars in the last 69 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What problem Grok2API Egress Enhancements solves
An AI gateway that fans requests across many residential proxies has a failure mode that ordinary retry logic handles badly. A fixed egress node dies mid-request, and the gateway either keeps binding new requests to a dead node or cools down an entire rotating pool because one exit failed. The README describes the second case explicitly: the official proxy pool mode continues to treat each new tunnel as a new tunnel, so a single rotating exit failure does not cool down the whole pool. The fixed-node case is what this repository patches.
The second problem is subtler. A streaming thinking model can return a plausible-looking answer without ever emitting reasoning content. The README calls this degraded output and treats it as a quality signal rather than a transport error. The repository is for operators who run grok2api at some scale, care about per-node egress health, and are willing to run a fork or a patch stack rather than a released binary. It is not a general-purpose gateway and does not duplicate upstream source.
Fixed proxy recovery: cooldown, single probe, bounded wait
The recovery path is documented as a sequence. When a connection refusal, reset, timeout or EOF happens before the request is submitted, the fixed node enters cooldown and an asynchronous recheck starts immediately. Concurrent failures on the same node start only one probe, so a burst of bad requests does not fan out into a burst of probes. Subsequent requests bound to that node wait up to five seconds; if the recheck reports healthy, the gateway rereads persisted state and continues, and if not, the cooldown stays.
Two boundaries are stated in the README and they matter more than the happy path. A cancelled request stops waiting immediately but does not cancel the shared probe, so one user aborting does not blind the node for everyone else. And a generation request that has already been submitted is never replayed, which means recovery helps the next request, not the one that just failed. Authentication, quota and rate-limit errors are excluded from this path; they are not treated as proxy faults. That distinction is the difference between a recovery mechanism and a retry storm.
The Quality Guard sidecar and its heuristic thresholds
The sidecar is a separate Python process at sidecar/quality_guard.py, paired with an admin page at /quality-guard. It audits throughput passively using the same formula as the grok2api panel: output tokens divided by total duration minus first-token latency, with reasoning tokens counted inside output tokens. A hard threshold isolates a node immediately. A soft threshold triggers an active recheck with a fixed prompt, and only repeated hits lead to isolation.
The README is unusually candid about the limits of this approach. It states that quality guarding is a heuristic circuit breaker, not a model capability assessment, and that intermediate buffering, existing files, long constants or cached content can produce abnormally high instantaneous token rates. The hard threshold policy is described as aggressive and adjustable upward per link. That is a real operational cost: a wrong isolation decision removes capacity, and the automatic recovery path only restores a node after a real model quality check on the new IP. Node-level IP rotation is supported through a trusted webhook and a 1024Proxy sticky session rotator. Account scheduling failures are handled separately from proxy faults, so an empty account pool delays the recheck instead of burning traffic on an IP change.
Installing the patch stack on a clean grok2api checkout
The README gives a direct application path for a clean grok2api repository sitting on v3.1.4. You fetch tags, branch, and apply the six patches in order with git am. The order matters because each patch is a commit series applied on top of the previous one.
git fetch --tags origin
git checkout -b tui-hold-serde v3.1.4
git am --3way /path/to/grok2api-egress-enhancements/patches/0015-fix-quality-thinking-evidence.patch
git am --3way /path/to/grok2api-egress-enhancements/patches/0016-fix-responses-annotations.patch
git am --3way /path/to/grok2api-egress-enhancements/patches/0017-fix-hold-tui-tool-turns.patch
git am --3way /path/to/grok2api-egress-enhancements/patches/0018-fix-empty-completed-retry.patch
git am --3way /path/to/grok2api-egress-enhancements/patches/0019-fix-clear-account-cooldown.patch
git am --3way /path/to/grok2api-egress-enhancements/patches/0020-fix-responses-abort-failed-mod.patchAfter the last patch applies without conflict, the tree should match the fork described in the README, with missing-thinking interception enabled by default. The README warns that patches 0006 through 0014 must not be reapplied on v3.1.4. If your tree is still on the older v3.0.11, the legacy patch is patches/0001-feat-add-egress-recovery-and-quality-guard.patch instead. The sidecar starts alongside the stack; the README says docker compose up -d brings it up with the sidecar, and that quality-guard.env and bootstrap files should not be committed.
Missing-thinking interception and what counts as evidence
This is the part with the most specific rules, and the rules are where the design earns its keep. A streaming thinking request is held before any visible output is written. It is released only when real streaming thinking appears: a reasoning or summary delta, or an encrypted_content or Anthropic signature that reaches the ciphertext floor. The floor is max(minEncryptedBytes, reasoning_tokens times encryptedBytesPerReasoningToken), with defaults of 256 bytes and 4.
The README lists what does not count: a short gAAAA-cipher stub, an empty reasoning item, a Chat SSE stub, and usage.reasoning_tokens appearing alone. A barely-over-floor flush of visible output within one second also counts as a miss. If visible output reaches minOutputTokens (8 in the fork and in the recommended values) with no streaming thinking, the response is recorded as degraded and not sent to the user; the gateway switches accounts and retries, up to six attempts, then returns 503 quality_degraded. First miss puts the account in a 12-hour cooldown, and a second miss after cooldown disables it. Empty response.completed or [DONE] switches accounts immediately with upstream_stream_empty rather than waiting for idle. The README states that the official PR uses the same parameters but leaves requestRetry.enabled at false, while the fork enables interception by default. TUI compression still uses skipQualityHold, and the README explicitly says not to set holdTimeout back to 3 seconds.
Where this is the wrong tool, and what to use instead
If you run one account behind one stable static proxy, this stack is unnecessary. The README says so directly about the CPA plugin: single-account or stable static proxy setups can skip installing it. The same logic applies to the sidecar, whose whole purpose is isolating nodes inside a pool.
The patch layer also has a version coupling problem. The README states that the current baseline is official latest with 0015 through 0020 merged upstream, and that the live increment is the fake-encrypted thinking interception, with the runnable tree being the fork. That means the patch set is a moving target tied to a specific upstream tag. If you would rather not track that, the alternative is upstream chenyme/grok2api with requestRetry.enabled left at its default false, accepting that degraded responses reach users. The difference in approach is not quality versus no quality; it is whether you want interception on by default in your own tree, or the upstream default with the option available. The CPA plugin is a separate answer for a different deployment: it is a pure CPA native plugin that reads authentication files and Usage events through the CPA Host API, binds an account proxy_url stickily to an egress node, and does not depend on or connect to the Grok2API runtime at all.
Maintenance cost, licence and upgrade path
The repository is MIT licensed, and the README is clear that it does not copy upstream source, which keeps the licence question simple for the patch files themselves. The maintenance cost is not in the licence but in the version tracking. Two upgrade paths exist and they are not interchangeable. If you are on a clean v3.1.4, you apply 0015 through 0020. If you are on v3.0.11, you stay on the legacy 0001 patch. The README states that 0006 through 0014 should not be reapplied on v3.1.4, which implies a real risk of duplicated or conflicting changes if you guess. The last push to this repository was on 2026-08-27, and the most recent release listed is v1.1.0 from 2026-08-18, described as grok2api lab patches 0006 through 0009. Note the gap: the release notes describe a different patch range from the one the README tells you to apply on v3.1.4, so the release tags are not a reliable index of the current patch set. Check patches/ directly rather than trusting the release name.
Editorial conclusion
Adopt it if you already run chenyme/grok2api with multiple residential egress nodes and you are willing to carry a fork or a patch stack. Skip it for a single account behind one stable static proxy, where the README itself says the plugin can be left out. Before deploying, verify which upstream tag your tree is on, because the README states that 0006 to 0014 must not be reapplied on v3.1.4, and confirm whether your deployment needs the sidecar at all or only the patches.
Frequently asked questions
Does Grok2API Egress Enhancements replace chenyme/grok2api?
No. The README describes it as an unofficial enhancement distribution that provides patches and a sidecar for chenyme/grok2api, and states that the repository does not copy the full upstream source. You still run grok2api, either as the fork or with the patches applied.
Do I need the Quality Guard sidecar if I only run one proxy?
The README says single-account or stable static proxy scenarios can skip installing the CPA plugin, and the sidecar's purpose is isolating nodes within a pool. With one fixed node there is nothing to quarantine or migrate between.
Which patches should I apply to a clean grok2api v3.1.4 checkout?
The README gives the sequence 0015 through 0020, applied with git am --3way in order, and states that patches 0006 through 0014 must not be reapplied on v3.1.4. Only trees still on v3.0.11 should use the legacy 0001 patch.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/lij768423-svg-grok2api-egress-enhancements)Star history chart for your README
[](https://hysenlabs.com/projects/lij768423-svg-grok2api-egress-enhancements)Was this useful?