LANGCHAIN + PROXIES.SX

LangChain is the most widely used LLM application framework. A proxy belongs in the tool that fetches, so wrap httpx in a @tool and hand it to a ReAct agent.

Sign up Get an API key

RUNNABLE SAMPLE

Replace ACCOUNT_ID and PROXY_PASSWORD with the values from GET https://api.proxies.sx/v1/gateway/credentials (header X-API-Key: psx_...). The proxy password is set once in the portal and is not your login password.

# pip install langchain-core langchain-openai langgraph httpx
import uuid, httpx
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

SID = uuid.uuid4().hex[:12]                        # one session id per run
PROXY = f"http://psx_ACCOUNT_ID-peer-gb-rot-sticky-sid-{SID}:PROXY_PASSWORD@gw.proxies.sx:7000"

@tool
def fetch_page(url: str) -> str:
    """Fetch a URL through a UK residential/mobile exit."""
    return httpx.get(url, proxy=PROXY, timeout=30).text[:4000]

agent = create_react_agent(ChatOpenAI(model="gpt-4o-mini"), tools=[fetch_page])
result = agent.invoke({"messages": [("user", "What IP does https://api.ipify.org report?")]})
print(result["messages"][-1].content)

For document loaders (WebBaseLoader, AsyncHtmlLoader) pass requests_kwargs={"proxies": {"http": PROXY, "https": PROXY}} instead.

ROTATION FOR LANGCHAIN

Use: sticky per agent invocation. Generate the session id when you build the tool for a run. Reusing one module-level id across days would pin every run to the same device; a per-run id keeps runs isolated.

Sticky pins the device for that session id, not the exit IP - mobile carriers re-NAT on their own schedule, so a pinned modem can still surface a new address. Without a -sid-, sticky and auto modes do nothing across connections. Unknown tokens are dropped silently, so -session- is not a substitute for -sid-.

CHANGE COUNTRY OR POOL

Edit the username only: peer-us, peer-jp, mbl-gb. peer covers ~127 countries; mbl is carrier modems in US, GB, FR, NL, PL and GE (Georgia). Check stock before you pick: GET https://api.proxies.sx/v1/gateway/pool/stock. $4/GB, $2.40/GB at 250 GB+, duration free.

MORE

/pool/skill.md (full username DSL and API contract) · /pool/ (Pool Gateway) · all integrations · skill.md for this section