routing

package
v2.38.6 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package routing provides shared provider routing for AI Gateway handlers.

Index

Constants

View Source
const ErrorCodeProviderDisabled = "provider_disabled"

ErrorCodeProviderDisabled is the code written in the response body when a request targets a configured-but-disabled provider. Paired with HTTP 503.

View Source
const InvalidPathMessage = "invalid request path"

InvalidPathMessage is the response body for requests rejected by RejectInvalidForwardPath.

View Source
const MaxRequestBodyBytes = 32 << 20 // 32 MiB

MaxRequestBodyBytes caps the request body size for AI Gateway provider endpoints to prevent denial-of-service via memory exhaustion. Anthropic enforces 32 MB on the direct API, 30 MB on Vertex AI, and 20 MB on Amazon Bedrock. See https://docs.anthropic.com/en/api/overview#request-size-limits OpenAI and GitHub Copilot do not document an equivalent HTTP body size limit. Using highest documented provider limit (32 MiB).

NOTE: aibridge does not currently proxy file-upload endpoints (e.g. /v1/files). Those endpoints accept much larger bodies (up to 500 MB for Anthropic, 50 MB for OpenAI). If file-upload routes are added, they will need a per-route limit instead of this single global cap.

Variables

This section is empty.

Functions

func NewProviderMux

func NewProviderMux(providers []provider.Provider, logger slog.Logger) *http.ServeMux

NewProviderMux registers mode-independent provider errors. Callers add their enabled-provider routes to the returned mux.

func RejectInvalidForwardPath

func RejectInvalidForwardPath(next http.Handler) http.Handler

RejectInvalidForwardPath wraps next and responds with 400 to requests whose path is unsafe to forward upstream, as reported by xurl.ContainsEncodedPath, before any routing or upstream request.

func WriteRequestBodyTooLarge

func WriteRequestBodyTooLarge(ctx context.Context, w http.ResponseWriter)

WriteRequestBodyTooLarge writes a human-readable 413 response indicating that the request body exceeded MaxRequestBodyBytes.

It records the limit before writing, so the request log names the limit that tripped and the too-large metric attributes the rejection to body size rather than to the other reasons coderd answers 413. Recording here rather than at each call site keeps the two inseparable: this helper is the only path to a body-too-large response from aibridge.

Types

This section is empty.

Jump to

Keyboard shortcuts

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