@outputai/http package gives you an HTTP client that automatically shows up in your traces. Every request — URL, method, status code, timing — is recorded as a child node in the trace tree, so you can see exactly what API calls your steps made and how long they took.
Under the hood, it wraps ky, a lightweight HTTP client built on fetch.
Creating a Client
The typical pattern is to create a client per external service in your clients directory, then import it in your steps:clients/jina.ts
HTTP Methods
Response Bodies
@outputai/http follows normal fetch semantics: callers own the returned response body. Always consume the body with
.json(), .text(), .arrayBuffer(), or another body reader when you need the payload.
If you only need response metadata from a non-HEAD request, such as response.url, response.status, or headers, cancel
the unused body so the underlying connection and native buffers can be released:
Using in Steps
Wrap HTTP calls in steps for automatic retry and tracing:steps.ts
Tracing
All requests made with@outputai/http are automatically traced — no configuration needed. In your trace files, HTTP calls appear as children of the step that made them:
Request Events
Every HTTP call made through@outputai/http’s fetch (and the higher-level httpClient) emits an http:request hook event — independent of whether you attach a cost. Subscribe to it with on for logging, alerting, or per-vendor metrics:
payload:
The event fires for every call — success, non-2xx responses, and network failures alike. The existing
cost:http:request event is unchanged and continues to fire only when you call addRequestCost.
Attaching Request Cost
When you know the dollar cost of an HTTP request (for example from provider billing headers), you can attach it to the HTTP trace event withaddRequestCost.
addRequestCost accepts the total request cost as a number.
addRequestCost only works with responses created by @outputai/http (or its exported fetch). If the response did not come from this package, the function safely no-ops and logs a warning.
It also emits a cost:http:request hook event (same hooks system as cost:llm:request). For the payload and examples, see Cost Events — HTTP.
Error Handling
The client throwsHTTPError for non-2xx responses and TimeoutError for timeouts: