Docs/Quickstart/Python
Python — requests & LangChain
Route any requests-based agent through the AixIps gateway with a standard proxies dict. Routing intent, geography and attribution are declared in the proxy username — no SDK required.
1Prerequisites
Python 3.9+ and an AixIps API key from the console. The snippets use the placeholder sk_test_xxx.
2Install
Only requests is needed — the gateway is a standard HTTP proxy.
pip install requests3Configure the gateway
The proxy username encodes your key plus optional routing parameters: country (geography), type (intent), session (sticky session or Persona), and tag (per-agent cost attribution).
import requests
API_KEY = "sk_test_xxx"
# Gateway credentials: username carries your key and routing params.
# user-{key}[-country-{cc}][-session-{sid}][-type-{intent}][-tag-{agent_tag}]
proxy_user = f"user-{API_KEY}-country-jp-type-explore-tag-demo"
proxies = {
"http": f"http://{proxy_user}:[email protected]:7777",
"https": f"http://{proxy_user}:[email protected]:7777",
}4Make your first request
A 200 response whose origin IP is in the requested region confirms the gateway is routing your traffic.
resp = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(resp.status_code) # 200
print(resp.json()) # {"origin": "203.0.113.42"} <- JP exit, not yours5Verify and wire into LangChain
Check the request appears in the console under Usage, attributed to the demo tag. Any LangChain tool that uses requests can take the same proxies dict.
# LangChain tools that use requests under the hood accept the
# same proxies dict. Example with a custom tool:
from langchain_core.tools import tool
@tool
def fetch_page(url: str) -> str:
"""Fetch a URL through an AixIps residential exit."""
resp = requests.get(url, proxies=proxies, timeout=30)
resp.raise_for_status()
return resp.text[:5000]