Configuration
NewClient accepts a variadic list of option.RequestOption values. The same option type is reused for per-call overrides on every render and document method — pass options as the last argument to override the client-wide value for that call.
Construction-time options
Section titled “Construction-time options”option.WithAPIKey(key)(required) — your API key. The key names its environment (pp_{env}_…); see Authentication.option.WithBaseURL(url)— override the API endpoint. Defaults tohttps://api.poli.page.option.WithTimeout(d)— per-request fallback deadline. Applied when the caller’scontext.Contexthas no deadline of its own. Defaults to60s.option.WithMaxRetries(n)— retry budget on top of the initial attempt. Defaults to2(three attempts total).option.WithRetryDelay(d)— base exponential-backoff delay. Defaults to500ms.option.WithHTTPClient(c)— inject a custom*http.Client(proxies, TLS pinning, recording).option.WithLogger(l)— wire a*slog.Loggerfor debug/warn/error lines.option.WithOnRetry(fn)/option.WithOnError(fn)— observability hooks. Fire-and-forget; panics are recovered.option.WithHeader(key, value)— attach a custom header to every request.
Per-call overrides
Section titled “Per-call overrides”option.WithIdempotencyKey(key)— override the SDK-generated UUID v4Idempotency-Key.option.WithRequestTimeout(d)— override the per-request timeout for a single call.option.WithHeader(key, value)— add or override a header for one call only.
Example
Section titled “Example”package main
import ( "log/slog" "os" "time"
"github.com/poli-page/sdk-go" "github.com/poli-page/sdk-go/option")
func main() { logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) _ = polipage.NewClient( option.WithAPIKey(os.Getenv("POLI_PAGE_API_KEY")), option.WithTimeout(30*time.Second), option.WithMaxRetries(3), option.WithRetryDelay(250*time.Millisecond), option.WithLogger(logger), )}