feat(openrouter): configurable base URL with OPENROUTER_BASE_URL env override#19
Open
cryptoxdog wants to merge 1 commit into
Open
feat(openrouter): configurable base URL with OPENROUTER_BASE_URL env override#19cryptoxdog wants to merge 1 commit into
cryptoxdog wants to merge 1 commit into
Conversation
…override The OpenRouter transport was constructed with a hardcoded baseURL 'https://openrouter.ai/api/v1', leaving no supported way to route through proxies, gateways, or OpenAI-compatible regional endpoints. - resolveOpenRouterBaseUrl(configured?, env): precedence explicit config > OPENROUTER_BASE_URL env var > default; trims, strips trailing slashes, validates absolute http(s) URL, throws typed InvalidBaseUrlError at construction time (fail-fast, not first request). - OpenRouterClient constructor gains a trailing optional baseUrl param; all existing call sites remain source-compatible. - RouterConfig.openrouterBaseUrl typed + zod-validated (url + http(s) scheme refine); router wires it through in index.ts. - README: 'Custom OpenRouter endpoint' section. - 12 new tests covering precedence matrix, normalization, invalid-value rejection, constructor integration, and schema validation.
|
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
Makes the OpenRouter base URL configurable instead of hardcoded, using the standard OpenAI-compatible pattern: explicit config takes precedence, then the
OPENROUTER_BASE_URLenvironment variable, then the built-in default. This unblocks routing through proxies, gateways, and regional endpoints without touching provider code.Verification:
tscbuild clean, ESLint clean, Vitest 17 files / 88 tests pass (12 new).Problem
src/providers/openrouter.tsconstructed its transport with a hardcodedbaseURL: 'https://openrouter.ai/api/v1'. During the Website-Bot go-live run this surfaced as a defect: any deployment that needs to reach OpenRouter through a proxy or an OpenAI-compatible gateway had no supported way to redirect traffic — the only options were forking the provider or monkey-patching the transport.Changes
src/providers/openrouter.tsDEFAULT_OPENROUTER_BASE_URLconstant andInvalidBaseUrlErrortyped error.resolveOpenRouterBaseUrl(configured?, env = process.env):OPENROUTER_BASE_URLenv var → default.http(s)URL; anything else throwsInvalidBaseUrlError(fail-fast at construction, not first request).OpenRouterClientconstructor acceptsbaseUrlas a new trailing optional parameter — fully backward compatible with all existing call sites.src/types.ts—RouterConfig.openrouterBaseUrl(optional, documented).src/schemas.ts—RouterConfigSchema.openrouterBaseUrl: Zodurl()plus anhttp(s)-scheme refine.src/index.ts— router wiresvalidated.openrouterBaseUrlthrough to the client; new symbols re-exported.README.md— new "Custom OpenRouter endpoint" section documenting both configuration paths and precedence.Tests (12 new,
tests/openrouter-base-url.test.ts)ftp://, missing scheme.openrouterBaseUrlinRouterConfig.How to verify