Space Router — Residential IP Proxy Routing
Route your HTTP requests through residential IP addresses via Space Router's forward proxy.
Setup
The environment variable SPACE_ROUTER_PROXY_URL must contain your full proxy URL including API key credentials:
CODEBLOCK0
The default gateway is https://gateway.spacerouter.org (port 443). For local development the host is typically localhost:8080.
When to Use This Skill
Use Space Router when a task requires any of the following:
- - Accessing a website that blocks datacenter IPs or cloud provider IP ranges
- Web scraping where you need residential IP rotation
- The user explicitly asks you to route traffic through a residential proxy
- A previous HTTP request failed with a 403 or CAPTCHA challenge suggesting IP-based blocking
- The user says to use "Space Router", "residential proxy", or "residential IP"
Do NOT route through the proxy when:
- - Accessing local services (localhost, 127.0.0.1, internal hostnames)
- Accessing APIs that authenticate by IP allowlist (the residential IP will not be allowlisted)
- The user explicitly says to make a direct request
How to Route Traffic
Python SDK (recommended for Python)
CODEBLOCK1
CODEBLOCK2
Async usage:
CODEBLOCK3
JavaScript/TypeScript SDK (recommended for Node.js)
CODEBLOCK4
CODEBLOCK5
CLI (for shell scripts and quick tasks)
CODEBLOCK6
Other useful CLI commands:
CODEBLOCK7
curl / environment variables
Set HTTP_PROXY and HTTPS_PROXY so all HTTP clients in the shell session use the proxy automatically:
CODEBLOCK8
Or pass the proxy explicitly to curl:
CODEBLOCK9
Region Targeting
Route requests through residential IPs in a specific country using ISO 3166-1 alpha-2 codes (e.g. US, KR, JP, DE):
Python:
CODEBLOCK10
JavaScript:
CODEBLOCK11
curl:
CODEBLOCK12
IP Type Filtering
Filter proxy nodes by IP address type: residential, mobile, datacenter, or business.
Python:
CODEBLOCK13
JavaScript:
CODEBLOCK14
SOCKS5 Support
Both SDKs support SOCKS5 as an alternative proxy protocol (default port 1080):
Python:
CODEBLOCK15
JavaScript:
CODEBLOCK16
Verifying the Proxy Works
After configuring the proxy, confirm that traffic is routed through a residential IP:
CODEBLOCK17
The returned IP should differ from your machine's public IP. You can also run the verification script:
CODEBLOCK18
Error Handling
The SDKs raise typed exceptions for proxy-layer errors:
| Exception | HTTP Status | Meaning | What to Do |
|---|
| INLINECODE13 | 407 | API key missing or invalid | Check that the API key has prefix INLINECODE14 |
| INLINECODE15 |
429 | Rate limit exceeded | Wait
retry_after seconds and retry |
|
UpstreamError | 502 | Residential node could not reach target | Retry; the proxy will try a different node |
|
NoNodesAvailableError | 503 | No residential nodes available | Wait and retry; nodes may be temporarily offline |
Python example:
CODEBLOCK19
JavaScript example:
CODEBLOCK20
Response Headers
Space Router adds these headers to proxied responses:
| Header | Meaning |
|---|
| INLINECODE19 | Unique request ID for debugging |
Routing headers sent on the proxy CONNECT request:
| Header | Meaning |
|---|
| INLINECODE20 | Target region (2-letter country code) |
| INLINECODE21 |
Target IP type (residential, mobile, etc.) |
Important Notes
- - The default gateway is
https://gateway.spacerouter.org (HTTPS, port 443). The proxy establishes a CONNECT tunnel for TLS traffic — your end-to-end encryption is preserved. - When using the
SPACE_ROUTER_PROXY_URL env var with curl, the URL scheme may be HTTP even for HTTPS targets. The proxy handles TLS tunneling. - Do not put the proxy URL in
NO_PROXY or bypass lists. - API keys have the prefix
sr_live_ and are passed as the username in the proxy URL (password is empty). - Rate limits are per API key, default 60 requests per minute.
- The Python SDK requires Python >= 3.10. The JS SDK requires Node.js >= 18.
Space Router — 住宅IP代理路由
通过Space Router的正向代理,将您的HTTP请求经由住宅IP地址路由。
设置
环境变量SPACEROUTERPROXY_URL必须包含完整的代理URL,包括API密钥凭证:
SPACEROUTERPROXYURL=https://srliveYOURAPI_KEY@gateway.spacerouter.org
默认网关为https://gateway.spacerouter.org(端口443)。本地开发时,主机通常为localhost:8080。
何时使用此技能
当任务需要以下任一情况时,请使用Space Router:
- - 访问屏蔽数据中心IP或云提供商IP范围的网站
- 需要住宅IP轮换的网络爬取
- 用户明确要求您通过住宅代理路由流量
- 之前的HTTP请求因403错误或CAPTCHA挑战失败,表明存在基于IP的屏蔽
- 用户提到使用Space Router、住宅代理或住宅IP
在以下情况下不要通过代理路由:
- - 访问本地服务(localhost、127.0.0.1、内部主机名)
- 访问通过IP白名单进行身份验证的API(住宅IP不会被列入白名单)
- 用户明确要求直接发起请求
如何路由流量
Python SDK(推荐用于Python)
bash
pip install spacerouter
python
from spacerouter import SpaceRouter
with SpaceRouter(srliveYOURAPIKEY) as client:
resp = client.get(https://example.com)
print(resp.statuscode, resp.requestid)
异步用法:
python
from spacerouter import AsyncSpaceRouter
async with AsyncSpaceRouter(srliveYOURAPIKEY) as client:
resp = await client.get(https://example.com)
print(resp.statuscode, resp.requestid)
JavaScript/TypeScript SDK(推荐用于Node.js)
bash
npm install @spacenetwork/spacerouter
ts
import { SpaceRouter } from @spacenetwork/spacerouter;
const client = new SpaceRouter(srliveYOURAPIKEY);
const resp = await client.get(https://example.com);
console.log(resp.status, resp.requestId);
client.close();
CLI(用于Shell脚本和快速任务)
bash
pip install spacerouter-cli
spacerouter config set api-key srliveYOURAPIKEY
spacerouter request get https://example.com
其他有用的CLI命令:
bash
spacerouter status # 检查服务健康状态
spacerouter api-key list # 列出API密钥
spacerouter node list # 列出代理节点
spacerouter request get https://httpbin.org/ip --region US
curl / 环境变量
设置HTTPPROXY和HTTPSPROXY,使Shell会话中的所有HTTP客户端自动使用代理:
bash
export HTTPPROXY=$SPACEROUTERPROXYURL
export HTTPSPROXY=$SPACEROUTERPROXYURL
或者显式地将代理传递给curl:
bash
curl -x $SPACEROUTERPROXY_URL https://httpbin.org/ip
区域定位
使用ISO 3166-1 alpha-2代码(例如US、KR、JP、DE)通过特定国家的住宅IP路由请求:
Python:
python
client = SpaceRouter(srlivexxx, region=US)
动态更改区域(返回新客户端)
jp
client = client.withrouting(region=JP)
JavaScript:
ts
const client = new SpaceRouter(srlivexxx, { region: US });
const jpClient = client.withRouting({ region: JP });
curl:
bash
curl -x $SPACEROUTERPROXY_URL -H X-SpaceRouter-Region: US https://httpbin.org/ip
IP类型过滤
按IP地址类型过滤代理节点:residential(住宅)、mobile(移动)、datacenter(数据中心)或business(商业)。
Python:
python
client = SpaceRouter(srlivexxx, ip_type=mobile)
JavaScript:
ts
const client = new SpaceRouter(srlivexxx, { ipType: mobile });
SOCKS5支持
两个SDK都支持SOCKS5作为替代代理协议(默认端口1080):
Python:
python
pip install spacerouter[socks]
client = SpaceRouter(srlivexxx, protocol=socks5, gateway_url=socks5://gateway:1080)
JavaScript:
ts
const client = new SpaceRouter(srlivexxx, {
protocol: socks5,
gatewayUrl: socks5://gateway:1080,
});
验证代理是否正常工作
配置代理后,确认流量通过住宅IP路由:
bash
curl -x $SPACEROUTERPROXY_URL https://httpbin.org/ip
返回的IP应与您机器的公网IP不同。您也可以运行验证脚本:
bash
bash {baseDir}/scripts/verify-proxy.sh
错误处理
SDK会针对代理层错误引发类型化异常:
| 异常 | HTTP状态码 | 含义 | 处理方法 |
|---|
| AuthenticationError | 407 | API密钥缺失或无效 | 检查API密钥是否以srlive为前缀 |
| RateLimitError |
429 | 超出速率限制 | 等待retry_after秒后重试 |
| UpstreamError | 502 | 住宅节点无法到达目标 | 重试;代理将尝试不同节点 |
| NoNodesAvailableError | 503 | 无可用住宅节点 | 等待后重试;节点可能暂时离线 |
Python示例:
python
from spacerouter import SpaceRouter, RateLimitError
import time
with SpaceRouter(srlivexxx) as client:
try:
resp = client.get(https://example.com)
except RateLimitError as e:
time.sleep(e.retry_after)
JavaScript示例:
ts
import { SpaceRouter, RateLimitError } from @spacenetwork/spacerouter;
const client = new SpaceRouter(srlivexxx);
try {
const resp = await client.get(https://example.com);
} catch (e) {
if (e instanceof RateLimitError) {
await new Promise((r) => setTimeout(r, e.retryAfter * 1000));
}
}
响应头
Space Router会向代理响应添加以下头信息:
| 头信息 | 含义 |
|---|
| X-SpaceRouter-Request-Id | 用于调试的唯一请求ID |
在代理CONNECT请求上发送的路由头信息:
| 头信息 | 含义 |
|---|
| X-SpaceRouter-Region | 目标区域(2字母国家代码) |
| X-SpaceRouter-IP-Type |
目标IP类型(住宅、移动等) |
重要说明
- - 默认网关为https://gateway.spacerouter.org(HTTPS,端口443)。代理会为TLS流量建立CONNECT隧道——您的端到端加密得以保留。
- 当使用SPACEROUTERPROXYURL环境变量与curl时,即使目标是HTTPS,URL方案也可能是HTTP。代理会处理TLS隧道。
- 不要将代理URL放入NOPROXY或绕过列表中。
- API密钥以srlive为前缀,并作为代理URL中的用户名传递(密码为空)。
- 速率限制按API密钥计算,默认为每分钟60个请求。
- Python SDK需要Python >= 3.10。JS SDK需要Node.js >= 18。