Skip to content

Run grok via OpenRouter by borrowing codex's harness - #47

Merged
eirikb merged 1 commit into
mainfrom
feature/eirikb/grok-openrouter
Jul 2, 2026
Merged

eirikb merged 1 commit into
mainfrom
feature/eirikb/grok-openrouter

Conversation

@eirikb

@eirikb eirikb commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Grok's own CLI can't be repointed at OpenRouter, but its model (x-ai/grok-build-0.1) is on OpenRouter — so grok stops being native-only: its OpenRouter leg runs x-ai/grok-build-0.1 through codex's read-only exec harness. A signed-in-but-out-of-credits grok now falls back to OpenRouter and succeeds on the user's key instead of hard-failing on xAI's 403.

  • The "grok borrows codex" fact lives in one place — openrouter_runner() (grok→codex, else self); command()/reads_stdin()/capability checks all derive from it
  • codex's exec command factored into codex_exec_command(repo, or_model), shared by codex (both legs) and grok's OpenRouter leg
  • openrouter_reachable() (selection/forcing) requires the borrowed runner to be installable, so grok isn't planned onto a route that can't build; openrouter_capable() adds the run-time Vibe-home check
  • prewarm/update bootstrap the runner (codex for grok), gated on a key being present

Two /code-review + /postmortemthis passes (borrowed-harness dependency, prewarm, selection-gate consensus findings all fixed). Build + clippy clean; native-fail→OpenRouter fallback and forced-OpenRouter both verified live (x-ai/grok-build-0.1 returns real answers on the OpenRouter key).

Grok's own CLI can't be repointed at OpenRouter, but its model
(x-ai/grok-build-0.1) is on OpenRouter - so grok stops being native-only:
its OpenRouter leg runs through codex's read-only `exec` harness pointed at
that model. A signed-in-but-out-of-credits grok now falls back to OpenRouter
and succeeds on the user's key instead of hard-failing on xAI's 403.

The "grok borrows codex" fact lives in one place, `openrouter_runner()`
(grok -> codex, everyone else -> self); command(), reads_stdin(), and the
capability checks all derive the executing CLI from it. codex's exec command
is factored into `codex_exec_command(repo, or_model)`, shared by codex's own
two legs and grok's OpenRouter leg.

Because that leg spawns codex, not grok:
- openrouter_reachable() (used for selection/forcing) requires the borrowed
  runner to be installable, so grok isn't planned onto a route that can't
  build; openrouter_capable() adds the run-time Vibe-home check on top
- prewarm/update bootstrap the runner too (codex for grok), but only when a
  key makes the fallback reachable
@eirikb
eirikb merged commit 5f9a173 into main Jul 2, 2026
1 check passed
@eirikb
eirikb deleted the feature/eirikb/grok-openrouter branch July 2, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant