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
cancelfires.
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
AbortErrorthatfetchraises 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
httpProxysetting. - 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 skipsthread.*events. Fails on malformed JSON, anerrorevent or a payload with a truthyerror. - 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
httpProxysetting adds for child processes:HTTP_PROXYandHTTPS_PROXY, each where the environment lacks it. - read_
chunk - The next chunk of a response body, or
Noneat the end. Fails with pi’s message whencancelfires or the connection drops:interruptedwhen 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 tooptions.max_retriestimes with pi’s backoff and honoringretry-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
httpIdleTimeoutMssets undici’sheadersTimeoutandbodyTimeout. 0 waits forever. - set_
settings_ proxy - Applies pi’s
httpProxysetting for this process: it serves asHTTP_PROXYandHTTPS_PROXYwhere those are unset. Call it before the first request. Only the first call counts. - user_
agent yapi (<os>; <arch>), after pi’spi (<platform> <release>; <arch>).