provider

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 (p *Anthropic) AuthHeader() string

func (*Anthropic) BaseURL

func (p *Anthropic) BaseURL() string

func (*Anthropic) BridgedRoutes

func (p *Anthropic) BridgedRoutes() []string

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 (p *Anthropic) InjectAuthHeader(headers *http.Header)

func (*Anthropic) Name

func (p *Anthropic) Name() string

func (*Anthropic) PassthroughRoutes

func (p *Anthropic) PassthroughRoutes() []string

func (*Anthropic) RoutePrefix added in v1.0.3

func (p *Anthropic) RoutePrefix() string

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 NewCopilot(cfg config.Copilot) *Copilot

func (*Copilot) AuthHeader

func (p *Copilot) AuthHeader() string

func (*Copilot) BaseURL

func (p *Copilot) BaseURL() string

func (*Copilot) BridgedRoutes

func (p *Copilot) BridgedRoutes() []string

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

func (p *Copilot) InjectAuthHeader(_ *http.Header)

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) Name

func (p *Copilot) Name() string

func (*Copilot) PassthroughRoutes

func (p *Copilot) PassthroughRoutes() []string

func (*Copilot) RoutePrefix added in v1.0.3

func (p *Copilot) RoutePrefix() string

type OpenAI

type OpenAI struct {
	// contains filtered or unexported fields
}

OpenAI allows for interactions with the OpenAI API.

func NewOpenAI

func NewOpenAI(cfg config.OpenAI) *OpenAI

func (*OpenAI) AuthHeader

func (p *OpenAI) AuthHeader() string

func (*OpenAI) BaseURL

func (p *OpenAI) BaseURL() string

func (*OpenAI) BridgedRoutes

func (p *OpenAI) BridgedRoutes() []string

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 (p *OpenAI) InjectAuthHeader(headers *http.Header)

func (*OpenAI) Name

func (p *OpenAI) Name() string

func (*OpenAI) PassthroughRoutes

func (p *OpenAI) PassthroughRoutes() []string

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

func (p *OpenAI) RoutePrefix() string

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:

!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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL