Skip to content

refactor: centralise provider base URLs — eliminate handler/fetcher duplication #350

Description

@edelauna

Problem

Several providers define their base URL independently in both the handler (constructor) and the fetcher, meaning a URL change requires edits in two places. The pattern was introduced with earlier providers and carried forward with each new addition.

Affected providers (handler + fetcher both hardcode the same URL):

Provider Handler Fetcher
opencode-go src/api/providers/opencode-go.ts:35 src/api/providers/fetchers/opencode-go.ts:7
vercel-ai-gateway src/api/providers/vercel-ai-gateway.ts:31 src/api/providers/fetchers/vercel-ai-gateway.ts:58

Additional providers with hardcoded URLs only in the handler (no fetcher constant to consolidate yet, but still worth noting for consistency):

  • fireworks, sambanova, unbound, xai, openai-codex, qwen-code, moonshot

Proposed Fix

Export each provider's base URL constant from packages/types/src/providers/<provider>.ts alongside the existing defaultModelId / defaultModelInfo exports, then import it in both the handler and the fetcher.

Example for opencode-go:

// packages/types/src/providers/opencode-go.ts
export const OPENCODE_GO_BASE_URL = "https://opencode.ai/zen/go/v1"
// src/api/providers/opencode-go.ts
import { ..., OPENCODE_GO_BASE_URL } from "@roo-code/types"
// ...
baseURL: OPENCODE_GO_BASE_URL,
// src/api/providers/fetchers/opencode-go.ts
import { ..., OPENCODE_GO_BASE_URL } from "@roo-code/types"
// remove local const OPENCODE_GO_BASE_URL

Scope

Start with opencode-go and vercel-ai-gateway (both have the handler+fetcher split). Extend to other providers opportunistically.

Surfaced during review of #319.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions