{"record":{"id":"41ced66abaa6d06e","repo":"upstash/context7","slug":"invalid-url","errorCode":"invalid_url","errorMessage":"Context7 client was passed an invalid URL. You should pass a URL starting with http:// or https://. Received: \"${url}\".","messagePattern":"Context7 client was passed an invalid URL\\. You should pass a URL starting with http:// or https://\\. Received: \"(.+?)\"\\.","errorType":"error_code","errorClass":"Context7UrlError","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/http/index.ts","lineNumber":57,"sourceCode":"    timeout: number | false;\n    keepAlive: boolean;\n  };\n  public readonly retry: RetryPolicy;\n\n  private readonly fetch: Context7Fetch;\n  private readonly onResponse?: (metadata: Context7ResponseMetadata) => void;\n\n  public constructor(config: HttpClientConfig) {\n    this.options = {\n      cache: config.cache,\n      signal: config.signal,\n      timeout: config.timeout ?? DEFAULT_TIMEOUT,\n      keepAlive: config.keepAlive ?? true,\n    };\n    validateTimeout(this.options.timeout);\n\n    this.baseUrl = config.baseUrl.replace(/\\/$/, \"\");\n    if (!isHttpUrl(this.baseUrl)) throw new Context7UrlError(this.baseUrl);\n\n    this.headers = { \"Content-Type\": \"application/json\", ...config.headers };\n    if (!config.fetch && !globalThis.fetch) {\n      throw new TypeError(\"A fetch implementation is required\");\n    }\n    this.fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n    this.onResponse = config.onResponse;\n    this.retry = createRetryPolicy(config.retry);\n  }\n\n  public async request<TResult>(request: Context7Request): Promise<Context7Response<TResult>> {\n    const method = request.method ?? \"POST\";\n    const abortState = createAbortState(\n      [resolveSignal(this.options.signal), request.signal],\n      request.timeout ?? this.options.timeout\n    );\n    const init: RequestInit = {\n      cache: normalizeCache(request.cache ?? this.options.cache),","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/upstash/context7/blob/80e681a507c5287bc12e483367c40754e29461b9/packages/sdk/src/http/index.ts#L39-L75","documentation":"Context7UrlError (code \"invalid_url\") thrown in the client constructor when the baseUrl does not start with http:// or https://. The trailing slash is stripped first, then isHttpUrl validates the scheme.","triggerScenarios":"new Context7Client({ baseUrl: 'context7.com/api' }) or 'localhost:8080' or an empty string — any URL without an http:// or https:// scheme.","commonSituations":"Omitting the scheme because browsers auto-complete it, reading baseUrl from env/config without scheme, accidentally passing a path or relative URL, or typos like 'hhttps://'.","solutions":["Prefix the URL with https:// (or http:// for local dev): baseUrl: 'https://context7.com/api'.","Validate the value before constructing: new URL(u) and check protocol is http: or https:.","Fix the environment variable/config file so it contains the full absolute URL.","Normalize trailing slashes if desired; the constructor already strips them — only the scheme matters."],"exampleFix":"// before\nnew Context7Client({ baseUrl: process.env.CONTEXT7_URL }); // 'context7.com' -> invalid_url\n// after\nconst raw = process.env.CONTEXT7_URL;\nconst baseUrl = raw.startsWith('http') ? raw : `https://${raw}`;\nnew Context7Client({ baseUrl });","handlingStrategy":"validation","validationCode":"function assertHttpUrl(u: string): void {\n  const parsed = new URL(u);\n  if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n    throw new Error(`baseUrl must start with http:// or https://, got: ${u}`);\n  }\n}","typeGuard":"function isHttpUrl(u: string): boolean {\n  try {\n    const p = new URL(u);\n    return p.protocol === 'http:' || p.protocol === 'https:';\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  const client = new Context7Client({ baseUrl });\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'invalid_url') {\n    console.error(`Fix CONTEXT7_BASE_URL (needs scheme): ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Always include https:// in config files and env vars for base URLs.","Run assertHttpUrl at app startup, before client construction.","Add a config schema validation step (zod .url()) for environment-derived values."],"tags":["url","configuration","validation"],"backgroundTag":"invalid-url-format","analyzedSha":"80e681a507c5287bc12e483367c40754e29461b9","analyzedAt":"2026-09-08T05:18:41.043Z","contentChangedAt":"2026-09-08T05:18:41.043Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}