httpapi

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 15 Imported by: 0

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

View Source
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

func New(name, baseURL string, headers func(http.Header), httpClient *http.Client) *Client

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

func (c *Client) PostJSON(ctx context.Context, path string, in, out any) error

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.

Jump to

Keyboard shortcuts

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