Documentation
¶
Index ¶
- Variables
- type Anthropic
- func (p *Anthropic) AuthHeader() string
- func (p *Anthropic) BaseURL() string
- func (p *Anthropic) BridgedRoutes() []string
- func (p *Anthropic) CircuitBreakerConfig() *config.CircuitBreaker
- func (p *Anthropic) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
- func (p *Anthropic) InjectAuthHeader(headers *http.Header)
- func (p *Anthropic) Name() string
- func (p *Anthropic) PassthroughRoutes() []string
- func (p *Anthropic) RoutePrefix() string
- type Copilot
- func (p *Copilot) AuthHeader() string
- func (p *Copilot) BaseURL() string
- func (p *Copilot) BridgedRoutes() []string
- func (p *Copilot) CircuitBreakerConfig() *config.CircuitBreaker
- func (p *Copilot) CreateInterceptor(_ http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
- func (p *Copilot) InjectAuthHeader(_ *http.Header)
- func (p *Copilot) Name() string
- func (p *Copilot) PassthroughRoutes() []string
- func (p *Copilot) RoutePrefix() string
- type OpenAI
- func (p *OpenAI) AuthHeader() string
- func (p *OpenAI) BaseURL() string
- func (p *OpenAI) BridgedRoutes() []string
- func (p *OpenAI) CircuitBreakerConfig() *config.CircuitBreaker
- func (p *OpenAI) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
- func (p *OpenAI) InjectAuthHeader(headers *http.Header)
- func (p *OpenAI) Name() string
- func (p *OpenAI) PassthroughRoutes() []string
- func (p *OpenAI) RoutePrefix() string
- type Provider
Constants ¶
This section is empty.
Variables ¶
var UnknownRoute = errors.New("unknown route")
Functions ¶
This section is empty.
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
Anthropic allows for interactions with the Anthropic API.
func NewAnthropic ¶
func NewAnthropic(cfg config.Anthropic, bedrockCfg *config.AWSBedrock) *Anthropic
func (*Anthropic) AuthHeader ¶
func (*Anthropic) BridgedRoutes ¶
func (*Anthropic) CircuitBreakerConfig ¶
func (p *Anthropic) CircuitBreakerConfig() *config.CircuitBreaker
func (*Anthropic) CreateInterceptor ¶
func (p *Anthropic) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
func (*Anthropic) InjectAuthHeader ¶
func (*Anthropic) PassthroughRoutes ¶
func (*Anthropic) RoutePrefix ¶ added in v1.0.3
type Copilot ¶
type Copilot struct {
// contains filtered or unexported fields
}
Copilot implements the Provider interface for GitHub Copilot. Unlike other providers, Copilot uses per-user API keys that are passed through the request headers rather than configured statically.
func NewCopilot ¶
func (*Copilot) AuthHeader ¶
func (*Copilot) BridgedRoutes ¶
func (*Copilot) CircuitBreakerConfig ¶
func (p *Copilot) CircuitBreakerConfig() *config.CircuitBreaker
func (*Copilot) CreateInterceptor ¶
func (p *Copilot) CreateInterceptor(_ http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
func (*Copilot) InjectAuthHeader ¶
InjectAuthHeader is a no-op for Copilot. Copilot uses per-user tokens passed in the original Authorization header, rather than a global key configured at the provider level. The original Authorization header flows through untouched from the client.
func (*Copilot) PassthroughRoutes ¶
func (*Copilot) RoutePrefix ¶ added in v1.0.3
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI allows for interactions with the OpenAI API.
func (*OpenAI) AuthHeader ¶
func (*OpenAI) BridgedRoutes ¶
func (*OpenAI) CircuitBreakerConfig ¶
func (p *OpenAI) CircuitBreakerConfig() *config.CircuitBreaker
func (*OpenAI) CreateInterceptor ¶
func (p *OpenAI) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (_ intercept.Interceptor, outErr error)
func (*OpenAI) InjectAuthHeader ¶
func (*OpenAI) PassthroughRoutes ¶
PassthroughRoutes define the routes which are not currently intercepted but must be passed through to the upstream. The /v1/completions legacy API is deprecated and will not be passed through. See https://platform.openai.com/docs/api-reference/completions.
func (*OpenAI) RoutePrefix ¶ added in v1.0.3
type Provider ¶
type Provider interface {
// Name returns the provider's name.
Name() string
// BaseURL defines the base URL endpoint for this provider's API.
BaseURL() string
// CreateInterceptor starts a new [Interceptor] which is responsible for intercepting requests,
// communicating with the upstream provider and formulating a response to be sent to the requesting client.
CreateInterceptor(http.ResponseWriter, *http.Request, trace.Tracer) (intercept.Interceptor, error)
// RoutePrefix returns a prefix on which the provider's bridged and passthroguh routes will be registered.
// Must be unique across providers to avoid conflicts.
RoutePrefix() string
// BridgedRoutes returns a slice of [http.ServeMux]-compatible routes which will have special handling.
// See https://pkg.go.dev/net/http#hdr-Patterns-ServeMux.
BridgedRoutes() []string
// PassthroughRoutes returns a slice of whitelisted [http.ServeMux]-compatible* routes which are
// not currently intercepted and must be handled by the upstream directly.
//
// * only path routes can be specified, not ones containing HTTP methods. (i.e. GET /route).
// By default, these passthrough routes will accept any HTTP method.
PassthroughRoutes() []string
// AuthHeader returns the name of the header which the provider expects to find its authentication
// token in.
AuthHeader() string
// InjectAuthHeader allows [Provider]s to set its authentication header.
InjectAuthHeader(*http.Header)
// CircuitBreakerConfig returns the circuit breaker configuration for the provider.
CircuitBreakerConfig() *config.CircuitBreaker
}
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} {aibridge root} {provider prefix} {provider route}
{host} + {aibridge root} + {provider prefix} form the base URL used in tools/clients using AI Bridge (eg. Claude/Codex).
When request is bridged, interceptor created based on route processes the request. When request is passed through the {host} + {aibridge root} + {provider prefix} URL part is replaced by provider's base URL and request is forwarded. This mirrors behaviour in bridged routes and SDKs used by interceptors.
Example:
OpenAI chat completions AI Bridge base URL (set in Codex): "https://host.coder.com/api/v2/aibridge/openai/v1" Upstream base URl (set in coder config): http://api.openai.com/v1 Request: Codex -> https://host.coder.com/api/v2/aibridge/openai/v1/chat/completions -> AI Bridge -> http://api.openai.com/v1/chat/completions url change: 'https://host.coder.com/api/v2/aibridge/openai/v1' -> 'http://api.openai.com/v1' | '/chat/completions' suffix remains the same
Anthropic messages AI Bridge base URL (set in Codex): "https://host.coder.com/api/v2/aibridge/anthropic" Upstream base URl (set in coder config): http://api.anthropic.com Request: Codex -> https://host.coder.com/api/v2/aibridge/anthropic/v1/messages -> AI Bridge -> http://api.anthropic.com/v1/messages url change: 'https://host.coder.com/api/v2/aibridge/anthropic' -> 'http://api.anthropic.com' | '/v1/messages' suffix remains the same
!Note! OpenAI and Anthropic use different route patterns. OpenAI includes the version '/v1' in the base url while Antropic does not. More details/examples: https://github.com/coder/aibridge/pull/174#discussion_r2782320152