feat(openrouter-execution): add OpenRouter execution layer with BYOK and tier-based routing (APR-206)#58
Open
JacobSampson wants to merge 2 commits into
Open
feat(openrouter-execution): add OpenRouter execution layer with BYOK and tier-based routing (APR-206)#58JacobSampson wants to merge 2 commits into
JacobSampson wants to merge 2 commits into
Conversation
…and tier-based routing (APR-206) Implements @aprovan/openrouter-execution — the execution layer that sits between the model selection engine (APR-205) and the OpenRouter API. - Tier router maps (complexity 1-5, cost_quality_tradeoff 0-10) to FREE / BUDGET / MID_TIER / FRONTIER model tiers - Model catalog defines ordered fallback lists per tier using OpenRouter model IDs; BYOK subscription keys registered in OpenRouter are used automatically - OpenRouterClient wraps the /chat/completions endpoint with provider preferences, per-request budget caps (max_price), and retryable error handling - execute() tries each model in the tier in order, retrying on 429/5xx before falling back to the next model; reports fallback usage in the result - 21 unit tests covering tier routing and executor behavior (fetch is mocked) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…onfig - Add eslint.config.mjs (ESLint 9 flat config extending @aprovan/eslint-config/base) - Fix lint script to use ESLint 9 glob pattern - Fix import order in executor.ts (alphabetical per import/order rule) - Fix tsconfig to extend @aprovan/tsconfig/node.json (not /package.json) - Add lib: ["ES2022", "DOM"] for fetch/AbortController types - Add @types/node devDependency for process.env access - Add return type to test helper function Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@aprovan/openrouter-executionpackage — the execution layer between the model selection engine (APR-205) and the OpenRouter APIresolveTier(complexity, costQualityTradeoff)maps the two inputs from the model selection engine to a model tier (FREE → BUDGET → MID_TIER → FRONTIER)execute(request, config?)calls OpenRouter with BYOK-first provider preferences, automatic fallback across models in a tier, per-request budget caps, and retry on 429/5xx errors:free-suffixed model IDs via OpenRouter's free tier; BYOK subscription keys registered in the OpenRouter account are used automatically at no markupArchitecture
src/types.tssrc/model-catalog.tssrc/tier-router.tssrc/openrouter-client.ts/chat/completionswith retryable error classificationsrc/executor.tsexecute()— orchestrates tier resolution, model selection, retries, and fallbackRequired Environment Variable
OPENROUTER_API_KEYOPENROUTER_MAX_BUDGET_USD0.5OPENROUTER_APP_NAMEAprovanLabsX-Titleheader for OpenRouter analyticsTest Plan
pnpm --filter @aprovan/openrouter-execution test— 21 tests across 2 files, all greenpnpm --filter @aprovan/openrouter-execution typecheck— zero type errorspnpm --filter @aprovan/openrouter-execution lint— zero lint errorspnpm --filter @aprovan/openrouter-execution build— ESM + DTS output cleanAcceptance criteria coverage:
OpenRouterClient+execute()providersfield in catalog +provider.orderin each requestcost_quality_tradeoffmapping:resolveTier()— 13 unit testsexecute()withallow_fallbacks: trueModelTier.FREEcatalog + tier routingCloses #APR-206
🤖 Generated with Claude Code