Proxies.ai

Python Requests

Use the Python requests library through Hyperproxy.

The Python requests library and httpx both support proxy configuration. Hyperproxy works with both.

requests

python
Sign in with active access to insert your proxy host. This command remains a template.
import requests

PROXY_URL = "https://proxy-abc123-u1a2b3:password@<proxy-host>:443"

proxies = {
    "http":  PROXY_URL,
    "https": PROXY_URL,
}

# Secret injection via placeholder — Hyperproxy replaces {$OPENAI_API_KEY} with the real key
response = requests.get(
    "https://api.openai.com/v1/models",
    headers={"Authorization": "Bearer {$OPENAI_API_KEY}"},
    proxies=proxies,
)
print(response.json())

Session Reuse

Use a requests.Session to avoid re-establishing proxy tunnels on every call:

python
Sign in with active access to insert your proxy host. This command remains a template.
import requests, os

PROXY_URL = os.environ["CIFP_PROXY_URL"]  # https://user:pass@<proxy-host>:443

session = requests.Session()
session.proxies = {"http": PROXY_URL, "https": PROXY_URL}
# Optional: set common headers once
session.headers["Authorization"] = "Bearer {$OPENAI_API_KEY}"

r1 = session.get("https://api.openai.com/v1/models")
r2 = session.post("https://api.openai.com/v1/chat/completions", json={...})

httpx

python
Sign in with active access to insert your proxy host. This command remains a template.
import httpx

proxies = {"https://": "https://user:pass@<proxy-host>:443"}

with httpx.Client(proxies=proxies) as client:
    r = client.get(
        "https://api.github.com/user",
        headers={"Authorization": "Bearer {$GITHUB_PAT}"},
    )
    print(r.json())

Async (httpx.AsyncClient)

python
Sign in with active access to insert your proxy host. This command remains a template.
import httpx, asyncio

async def main():
    proxy_url = "https://user:pass@<proxy-host>:443"
    async with httpx.AsyncClient(proxies={"https://": proxy_url}) as client:
        r = await client.get(
            "https://api.stripe.com/v1/customers",
            headers={"Authorization": "Bearer {$STRIPE_SECRET_KEY}"},
        )
        print(r.json())

asyncio.run(main())

Environment-Based Configuration

Store proxy configuration in environment variables so your code doesn't need to change between environments:

bash
Sign in with active access to insert your proxy host. This command remains a template.
# .env
CIFP_PROXY_URL="https://proxy-abc123-u1a2b3:password@<proxy-host>:443"
HTTPS_PROXY=$CIFP_PROXY_URL
python
import requests
# requests automatically reads HTTPS_PROXY from the environment
r = requests.get("https://api.openai.com/v1/models",
                 headers={"Authorization": "Bearer {$OPENAI_API_KEY}"})