Only absolute URLs are supported

Hello, I encountered an issue while using the chromadb npm package. Upon investigating the problem, I found that the issue seems to be with the “@hey-api/client-fetch” package, which is not working as expected. It works fine on the client side, but not on the backend. Do you have any suggestions or insights regarding this issue?

import { createClient, createConfig } from '@hey-api/client-fetch'
import { fetch } from 'meteor/fetch'

  const configOptions = {
    baseUrl: 'https://chroma.recepozen.com',
    fetch: fetch,
  }

  const apiClient = createClient(createConfig(configOptions))

  apiClient
    .get({ url: '/api/v2/version' })
    .then((response) => console.log(response))
    .then((result) => console.log(result))
    .catch((error) => Logger.error({ err: error }, 'api error'))
[12-06-2025 10:51:01.241] ERROR: api error
    err: {
      "type": "TypeError",
      "message": "Only absolute URLs are supported",
      "stack":
          TypeError: Only absolute URLs are supported
              at getNodeRequestOptions (/Users/recepozen/.meteor/packages/fetch/.0.1.6.1jl6fak2dbx++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/node-fetch/lib/index.js:1327:9)
              at /Users/recepozen/.meteor/packages/fetch/.0.1.6.1jl6fak2dbx++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/node-fetch/lib/index.js:1454:19
              at new Promise (<anonymous>)
              at fetch (/Users/recepozen/.meteor/packages/fetch/.0.1.6.1jl6fak2dbx++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/node-fetch/lib/index.js:1451:9)
              at Package.fetch.fetch (packages/montiapm:agent/lib/hijack/http.js:73:27)
              at o (/Users/recepozen/bordo/monochat/node_modules/@hey-api/client-fetch/src/client.ts:66:16)
              at Object.get (/Users/recepozen/bordo/monochat/node_modules/@hey-api/client-fetch/src/client.ts:167:49)
              at imports/managers/ai-manager/server/vector-stores/providers/chroma.ts:322:6
              at Function.time (/Users/recepozen/bordo/monochat/.meteor/local/build/programs/server/tools/tool-env/profile.ts:646:30)
              at /tools/static-assets/server/boot.js:453:19
              at processTicksAndRejections (node:internal/process/task_queues:105:5)
              at /tools/static-assets/server/boot.js:503:5
              at startServerProcess (/tools/static-assets/server/boot.js:501:3)
    }

Perplexity AI:

The error

"type": "TypeError",
"message": "Only absolute URLs are supported",

occurs because the @hey-api/client-fetch (or similar fetch-based libraries) is being given a relative URL (like /api/data) instead of an absolute URL (like https://example.com/api/data). This is a requirement in Node.js environments and some frameworks (like Next.js) when executing code server-side or during testing, because unlike browsers, Node.js does not have a base URL context to resolve relative paths[1][2][3][4][5].

Why This Happens

  • In browsers, fetch(‘/api/data’) works because the browser knows the current domain and protocol, so it can resolve the relative path.
  • In Node.js (which is where @hey-api/client-fetch likely runs), there is no concept of a “current domain”—so fetch requires a full, absolute URL to know where to send the request[2][3][4].
  • This is especially common in server-side rendering frameworks like Next.js, or when running tests in Node.js[1][2][3][5].

How to Fix

  • Always use an absolute URL when calling APIs from server-side code or Node.js-based libraries.
  • You can construct the absolute URL using environment variables or configuration, for example:
const apiBaseUrl = process.env.API_BASE_URL; // e.g., 'https://example.com'
const response = await fetch(`${apiBaseUrl}/api/data`);
  • If you need to support both client-side and server-side code, detect the environment and construct the URL accordingly, or always use absolute URLs for consistency.

Summary Table

Environment Relative URL Works? Solution
Browser Yes Use relative or absolute URL
Node.js No Use absolute URL

In short:
Update your API calls to use absolute URLs when using @hey-api/client-fetch or any fetch-based library in Node.js or server-side code to resolve this error[1][2][3][4][5].

Thank you very much for your answer. If this is in a package, can apiBaseUrl be given via fetch options?