Skip to content

feat: add xai-proxy — OAuth PKCE sidecar for xAI SuperGrok#841

Merged
thepagent merged 6 commits into
mainfrom
feat/xai-proxy
May 18, 2026
Merged

feat: add xai-proxy — OAuth PKCE sidecar for xAI SuperGrok#841
thepagent merged 6 commits into
mainfrom
feat/xai-proxy

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented May 18, 2026

Summary

Adds xai-proxy, a lightweight Rust single-binary sidecar that:

  1. Authenticates with xAI via browser OAuth PKCE or device-code flow
  2. Proxies OpenAI-compatible requests to api.x.ai/v1 with the OAuth token injected
  3. Auto-refreshes tokens before expiry

This allows any OpenAI-compatible coding agent (OpenCode, Hermes, etc.) to use SuperGrok subscription quota instead of per-token API credits.

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│ Kubernetes Pod                                                      │
│                                                                     │
│  ┌──────────┐    ┌───────────────────────────────┐                  │
│  │  openab  │───►│  opencode acp                 │                  │
│  │          │◄───│  (model: xai/grok-4.3)        │                  │
│  └──────────┘    └───────────┬───────────────────┘                  │
│                              │ POST /v1/chat/completions            │
│                              │ (no auth header)                     │
│                              ▼                                      │
│                  ┌───────────────────────────────┐                  │
│                  │  xai-proxy  :9090             │                  │
│                  │                               │                  │
│                  │  1. Read OAuth token from PVC │                  │
│                  │  2. Inject Authorization hdr  │                  │
│                  │  3. Auto-refresh before expiry│                  │
│                  └───────────┬───────────────────┘                  │
│                              │                                      │
│  PVC (/home/agent)           │                                      │
│    └─ .openab/xai-proxy/     │                                      │
│         tokens.json          │                                      │
└──────────────────────────────┼──────────────────────────────────────┘
                               │ POST https://api.x.ai/v1/chat/completions
                               │ Authorization: Bearer <oauth_token>
                               ▼
                  ┌───────────────────────────────┐
                  │  api.x.ai/v1                  │
                  │  (SuperGrok subscription)     │
                  └───────────────────────────────┘

Usage

# Login (one-time)
xai-proxy login          # browser OAuth PKCE
xai-proxy login-device   # headless/K8s/ECS (device-code flow)

# Start proxy
xai-proxy serve --port 9090

# Custom token path (for K8s PVC persistence)
XAI_PROXY_TOKEN_PATH=/home/agent/.openab/xai-proxy/tokens.json xai-proxy serve

What was tested

  • cargo build --release passes on Rust 1.86+
  • OAuth device-code flow tested end-to-end
  • Deployed as sidecar on OrbStack K8s with opencode acp backend — confirmed Grok 4.3 responses via SuperGrok

Notes

  • Client ID is Grok CLI's public OAuth client (same as Hermes Agent, officially supported by xAI)
  • Scope: openid profile email offline_access grok-cli:access api:access
  • Token stored at ~/.xai-proxy/tokens.json (chmod 600) or custom path via XAI_PROXY_TOKEN_PATH
  • Requires rustls crypto provider (ring) — installed automatically at startup

Thread: 1505301662309552260

Lightweight Rust binary that authenticates with xAI via browser OAuth
(PKCE, borrowing Grok CLI's public client ID) and proxies
OpenAI-compatible requests to api.x.ai/v1 with the subscription token
injected.

Allows any OpenAI-compatible coding agent (Claude Code, OpenCode,
Codex CLI, etc.) to use SuperGrok subscription quota instead of
per-token API credits.
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner May 18, 2026 01:39
@github-actions github-actions Bot added pending-screening PR awaiting automated screening closing-soon PR missing Discord Discussion URL — will auto-close in 3 days labels May 18, 2026
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

超渡法師 and others added 5 commits May 18, 2026 01:59
Adds `login-device` subcommand that uses RFC 8628 device authorization
grant. Works in K8s exec, ECS exec, SSH — no browser or port-forward needed.

Usage:
  xai-proxy login-device
  # prints verification URL + user code
  # poll until user approves on any device
…PATH env var

- Add rustls as direct dep and call install_default() in main() to fix
  'Could not automatically determine CryptoProvider' panic on serve
- Support XAI_PROXY_TOKEN_PATH env var for custom token file location
  (useful for K8s PVC persistence at e.g. /home/agent/.openab/xai-proxy/tokens.json)
- Add Dockerfile for container builds
@thepagent thepagent merged commit 26b10e0 into main May 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days pending-screening PR awaiting automated screening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants