ky Proxy Configuration
← Back to JavaScript / TypeScript Libraries
ky is a tiny, promise-based HTTP client built on the Fetch API. Use ky with ProxyMesh for APIs, scraping, and lightweight requests in Node.js.
The javascript-proxy-headers package provides createProxyKy(), which configures ky with a custom fetch backed by ProxyHeadersAgent so you can send custom proxy headers (e.g. X-ProxyMesh-Country) during HTTPS CONNECT and read X-ProxyMesh-IP from response.proxyHeaders.
Installation
npm install ky javascript-proxy-headers
Or from JSR: npx jsr add @proxymesh/javascript-proxy-headers then npm install ky.
Basic Proxy Configuration
Use createProxyKy() (async) with your ProxyMesh proxy URL. Responses expose proxyHeaders from the CONNECT tunnel:
import { createProxyKy } from 'javascript-proxy-headers/ky';
const api = await createProxyKy({
proxy: 'http://username:password@proxyhost:31280'
});
const response = await api('https://api.ipify.org?format=json');
const data = await response.json();
console.log(data);
console.log(response.proxyHeaders.get('x-proxymesh-ip'));
With IP authentication (whitelist your server IP in the dashboard), omit credentials:
const api = await createProxyKy({
proxy: 'http://proxyhost:port'
});
Custom Proxy Headers
Pass proxyHeaders to send custom headers to the proxy during HTTPS CONNECT (e.g. to select a country with world proxy or open proxy):
import { createProxyKy } from 'javascript-proxy-headers/ky';
const api = await createProxyKy({
proxy: 'http://username:password@proxyhost:31280',
proxyHeaders: { 'X-ProxyMesh-Country': 'US' }
});
const response = await api('https://httpbin.org/ip');
console.log(response.proxyHeaders.get('x-proxymesh-ip'));
ProxyMesh Headers Reference
Send these headers to control proxy behavior:
X-ProxyMesh-Country- Route through a specific country (e.g., "US"). Only works with world proxy or open proxyX-ProxyMesh-IP- Request a specific outgoing IP addressX-ProxyMesh-Not-IP- Exclude specific IPs from rotation
The proxy returns X-ProxyMesh-IP in the response with the IP address used.
Resources
- ky Documentation
- javascript-proxy-headers (ky)
- javascript-proxy-headers on npm
- @proxymesh/javascript-proxy-headers on JSR
- Example Code on GitHub
Related JavaScript / TypeScript Proxy Guides
Explore proxy configuration for other JavaScript / TypeScript HTTP libraries: