DEV Community

q2408808
q2408808

Posted on • Originally published at nexa-api.com

Replicate Python SDK Broken on httpx — Fix the ImportError or Switch to NexaAPI

If you've recently upgraded your Python environment and started seeing this error:

ImportError: cannot import name 'Proxy' from 'httpx'
Enter fullscreen mode Exit fullscreen mode

You're not alone. The Replicate Python SDK has a known compatibility issue with newer versions of httpx (tracked in GitHub issue #457). Hundreds of developers have been hit by this after upgrading to Python 3.13 or updating their httpx dependency.


What's Happening

The Replicate Python SDK imports Proxy from httpx internally. When httpx removed or changed the Proxy class in newer versions, the Replicate SDK broke with an ImportError.

Affected scenarios:

  • Upgrading Python to 3.13+
  • Running pip install --upgrade httpx (or any dependency that pulls in a newer httpx)
  • Fresh installs where pip resolves to a newer httpx version
  • Docker containers with updated base images

Quick Fix: Pin httpx

The fastest workaround is to downgrade httpx:

pip install "httpx==0.28.1" replicate
Enter fullscreen mode Exit fullscreen mode

⚠️ Warning: Pinning httpx to an old version may break other libraries in your project (OpenAI SDK, LangChain, FastAPI clients, etc.). This is a band-aid, not a fix.


Why This Keeps Happening

The Replicate Python SDK has a pattern of breaking due to dependency conflicts:

  • v1.0.0: Breaking change — replicate.run() now returns FileOutput objects instead of URLs
  • httpx compatibility: SDK breaks when httpx is updated (open issue as of March 2026)
  • v2.0.0b1 beta: New replicate.use() interface, replicate.stream() deprecated
  • Python 3.14: Incompatibility due to Pydantic V1 usage (open issue)

Every few months, something breaks. If you're building a production app, this is maintenance overhead you shouldn't have to carry.


Permanent Fix: Migrate to NexaAPI in 5 Minutes

NexaAPI has its own clean Python SDK with minimal dependencies — no httpx, no FileOutput objects, no module-level restrictions. Works on Python 3.8+.

Python — Works on Python 3.8+

# Install: pip install nexaapi
# No httpx version pinning required

from nexaapi import NexaAPI

client = NexaAPI(api_key='YOUR_API_KEY')

# Generate an image — clean, simple, no dependency conflicts
response = client.image.generate(
    model='flux-schnell',  # same model available on Replicate
    prompt='A futuristic cityscape at sunset',
    width=1024,
    height=1024
)

print(response.url)  # Direct URL — always works
# Cost: $0.003/image
Enter fullscreen mode Exit fullscreen mode

JavaScript / Node.js

// Install: npm install nexaapi
import NexaAPI from 'nexaapi';

const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });

async function generateImage() {
  const response = await client.image.generate({
    model: 'flux-schnell',
    prompt: 'A futuristic cityscape at sunset',
    width: 1024,
    height: 1024
  });

  return response.url; // Migrated from Replicate in under 5 minutes
}
Enter fullscreen mode Exit fullscreen mode

Before vs After

# BEFORE (Replicate — broken on newer httpx)
import replicate
# ImportError: cannot import name 'Proxy' from 'httpx'

output = replicate.run(
    "black-forest-labs/flux-schnell",
    input={"prompt": "A sunset over mountains"}
)
image_url = output[0].url  # FileOutput object — extra complexity

# AFTER (NexaAPI — works on any Python 3.8+)
from nexaapi import NexaAPI

client = NexaAPI(api_key='YOUR_NEXAAPI_KEY')
response = client.image.generate(
    model='flux-schnell',
    prompt='A sunset over mountains'
)
image_url = response.url  # Direct URL, no dependency issues
Enter fullscreen mode Exit fullscreen mode

Pricing Comparison

Model Replicate NexaAPI Savings
Flux Schnell ~$0.003/image $0.003/image Same price, no dependency hell
SDXL ~$0.005/image $0.003/image 40% cheaper
Flux 2 Pro ~$0.055/image $0.020/image 63% cheaper
Video generation ~$0.10+/run $0.03/run 70% cheaper

Get Started with NexaAPI

56+ AI models. No httpx conflicts. $0.003/image. Just works.


Reference: Replicate Python SDK Issue #457

Top comments (0)