feat: add Type() to Provider interface and configurable instance Name#237
feat: add Type() to Provider interface and configurable instance Name#237ssncferreira merged 1 commit intomainfrom
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
| Provider: p.Type(), | ||
| ProviderName: p.Name(), |
There was a problem hiding this comment.
Keeping the provider type ("anthropic", "openai", "copilot") so interceptions preserve this value and we are still easily able to aggregate by provider. The ProviderName field provides the specific instance identity. Alternatively, we could store the upstream URL instead.
Examples:
- Anthropic: Provider: anthropic, ProviderName: anthropic
- Copilot: Provider: copilot, ProviderName: copilot
- Copilot Business: Provider: copilot, ProviderName: copilot-business
- Copilot Enterprise: Provider: copilot, ProviderName: copilot-enterprise
config/config.go
Outdated
| ) | ||
|
|
||
| type Anthropic struct { | ||
| // Name is the provider instance name. If empty, defaults to ProviderAnthropic. |
There was a problem hiding this comment.
nit: comment is a bit confusing, defaults to "ProviderAnthropic" or value of ProviderAnthropic variable?
Maybe functions Name()and Type() with logic regarding defaults should be in config package and provider would simply call them? Then it would be simpler to understand the comment.
Same confusion in comments for other providers.
There was a problem hiding this comment.
Updated the comment to reference the name "anthropic", "openai", "copilot".
On moving the defaulting logic to config: I'd prefer to keep it in the provider constructors for consistency, that's the same pattern used for the other methods like BaseURL, Key, APIDumpDir, and CircuitBreaker.
I'm not sure how I fell about this. If If Lines 14 to 45 in b97c9d4 and here is comment showing differences from PR: #174 (comment) |
2c8fad4 to
85648f5
Compare
I don't think Your comment about OpenAI vs Anthropic base URL differences still applies: that behavior is unchanged since each provider's |
| } | ||
|
|
||
| func (p *Anthropic) Name() string { | ||
| return p.cfg.Name |
There was a problem hiding this comment.
Since Name defines route prefix does it need to be checked/sanitized?
There was a problem hiding this comment.
Yes, it should. I can add it in validateProviders on the upstack PR: #240
Merge activity
|
85648f5 to
f44164f
Compare

Problem
There is no way to register multiple provider instances of the same type with distinct identities. For example, introducing a copilot-business provider (targeting
api.business.githubcopilot.com) alongside the default copilot provider (targetingapi.individual.githubcopilot.com) would result in both sharing the same name, making them indistinguishable in metrics, logs, circuit breaker, API dump, database records, and the coder aibridge HTTP route prefix.Changes
Type()toProviderinterface returning the provider type ("anthropic", "openai", "copilot")Namefield to provider configs, defaulting to the type when not setName()now returns the instance name, used for metrics, logs, circuit breaker, routing, and the coder aibridge endpoint (RoutePrefix()is derived fromName())Type()is used for the databaseProviderfieldProviderNamefield toInterceptionRecordfor the instance nameRelated to: #152
Disclaimer: initially produced by Claude Opus 4.6, heavily modified and reviewed by @ssncferreira .