Skip to content

feat(provider): add sub-provider accessors for custom-named gateway providers - #105

Merged
ThomasK33 merged 1 commit into
mainfrom
feat-provider-104-custom-providers
Aug 25, 2026
Merged

feat(provider): add sub-provider accessors for custom-named gateway providers#105
ThomasK33 merged 1 commit into
mainfrom
feat-provider-104-custom-providers

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Closes #104.

Adds sub-provider factories to CoderProvider so one instance can target any admin-defined AI Gateway provider, per the accepted design in #104 (explicit accessors; prefix routing rejected there):

const azure = coder.openaiProvider("azure-openai");        // → <base>/api/v2/aibridge/azure-openai/v1
const bedrock = coder.anthropicProvider("anthropic-bedrock"); // → <base>/api/v2/aibridge/anthropic-bedrock/v1

API surface

One construction path

The default openai/anthropic surfaces are now built by the same factories (openaiProvider(DEFAULT_OPENAI_PROVIDER) etc.), so custom-named sub-providers inherit every default behavior: auth mode matrix (centralized/BYOK), header merging, custom fetch, includeUsage, and the fail-fast embeddings guard. Two deliberate, strictly-fail-faster consequences to note:

  • settings.providers rename values are now validated against the same grammar at createCoder time (previously a bad rename surfaced as a request-time 404; such names can never be registered server-side, so no working config breaks).
  • A renamed sub-provider's telemetry/provider-metadata string is now coder.<name> (e.g. coder.azure-openai.chat) instead of always coder.openai; defaults are byte-identical to before (coder.openai / coder.anthropic), which the unit tests pin via unchanged existing assertions.

README

Rewrote the provider README's "The two surfaces" section as "Named providers and the two wire protocols": the two protocols with their upstream types and default names, the new accessors with the azure-openai/anthropic-bedrock example, the existing settings.providers re-point option, and an explicit note that provider discovery is admin-only server-side (GET /api/v2/ai/providers → 403 for regular users; get names from your platform team). Updated the root README anchor and the stale ~175 lines claim in the security section. All snippets typecheck (scratch file assembled in examples/, pnpm --filter @coder/ai-sdk-provider typecheck, then deleted).

Validation

Unit (source-verified): 22 tests pass — 15 pre-existing unchanged (defaults pinned), 7 new: exact request URL for custom names on both protocols (captured fetch), custom aiGatewayPath, openaiProvider("openai") ≡ default surface, grammar rejection (7 malformed names × both accessors, InvalidArgumentError.isInstance, zero requests), embeddings fail-fast on named sub-providers, settings.providers grammar validation.

Gates: pnpm check, pnpm -r build, pnpm -r test (494 tests), pnpm publint, pnpm attw — all green.

Live (dev.coder.com, v2.36.x):

  • coder("gpt-4o-mini") and coder.openaiProvider("openai")("gpt-4o-mini") emitted byte-identical request URLs (…/api/v2/aibridge/openai/v1/chat/completions) and both completed (finishReason: stop, same reply).
  • coder.openaiProvider("does-not-exist")("gpt-4o-mini") → clean AI_APICallError, statusCode: 404, URL …/aibridge/does-not-exist/v1/chat/completions, body route not supported: POST /does-not-exist/v1/chat/completions.
  • coder.openaiProvider("Does_Not_Exist") → client-side AI_InvalidArgumentError, zero requests emitted.

Honesty tier: dev.coder.com only defines the default openai/anthropic providers, so custom-name routing to a real custom provider is verified by unit-level URL construction plus the live 404 shape above (which proves the URL reaches the gateway's per-name router), not by a live custom-provider round-trip.


Generated with mux • Model: anthropic:claude-fable-5 • Thinking: xhigh

…roviders

Change-Id: I8b538132266fcff1c57a1dd430be2d945ce25dee
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d5469b9320

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: d5469b9320

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Aug 25, 2026
Merged via the queue into main with commit c049a45 Aug 25, 2026
6 checks passed
@ThomasK33
ThomasK33 deleted the feat-provider-104-custom-providers branch August 25, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provider: reach custom-named AI Gateway providers (sub-provider accessors)

1 participant