Skip to content

OpenAPI Client throws "Invalid URL" error when using relative paths like "/api" #1159

Description

@SeraphimKaito

Environment

  • os: Darwin Kernel Version 25.0.0: Wed Sep 17 21:35:32 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6020 arm64
  • node: v24.2.0
  • orpc: V1.10.2

Reproduction

client

import { createORPCClient } from '@orpc/client'
import { OpenAPILink } from '@orpc/openapi-client/fetch'
import { contract } from './contract'

const link = new OpenAPILink(contract, {
  url: '/api', 
})

export const client: JsonifiedClient<ContractRouterClient<typeof contract>> = createORPCClient(link)

vite config

export default defineConfig({
  plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:3000",
        changeOrigin: true,
      },
    },
  },
});

Describe the bug

When configuring OpenAPILink with a relative URL (e.g., /api), the client throws an error:

Image

Current behavior:

The StandardOpenapiLinkCodec uses new URL(baseUrl) which requires an absolute URL. This fails when users provide relative paths.

Expected behavior:

The client should support relative URLs in browser environments, automatically resolving them against location.origin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions