Documentation
¶
Overview ¶
Package routing provides shared provider routing for AI Gateway handlers.
Index ¶
Constants ¶
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.
const InvalidPathMessage = "invalid request path"
InvalidPathMessage is the response body for requests rejected by RejectInvalidForwardPath.
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 ¶
NewProviderMux registers mode-independent provider errors. Callers add their enabled-provider routes to the returned mux.
func RejectInvalidForwardPath ¶
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.