Documentation
¶
Overview ¶
Package httpapi is the shared HTTP core for the hosted-provider adapters: one governed POST-JSON pipeline (netguard-dialed by default, capped response read, retry with Retry-After through the integrations transport) and one quota classifier, so every adapter makes the same retry-vs-fail decision and a hardening fix lands once instead of per provider. Adapters stay thin wire-format mappers: they build a request struct, call PostJSON, and decode their response type.
Index ¶
Constants ¶
const ( // DefaultTimeout bounds one whole HTTP attempt. It is generous because a // single non-streaming model turn can legitimately run for minutes before // the first response byte arrives. DefaultTimeout = 10 * time.Minute // MaxResponseBytes caps the response-body read, so a hostile or broken // endpoint (reachable via a base-URL override) cannot exhaust memory with an // unbounded body. Far above any real model response, which is bounded by the // output-token ceiling. MaxResponseBytes = 32 << 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client posts JSON requests to one provider API. Build it once per adapter.
func New ¶
New builds a Client for the provider named name (the fault-code and message prefix), rooted at baseURL. headers stamps per-provider authentication onto every request. httpClient overrides the underlying HTTP client (tests inject a mock transport); nil selects the default for the endpoint: loopback (a local model server) gets a plain client, anything else dials through netguard so a hosted call can never be steered at a private, loopback, or cloud-metadata address.
func (*Client) PostJSON ¶
PostJSON marshals in, posts it to path, and decodes a 2xx body into out. Transient failures (network faults, 408/429/5xx) are retried by the transport with backoff, honouring Retry-After; the response read is capped at MaxResponseBytes. Every error is fault-classified: encode/decode and client errors terminal, network and server errors transient, with the 429 quota exception decided by the shared classifier in statusError.