Python Requests
Use the Python requests library through CIFP.
The Python requests library and httpx both support proxy configuration. CIFP works with both.
requests
python
import requests
PROXY_URL = "https://proxy-abc123-u1a2b3:password@proxy-abc123.proxy.cifp.vril.dev:3128"
proxies = {
"http": PROXY_URL,
"https": PROXY_URL,
}
# Secret injection via placeholder — CIFP 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
import requests, os
PROXY_URL = os.environ["CIFP_PROXY_URL"] # https://user:pass@proxy-id.proxy.cifp.vril.dev:3128
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
import httpx
proxies = {"https://": "https://user:pass@proxy-abc123.proxy.cifp.vril.dev:3128"}
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
import httpx, asyncio
async def main():
proxy_url = "https://user:pass@proxy-abc123.proxy.cifp.vril.dev:3128"
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
# .env
CIFP_PROXY_URL=https://proxy-abc123-u1a2b3:password@proxy-abc123.proxy.cifp.vril.dev:3128
HTTPS_PROXY=$CIFP_PROXY_URLpython
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}"})