summaryrefslogtreecommitdiff
path: root/internal/llm/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/llm/util.go')
-rw-r--r--internal/llm/util.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/internal/llm/util.go b/internal/llm/util.go
index b6e2adc..fe99467 100644
--- a/internal/llm/util.go
+++ b/internal/llm/util.go
@@ -13,7 +13,18 @@ import (
// small helper to keep return type consistent
func nilStringErr(msg string) (string, error) { return "", errors.New(msg) }
+// doJSONRequest is the shared entry point for provider HTTP calls. It applies
+// the default retry-with-backoff policy and the shared circuit breaker so that
+// transient upstream failures (network resets, 429, 5xx) are smoothed over,
+// while client errors (4xx) and successes are returned immediately. The body
+// bytes are passed by value so each retry can rebuild a fresh request.
func doJSONRequest(ctx context.Context, httpClient *http.Client, url string, body []byte, headers map[string]string, accept string) (*http.Response, error) {
+ return doJSONRequestResilient(ctx, httpClient, url, body, headers, accept, defaultRetryPolicy(), sharedBreaker)
+}
+
+// doJSONRequestOnce performs exactly one HTTP POST with the given JSON body and
+// headers. It is the single-attempt primitive used by the resilience layer.
+func doJSONRequestOnce(ctx context.Context, httpClient *http.Client, url string, body []byte, headers map[string]string, accept string) (*http.Response, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, err