@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
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:
| Field | Description |
|---|---|
eventId | UUID v4 stamped per emit. Stable per-emit idempotency key — http:request and cost:http:request for the same fetch get distinct eventIds, so dedup keyed on eventId won’t collapse the two. |
eventDate | Millisecond epoch timestamp for when the event was emitted. |
requestId | UUID generated per request inside @outputai/http. Shared between the matching http:request and cost:http:request events for cross-event correlation. |
method | HTTP method (uppercase). |
url | Absolute request URL. |
status | HTTP status code; undefined on network failure. |
durationMs | Elapsed time from request issuance to response (or failure), in milliseconds. |
outcome | One of 'success' (2xx-3xx), 'error' (status >= 400), 'failure' (DNS / timeout / abort). |
activityInfo | Temporal activity.Info for the activity that made the request. |
workflowDetails | Output’s serializable subset of Temporal workflow.WorkflowInfo. |
outputActivityKind | Output activity kind. Possible values are step, evaluator, and internal_step. |
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:
Environment Variables
| Variable | Description |
|---|---|
OUTPUT_TRACE_HTTP_VERBOSE | Set to true or 1 to include request/response headers and bodies in trace files (otherwise only method, URL, and status are recorded) |