fix: preserve base URL path prefix in record proxy#57
Open
iskhakovt wants to merge 1 commit intoCopilotKit:mainfrom
Open
fix: preserve base URL path prefix in record proxy#57iskhakovt wants to merge 1 commit intoCopilotKit:mainfrom
iskhakovt wants to merge 1 commit intoCopilotKit:mainfrom
Conversation
The URL constructor drops the base path when the pathname is absolute:
new URL("/v1/chat/completions", "https://openrouter.ai/api") resolves to
https://openrouter.ai/v1/chat/completions — losing /api.
Extract resolveUpstreamUrl() that normalizes inputs for RFC 3986 relative
resolution (trailing slash on base, strip leading slash from pathname).
Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Problem
The record proxy loses the base URL path prefix when constructing upstream URLs.
new URL("/v1/chat/completions", "https://openrouter.ai/api")resolves tohttps://openrouter.ai/v1/chat/completions— the/apiprefix is dropped.This is standard
URLconstructor behavior (absolute pathname replaces thebase path), but breaks providers like OpenRouter whose API lives at a
non-root path (
/api/v1/...).Providers with root-path APIs (OpenAI, Anthropic) are unaffected.
Fix
Extract URL joining into a
resolveUpstreamUrl()helper that normalizesinputs for RFC 3986 relative resolution:
This preserves any path prefix while keeping existing behavior for
root-path providers unchanged. Unit tests cover all combinations.
Examples
https://openrouter.ai/api/v1/chat/completionshttps://openrouter.ai/v1/chat/completionshttps://openrouter.ai/api/v1/chat/completionshttps://api.openai.com/v1/chat/completionshttps://api.openai.com/v1/chat/completionshttps://api.openai.com/v1/chat/completionshttps://api.anthropic.com/v1/messageshttps://api.anthropic.com/v1/messageshttps://api.anthropic.com/v1/messages