Provider defines routes (bridged and passed through) for given provider. Bridged routes are processed by dedicated interceptors. All routes have following pattern: - https://coder.host.com/api/v2 + /aibridge + /{provider.RoutePrefix()} + /{bridged or passthrough route} {host}
| 45 | // OpenAI includes the version '/v1' in the base url while Anthropic does not. |
| 46 | // More details/examples: https://github.com/coder/aibridge/pull/174#discussion_r2782320152 |
| 47 | type Provider interface { |
| 48 | // Type returns the provider type: "copilot", "openai", or "anthropic". |
| 49 | // Multiple provider instances can share the same type. |
| 50 | Type() string |
| 51 | // Name returns the provider instance name. |
| 52 | // Defaults to Type() when not explicitly configured. |
| 53 | Name() string |
| 54 | // BaseURL defines the base URL endpoint for this provider's API. |
| 55 | BaseURL() string |
| 56 | |
| 57 | // CreateInterceptor starts a new [Interceptor] which is responsible for intercepting requests, |
| 58 | // communicating with the upstream provider and formulating a response to be sent to the requesting client. |
| 59 | CreateInterceptor(http.ResponseWriter, *http.Request, trace.Tracer) (intercept.Interceptor, error) |
| 60 | |
| 61 | // RoutePrefix returns a prefix on which the provider's bridged and passthroguh routes will be registered. |
| 62 | // Must be unique across providers to avoid conflicts. |
| 63 | RoutePrefix() string |
| 64 | |
| 65 | // BridgedRoutes returns a slice of [http.ServeMux]-compatible routes which will have special handling. |
| 66 | // See https://pkg.go.dev/net/http#hdr-Patterns-ServeMux. |
| 67 | BridgedRoutes() []string |
| 68 | // PassthroughRoutes returns a slice of whitelisted [http.ServeMux]-compatible* routes which are |
| 69 | // not currently intercepted and must be handled by the upstream directly. |
| 70 | // |
| 71 | // * only path routes can be specified, not ones containing HTTP methods. (i.e. GET /route). |
| 72 | // By default, these passthrough routes will accept any HTTP method. |
| 73 | PassthroughRoutes() []string |
| 74 | |
| 75 | // AuthHeader returns the name of the header which the provider expects to find its authentication |
| 76 | // token in. |
| 77 | AuthHeader() string |
| 78 | // InjectAuthHeader allows [Provider]s to set its authentication header. |
| 79 | InjectAuthHeader(*http.Header) |
| 80 | |
| 81 | // CircuitBreakerConfig returns the circuit breaker configuration for the provider. |
| 82 | CircuitBreakerConfig() *config.CircuitBreaker |
| 83 | |
| 84 | // APIDumpDir returns the directory path for dumping API requests and responses. |
| 85 | // Empty string is returned when API dumping is not enabled. |
| 86 | APIDumpDir() string |
| 87 | } |
no outgoing calls
no test coverage detected