Skip to content

Quickstart for OpenRouter Users ​

OpenRouter gives you one API key across Anthropic, OpenAI, Google, DeepSeek, Qwen, Meta, Mistral, xAI, and more. Kompile treats OpenRouter as a first-class direct provider (openrouter, https://openrouter.ai/api/v1) with live catalog discovery, routed prompt caching, session affinity, structured outputs, and built-in key usage telemetry.

You don't need to memorize OpenRouter's org/model IDs or CLI flags. Run the interactive wizard once to save your key, search OpenRouter's live /models catalog, and save your defaults — after that, just run kompile chat:

bash
cd /path/to/your/repo
kompile auth login       # Interactive Auth Wizard → pick OpenRouter (or `/auth` inside chat)
kompile chat             # Launches SetupWizard on first run (or `kompile chat --setup` anytime)

1. Authenticate ​

OpenRouter supports both Kompile's managed credential store and the OPENROUTER_API_KEY environment variable fallback.

Run bare kompile auth login (or /auth inside chat) for the interactive wizard, or use direct commands for scripts and multiple named keys:

bash
# Option A: Direct masked prompt
kompile auth login openrouter

# Option B: Pipe from stdin or bind a named env var (CI / scripts)
printf '%s\n' "$OPENROUTER_API_KEY" | kompile auth login openrouter --stdin
kompile auth login openrouter --from-env OPENROUTER_API_KEY

# Option C: Ambient environment variable (no login required)
export OPENROUTER_API_KEY="sk-or-v1-..."

Store multiple keys (e.g., personal vs team budget) with --name:

bash
kompile auth login openrouter --name team --no-switch
kompile auth list

2. Start chatting ​

Once saved via kompile chat --setup, run kompile chat. Direct CLI commands for scripts or one-off overrides:

bash
cd /path/to/your/repo

# Interactive setup wizard — fetches live models from https://openrouter.ai/api/v1/models
kompile chat --setup

# Direct CLI overrides
kompile chat --provider openrouter --model anthropic/claude-sonnet-4-5
kompile chat --provider openrouter --model deepseek/deepseek-r1
kompile chat --provider openrouter --model google/gemini-2.5-pro

Inside a running session, switch models at any time with /model — Kompile queries OpenRouter's live /models endpoint and caches the last-known-good catalog in ~/.kompile/cache/model-catalogs.json as an offline/outage fallback.

Non-interactive / CI turns ​

bash
kompile chat --provider openrouter --model anthropic/claude-sonnet-4-5 \
  --prompt "Summarize recent changes and flag risky diffs" \
  --output-format stream-json

3. Prompt caching, usage & cost estimation ​

Kompile configures OpenRouter-specific transport features automatically:

  • Routed prompt caching & session affinity: Sends OpenRouter's session affinity header and retention hints (ProviderPromptCacheCapabilities: Activation.ROUTED, SessionAffinity.OPENROUTER_SESSION_HEADER, RetentionControl.OPENROUTER). Tune with --prompt-cache-retention long|short|none (defaults to long).
  • Live key telemetry (/usage): VendorUsageService queries https://openrouter.ai/api/v1/key with your bearer token to display live key usage and limits right inside /usage. (Account-level credit balances require a separate management key at https://openrouter.ai/settings/credits.)
  • Structured outputs: Supported directly (ProviderStructuredOutputCapabilities), which keeps Kompile's JSON tool calls and judge verdicts reliable.

4. How resolve_model works with OpenRouter ​

Before spawning a subagent, Kompile agents call resolve_model — a read-only lookup that never runs a model turn and never guesses credentials:

How your vendor of choice is resolved ​

  • When OpenRouter is your active chat provider, ModelRouting keeps every OpenRouter-hosted family on openrouter automatically.
  • When another provider is active (for example anthropic or openai), requesting a bare family ID routes to that family's first-party owner if configured, or refuses with AmbiguousModelRouteException if multiple non-owner hosts (like openrouter and github-copilot) are configured. Pass provider=openrouter explicitly (or copy taskArguments from resolve_model) to force OpenRouter.

WARNING

Never make top-tier models like Opus (*opus*) or Fable (*fable*) — or Astra (*astra*) / Neon (*neon*) — a subagent unless you are sure of the cost. OpenRouter makes every frontier model one model-ID away, so explicit /subagent-config bans and a dollar cap (cost-budget) are essential before launching parallel multi_task or quorum_task fan-outs.

Subagents never silently borrow the parent chat's Kompile-managed credential — pin your OpenRouter credential name (kompile auth list openrouter) in /subagent-config route:

text
/subagent-config ban *opus*
/subagent-config ban *fable*
/subagent-config ban *astra*
/subagent-config ban *neon*
/subagent-config route openrouter/deepseek/deepseek-v3.1 credential=default
/subagent-config role-route reviewer openrouter/anthropic/claude-sonnet-4-5 credential=default
/subagent-config per-session 4
/subagent-config cost-budget 2.00
/subagent-config preload-tools read,grep,glob,edit,write,bash

Power pattern: Multi-model teams & independent judges on one key ​

Because OpenRouter exposes every major model family behind a single credential, it pairs naturally with Kompile's multi-model harness:

  1. Frontier lead + economical subagents: Run a frontier model for your main chat (e.g., anthropic/claude-sonnet-4-5 or openai/gpt-6.2-sol) and route bulk read/search/test workers through openrouter to fast, low-cost models.
  2. Independent cross-family judge: Pair your primary coding model with a different family as The Judge so reviews aren't graded by the same model that wrote the code.

Configure multi-model teams interactively via /workflow — see Interactive Workflows.

Resuming & importing sessions onto OpenRouter ​

Hit a rate limit on a Claude Code, Codex, or Antigravity subscription mid-task? Import that session into Kompile and resume it seamlessly on any OpenRouter model — CrossAgentResumeCompactor automatically compacts older turns to fit your target model's context window:

bash
# Resume Kompile Standard Chat sessions
kompile chat --continue                                # Resume last session in this project
kompile resume                                         # Interactive multi-tab session browser
kompile resume-all                                     # Restore all recently active terminal windows

# Import external CLI/IDE history and continue via OpenRouter
kompile session import --source=claude-code            # Or codex, agy, opencode, cursor, ...
kompile chat --resume <id> --provider openrouter --model anthropic/claude-sonnet-4-5

See Import & Resume for all 11 adapters, /resume, and subagent_resume.

Common gotchas ​

  • Use OpenRouter's vendor/model IDs: OpenRouter model IDs are slash-qualified (e.g., anthropic/claude-sonnet-4-5, not bare claude-sonnet-4-5). Use kompile chat --setup or /model to pick from the live catalog without guessing.
  • Custom gateway URLs: Point at an internal OpenRouter proxy with --base-url https://your-proxy.example/api/v1.

Next steps ​

Released under the Apache-2.0 License.