MCPcopy Create free account
hub / github.com/OpenRouterTeam/python-sdk / do_request

Function do_request

src/openrouter/utils/retries.py:192–220  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190 if retries.config.strategy == "backoff":
191
192 def do_request() -> httpx.Response:
193 res: httpx.Response
194 try:
195 res = func()
196
197 for code in retries.status_codes:
198 if "X" in code.upper():
199 code_range = int(code[0])
200
201 status_major = res.status_code / 100
202
203 if code_range <= status_major < code_range + 1:
204 raise TemporaryError(res)
205 else:
206 parsed_code = int(code)
207
208 if res.status_code == parsed_code:
209 raise TemporaryError(res)
210 except (httpx.NetworkError, httpx.TimeoutException) as exception:
211 if retries.config.retry_connection_errors:
212 raise
213
214 raise PermanentError(exception) from exception
215 except TemporaryError:
216 raise
217 except Exception as exception:
218 raise PermanentError(exception) from exception
219
220 return res
221
222 return retry_with_backoff(
223 do_request,

Callers

nothing calls this directly

Calls 2

TemporaryErrorClass · 0.85
PermanentErrorClass · 0.85

Tested by

no test coverage detected