Skip to main content

Module http

Module http 

Source
Expand description

HTTP transport shared by the wire APIs: client, retries, cancellation, errors.

Structs§

SseReader
Reads server-sent events from a response until it ends or cancel fires.

Enums§

Failure
Why a request produced no usable response.

Constants§

ABORTED_BEFORE_RESPONSE
Message when the request is cancelled before a response arrives.
ABORTED_DURING_STREAM
Message when the request is cancelled while the response streams.
ABORTED_READ
Message of the DOM AbortError that fetch raises when it is cancelled during a pending body read.
DEFAULT_IDLE_TIMEOUT_MS
pi’s default httpIdleTimeoutMs: five minutes.
MALFORMED_SSE_JSON
Message for a stream event whose data is not JSON, as the OpenAI SDK words it.

Functions§

client
The process-wide HTTP client. It honors the standard proxy variables and the httpProxy setting.
is_truthy
JavaScript truthiness of a JSON value.
next_openai_chunk
The next JSON chunk of an OpenAI SDK stream. Ends at [DONE] or the end of the body and skips thread.* events. Fails on malformed JSON, an error event or a payload with a truthy error.
provider_error_message
pi’s formatProviderError: the SDK message, or the status and body when the message does not already include the error body. With a prefix, either form reads <prefix> (<status>): <text>. Without one, a body reads <status>: <body>.
proxy_env
The proxy variables the httpProxy setting adds for child processes: HTTP_PROXY and HTTPS_PROXY, each where the environment lacks it.
read_chunk
The next chunk of a response body, or None at the end. Fails with pi’s message when cancel fires or the connection drops: interrupted when it fires during the read.
sdk_error_message
The message of an error the OpenAI SDK raises without a status, such as an error payload inside a stream: its message, or the error as JSON.
sdk_status_message
The error message the Stainless SDKs (Anthropic, OpenAI) give a failed status: <status> <error.message>, the error as JSON, or the raw body.
send
Sends a request built by build, retrying retryable failures up to options.max_retries times with pi’s backoff and honoring retry-after.
set_idle_timeout_ms
Sets how long provider requests may wait for response headers, and then for each body chunk, before failing, as pi’s httpIdleTimeoutMs sets undici’s headersTimeout and bodyTimeout. 0 waits forever.
set_settings_proxy
Applies pi’s httpProxy setting for this process: it serves as HTTP_PROXY and HTTPS_PROXY where those are unset. Call it before the first request. Only the first call counts.
user_agent
yapi (<os>; <arch>), after pi’s pi (<platform> <release>; <arch>).