Skip to main content
In Bun, fetch supports sending requests through an HTTP or HTTPS proxy. Use it on corporate networks or when a request must come from a specific IP address.
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bproxy.ts

The proxy option can be a URL string, a URL instance, or an object with url (a string or a URL) and optional headers. The URL can include the username and password if the proxy requires authentication. It can be http:// or https://.

Custom proxy headers

To send custom headers to the proxy server (for proxy authentication tokens or custom routing), use the object format:
https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bproxy-headers.ts
The headers property accepts a plain object or a Headers instance. These headers are sent directly to the proxy server in CONNECT requests (for HTTPS targets) or in the proxy request (for HTTP targets). If you provide a Proxy-Authorization header, it overrides any credentials in the proxy URL.

Environment variables

To use the same proxy for all requests, set the $HTTP_PROXY or $HTTPS_PROXY environment variable to the proxy URL.
terminal