Hermes Bot commited on
Commit
167678e
·
unverified ·
1 Parent(s): 1f55836

fix: use httpx.Client(trust_env=True) to route through Space environment proxies

Browse files
Files changed (1) hide show
  1. shared/inference_client.py +3 -2
shared/inference_client.py CHANGED
@@ -146,7 +146,7 @@ def generate(
146
  use_token = token or HF_TOKEN
147
 
148
  # Call direct HF serverless Inference API
149
- url = f"https://huggingface.co/api/models/{use_model}"
150
  headers = {}
151
  if use_token:
152
  headers["Authorization"] = f"Bearer {use_token}"
@@ -160,7 +160,8 @@ def generate(
160
  }
161
  }
162
 
163
- resp = httpx.post(url, json=payload, headers=headers, timeout=30.0)
 
164
  if resp.status_code != 200:
165
  raise RuntimeError(f"HF Inference API Error {resp.status_code}: {resp.text}")
166
 
 
146
  use_token = token or HF_TOKEN
147
 
148
  # Call direct HF serverless Inference API
149
+ url = f"https://api-inference.huggingface.co/models/{use_model}"
150
  headers = {}
151
  if use_token:
152
  headers["Authorization"] = f"Bearer {use_token}"
 
160
  }
161
  }
162
 
163
+ with httpx.Client(trust_env=True) as http_client:
164
+ resp = http_client.post(url, json=payload, headers=headers, timeout=30.0)
165
  if resp.status_code != 200:
166
  raise RuntimeError(f"HF Inference API Error {resp.status_code}: {resp.text}")
167