musistudio/claude-code-router · error · Error
Provider Base URL is invalid.
Error message
Provider Base URL is invalid.
What it means
After protocol validation, validateProviderBaseUrl requires a non-empty hostname. A URL like "https:///v1" or "https://:8080" parses but has no hostname, so the base URL points nowhere and is rejected as invalid.
Source
Thrown at packages/core/src/contracts/deep-link.ts:474
}
function boundedString(value: string | undefined, maxLength: number, label: string): string | undefined {
if (!value) {
return undefined;
}
if (value.length > maxLength) {
throw new Error(`${label} is too long.`);
}
return value;
}
function validateProviderBaseUrl(value: string): void {
const url = new URL(providerUrlWithDefaultScheme(value));
if (!["http:", "https:"].includes(url.protocol)) {
throw new Error("Provider Base URL must use http or https.");
}
if (!url.hostname) {
throw new Error("Provider Base URL is invalid.");
}
}
function validateManifestUrl(value: string): void {
const url = new URL(value);
if (url.protocol !== "https:") {
throw new Error("Provider manifest URL must use https.");
}
if (url.username || url.password) {
throw new Error("Provider manifest URL cannot include credentials.");
}
if (!url.hostname) {
throw new Error("Provider manifest URL is invalid.");
}
}
function normalizeProviderProtocol(value: string | undefined): GatewayProviderProtocol | undefined {
if (!value) {View on GitHub (pinned to 99f24806c6)
Solutions
- Include a real hostname: https://api.provider.com/v1
- If using env vars, ensure the host variable is set before building the URL
- Log the final composed base_url before parsing to catch empty hosts early
Example fix
// before
{"base_url":"https:///v1"}
// after
{"base_url":"https://api.acme.dev/v1"} Defensive patterns
Strategy: validation
Validate before calling
const u = new URL(baseUrl.includes("://") ? baseUrl : `https://${baseUrl}`); if (!u.hostname) return reject("empty host"); Type guard
const hasHostname = (v: string) => { try { return new URL(/^\w+:\/\/.test(v) ? v : `https://${v}`).hostname.length > 0; } catch { return false; } }; Try / catch
try { validateProviderBaseUrl(baseUrl); } catch (e) { if (e instanceof Error && e.message === "Provider Base URL is invalid.") return promptForUrl(); throw e; } Prevention
- Fallback-interpolate hosts: `https://${host || defaultHost}/v1`
- Log the final composed URL before parsing
When it happens
Trigger: Passing base_url="https:///path" (empty host), a URL consisting only of port/path, or one whose host was lost during templating.
Common situations: Template interpolation producing an empty host (https://${HOST}/v1 with HOST unset); copy-paste dropping the host; URLs built from config env vars that are undefined.
Related errors
- Provider Base URL must use http or https.
- Provider manifest URL is invalid.
- New API provider base URL is missing.
- The CCR artifact endpoint returned a non-media content type.
- The CCR media artifact exceeds the inline preview size limit
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/42dba1fe0e9661ca.
Report an issue: GitHub.