Skip to main content
The @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
You can extend clients to create specialized instances:

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:
See Tracing for details on the trace format.

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:
The handler receives an event envelope. Request-specific fields are available under 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 with addRequestCost.
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 throws HTTPError for non-2xx responses and TimeoutError for timeouts:
Since steps retry automatically, you generally just need to handle cases where retrying won’t help (like a 404). For everything else, let the error propagate and the step’s retry policy will handle it.

Environment Variables

API Reference

For complete TypeScript API documentation, see the HTTP Module API Reference.