HttpProxyService class

Proxies authenticated clients' outbound HTTPS requests to AI provider APIs.

A browser client cannot call api.anthropic.com and friends directly (CORS, and it should not hold the operator's keys), so the Hub makes the request on its behalf. The proxy is deliberately narrow:

  • Authenticated callers only — the broker dispatches handle solely for authenticated client peers; the proxy is never reachable pre-auth.
  • Allowlisted hosts + https only — requests to anything other than the known AI provider hosts (plus an optional configured defaultConfig baseUrl host) are rejected. This is the SSRF boundary; do not widen it into a general fetch.
  • Optional credential injection — with HttpProxyCredentialMode.hubDefault the Hub injects its configured key for the matched provider, so the key never leaves the Hub. With HttpProxyCredentialMode.none the client's own request (key included) is forwarded verbatim.

Constructors

HttpProxyService({AiConfig? defaultConfig, Client? httpClient, Duration timeout = const Duration(seconds: 120)})
Creates an HTTP proxy service.

Properties

defaultConfig AiConfig?
The Hub's default AI configuration, used for hubDefault credential injection and config discovery. null when the Hub has no AI key configured (only the bring-your-own-key path then works).
final
hashCode int
The hash code for this object.
no setterinherited
httpClient → Client
The HTTP client used for outbound requests (injectable for tests).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
timeout Duration
How long to wait for a provider response before failing.
final

Methods

close() → void
Releases the HTTP client.
describe(String requestId) AiConfigResponse
Builds the config-discovery reply, omitting the API key.
handle(HttpProxyRequest req) Future<HttpProxyResponse>
Performs req and returns the proxied response, or an error response on a rejected target / transport failure.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited