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

Method do_request_async

src/openrouter/basesdk.py:312–396  ·  view source on GitHub ↗
(
        self,
        hook_ctx: HookContext,
        request: httpx.Request,
        is_error_status_code: Callable[[int], bool],
        stream: bool = False,
        retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
    )

Source from the content-addressed store, hash-verified

310 return http_res
311
312 async def do_request_async(
313 self,
314 hook_ctx: HookContext,
315 request: httpx.Request,
316 is_error_status_code: Callable[[int], bool],
317 stream: bool = False,
318 retry_config: Optional[Tuple[RetryConfig, List[str]]] = None,
319 ) -> httpx.Response:
320 client = self.sdk_configuration.async_client
321 logger = self.sdk_configuration.debug_logger
322
323 hooks = self.sdk_configuration.__dict__["_hooks"]
324
325 async def do():
326 http_res = None
327 try:
328 req = await run_sync_in_thread(
329 hooks.before_request, BeforeRequestContext(hook_ctx), request
330 )
331
332 if "timeout" in request.extensions and "timeout" not in req.extensions:
333 req.extensions["timeout"] = request.extensions["timeout"]
334 logger.debug(
335 "Request:\nMethod: %s\nURL: %s\nHeaders: %s\nBody: %s",
336 req.method,
337 req.url,
338 req.headers,
339 get_body_content(req),
340 )
341
342 if client is None:
343 raise ValueError("client is required")
344
345 http_res = await client.send(req, stream=stream)
346 except Exception as e:
347 _, e = await run_sync_in_thread(
348 hooks.after_error, AfterErrorContext(hook_ctx), None, e
349 )
350
351 if e is not None:
352 logger.debug("Request Exception", exc_info=True)
353 raise e
354
355 if http_res is None:
356 logger.debug("Raising no response SDK error")
357 raise errors.NoResponseError("No response received")
358
359 logger.debug(
360 "Response:\nStatus Code: %s\nURL: %s\nHeaders: %s\nBody: %s",
361 http_res.status_code,
362 http_res.url,
363 http_res.headers,
364 "<streaming response>" if stream else http_res.text,
365 )
366
367 return http_res
368
369 if retry_config is not None:

Callers 15

list_asyncMethod · 0.80
get_credits_asyncMethod · 0.80
generate_asyncMethod · 0.80
get_generation_asyncMethod · 0.80
list_asyncMethod · 0.80
create_asyncMethod · 0.80
delete_asyncMethod · 0.80
get_asyncMethod · 0.80
update_asyncMethod · 0.80

Calls 4

run_sync_in_threadFunction · 0.90
AfterErrorContextClass · 0.90
AfterSuccessContextClass · 0.90
debugMethod · 0.45

Tested by

no test coverage detected