Skip to content

fix: preserve base URL path prefix in record proxy#57

Open
iskhakovt wants to merge 1 commit intoCopilotKit:mainfrom
iskhakovt:fix/proxy-url-resolution
Open

fix: preserve base URL path prefix in record proxy#57
iskhakovt wants to merge 1 commit intoCopilotKit:mainfrom
iskhakovt:fix/proxy-url-resolution

Conversation

@iskhakovt
Copy link
Copy Markdown

Problem

The record proxy loses the base URL path prefix when constructing upstream URLs.

new URL("/v1/chat/completions", "https://openrouter.ai/api") resolves to
https://openrouter.ai/v1/chat/completions — the /api prefix is dropped.
This is standard URL constructor behavior (absolute pathname replaces the
base 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 normalizes
inputs for RFC 3986 relative resolution:

  • Ensure base URL has a trailing slash (marks it as a "directory")
  • Strip leading slash from pathname (makes it relative, not absolute)

This preserves any path prefix while keeping existing behavior for
root-path providers unchanged. Unit tests cover all combinations.

Examples

Base URL Pathname Before After
https://openrouter.ai/api /v1/chat/completions https://openrouter.ai/v1/chat/completions https://openrouter.ai/api/v1/chat/completions
https://api.openai.com /v1/chat/completions https://api.openai.com/v1/chat/completions https://api.openai.com/v1/chat/completions
https://api.anthropic.com /v1/messages https://api.anthropic.com/v1/messages https://api.anthropic.com/v1/messages

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>
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

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