# Proxy HTTP requests using fetch() (/guides/http/proxy)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 570 · updated: 2026-09-23 -->
Related: [Common HTTP server usage](/guides/http/server.md), [Write a simple HTTP server](/guides/http/simple.md), [Send an HTTP request using fetch](/guides/http/fetch.md), [Hot reload an HTTP server](/guides/http/hot.md), [Start a cluster of HTTP servers](/guides/http/cluster.md), [Configure TLS on an HTTP server](/guides/http/tls.md)

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.

```ts icon="/icons/typescript.svg" title="proxy.ts"
await fetch("https://example.com", {
  // The URL of the proxy server
  proxy: "https://username:password@proxy.example.com:8080",
});
```

***

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 [#custom-proxy-headers]

To send custom headers to the proxy server (for proxy authentication tokens or custom routing), use the object format:

```ts icon="/icons/typescript.svg" title="proxy-headers.ts"
await fetch("https://example.com", {
  proxy: {
    url: "https://proxy.example.com:8080",
    headers: {
      "Proxy-Authorization": "Bearer my-token",
      "X-Proxy-Region": "us-east-1",
    },
  },
});
```

The `headers` property accepts a plain object or a `Headers` instance. Bun sends these headers 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 [#environment-variables]

To use the same proxy for all requests, set the `$HTTP_PROXY` and `$HTTPS_PROXY` environment variables to the proxy URL. Bun uses `$HTTP_PROXY` only for requests to `http://` URLs and `$HTTPS_PROXY` only for requests to `https://` URLs, so set both to proxy every request.

```sh icon="terminal" title="terminal" terminal
HTTP_PROXY=https://username:password@proxy.example.com:8080 HTTPS_PROXY=https://username:password@proxy.example.com:8080 bun run index.ts
```

`$ALL_PROXY` applies to both kinds of URL when the scheme-specific variable is unset. `$NO_PROXY` lists the hosts that bypass the proxy. See [Proxying requests](/runtime/networking/fetch#proxying-requests) for the syntax.

To ignore these variables for one request, pass `proxy: false`:

```ts icon="/icons/typescript.svg" title="direct.ts"
await fetch("https://example.com", { proxy: false });
```
