#18487 · @raf1hh · opened Mar 21, 2026 at 3:33 AM UTC · last updated Mar 21, 2026 at 4:18 AM UTC

fix: inherit provider loaders for provider aliases

appfix
67
+4692 files

Score breakdown

Impact

8.0

Clarity

9.0

Urgency

7.0

Ease Of Review

8.0

Guidelines

8.0

Readiness

8.0

Size

8.0

Trust

5.0

Traction

2.0

Summary

This PR aims to fix aliased custom providers not inheriting authentication and model loading behavior from their referenced base providers. It introduces an "auth_provider" field to allow this inheritance. This enables custom provider IDs to leverage built-in SDK logic previously unavailable.

Open in GitHub

Description

Issue for this PR

Closes #18486

Type of change

  • [ ] Bug fix
  • [x] New feature
  • [x] Refactor / code improvement
  • [ ] Documentation

What does this PR do?

Fix custom providers configured with auth_provider so they inherit the referenced provider's SDK options and model loader behavior.

Before this change, built-in auth/plugin loaders were only applied to the source provider id and there is no way to reuse built-in sdk auth/model-loading behavior.

This change applies plugin auth loaders to aliased providers and reuses model/vars loaders from the referenced provider, so config like this now works:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "my-github-copilot": {
      "name": "My GitHub Copilot",
      "auth_provider": "github-copilot",
      "npm": "@ai-sdk/github-copilot"
    }
  }
}

With this change, my-github-copilot behaves like a GitHub Copilot-backed provider for auth/model loading, while still keeping its own provider id and config entry instead of overriding github-copilot directly.

Without this fix, using a custom id here is limiting because the aliased provider does not inherit the built-in loader behavior.

How did you verify your code works?

I cherry-picked this onto current upstream dev, verified the PR diff is limited to this fix, and ran bun typecheck from packages/opencode.

Screenshots / recordings

Not a UI change.

Checklist

  • [x] I have tested my changes locally
  • [x] I have not included unrelated changes in this PR

Linked Issues

#18486 custom providers do not inherit provider loaders

View issue

Comments

No comments.

Changed Files

packages/opencode/src/config/config.ts

+40
@@ -979,6 +979,10 @@ export namespace Config {
.extend({
whitelist: z.array(z.string()).optional(),
blacklist: z.array(z.string()).optional(),
auth_provider: z
.string()
.optional()
.describe("Provider to inherit SDK and model loading behavior from"),
models: z
.record(
z.string(),

packages/opencode/src/provider/provider.ts

+429
@@ -55,6 +55,22 @@ import { ModelID, ProviderID } from "./schema"
export namespace Provider {
const log = Log.create({ service: "provider" })
function driver(cfg: Config.Info, id: string): string {
const seen = new Set<string>()
let current = id
while (true) {
if (seen.has(current)) return current
seen.add(current)
const next = cfg.provider?.[current]?.auth_provider
if (!next || next === current) return current
current = next
}
}
function aliases(cfg: Config.Info, source: string): string[] {
return Object.keys(cfg.provider ?? {}).filter((item) => item !== source && driver(cfg, item) === source)
}
function shouldUseCopilotResponsesApi(modelID: string): boolean {
const match = /^gpt-(\d+)/.exec(modelID)
if (!match) return false
@@ -1069,19 +1085,27 @@ export namespace Provider {
for (const plugin of await Plugin.list()) {
if (!plugin.auth) continue
const providerID = ProviderID.make(plugin.auth.provider)
if (disabled.has(providerID)) continue
const auth = await Auth.get(providerID)
if (!auth) continue
if (!plugin.auth.loader) continue