Blocking calls still performed when using async · Issue #358 · OpenRouterTeam/python-sdk · GitHub
Skip to content

Blocking calls still performed when using async #358

Description

@ab3lson

I am trying to implement this SDK into my Home Assistant integration, but came across an issue. Home Assistant is very picky and wants all work to be performed async off the main thread. I am using the SDK in async as the README describes, but I get warnings stating that blocking is still occurring. See the attached stack trace for two examples.

Please ensure that your async calls take all work off the main thread.

Example stack trace:

2026-06-22 03:01:50.878 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f59d53ba5b0>, '/home/vscode/.local/ha-venv/lib/python3.14/site-packages/certifi/cacert.pem', None, None) inside the event loop by integration 'open_router' at homeassistant/components/open_router/config_flow.py, line 118: client = OpenRouter(api_key=entry.data[CONF_API_KEY]) (offender: /home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/ssl.py, line 729: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+open_router%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations
Traceback (most recent call last):
  File "/home/vscode/.local/ha-venv/bin/hass", line 10, in <module>
    sys.exit(main())
  File "/workspaces/core/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/workspaces/core/homeassistant/runner.py", line 289, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
    self.run_forever()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
    self._run_once()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 2049, in _run_once
    handle._run()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/events.py", line 94, in _run
    self._context.run(self._callback, *self._args)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 675, in start
    task = asyncio.Task(coro, loop=loop, eager_start=True)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 575, in _handle_request
    resp = await request_handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/security_filter.py", line 90, in security_filter_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/forwarded.py", line 86, in forwarded_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/auth.py", line 261, in auth_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/headers.py", line 39, in headers_middleware
    response = await handler(request)
  File "/workspaces/core/homeassistant/helpers/http.py", line 88, in handle
    result = await handler(request, **request.match_info)
  File "/workspaces/core/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/http/data_validator.py", line 72, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/config/config_entries.py", line 313, in post
    return await super()._post_impl(request, data)
  File "/workspaces/core/homeassistant/helpers/data_entry_flow.py", line 80, in _post_impl
    result = await self._flow_mgr.async_init(
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 314, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 482, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 140, in async_step_user
    return await self.async_step_init(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 170, in async_step_init
    await self._get_models()
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 118, in _get_models
    client = OpenRouter(api_key=entry.data[CONF_API_KEY])

2026-06-22 03:01:50.890 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('.security', 'openrouter.components') inside the event loop by integration 'open_router' at homeassistant/components/open_router/config_flow.py, line 118: client = OpenRouter(api_key=entry.data[CONF_API_KEY]) (offender: /home/vscode/.local/ha-venv/lib/python3.14/site-packages/openrouter/components/__init__.py, line 6007: return import_module(modname, __package__)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+open_router%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
Traceback (most recent call last):
  File "/home/vscode/.local/ha-venv/bin/hass", line 10, in <module>
    sys.exit(main())
  File "/workspaces/core/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/workspaces/core/homeassistant/runner.py", line 289, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
    self.run_forever()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
    self._run_once()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 2049, in _run_once
    handle._run()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/events.py", line 94, in _run
    self._context.run(self._callback, *self._args)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 675, in start
    task = asyncio.Task(coro, loop=loop, eager_start=True)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 575, in _handle_request
    resp = await request_handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/security_filter.py", line 90, in security_filter_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/forwarded.py", line 86, in forwarded_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/auth.py", line 261, in auth_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/headers.py", line 39, in headers_middleware
    response = await handler(request)
  File "/workspaces/core/homeassistant/helpers/http.py", line 88, in handle
    result = await handler(request, **request.match_info)
  File "/workspaces/core/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/http/data_validator.py", line 72, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/config/config_entries.py", line 313, in post
    return await super()._post_impl(request, data)
  File "/workspaces/core/homeassistant/helpers/data_entry_flow.py", line 80, in _post_impl
    result = await self._flow_mgr.async_init(
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 314, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 482, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 140, in async_step_user
    return await self.async_step_init(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 170, in async_step_init
    await self._get_models()
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 118, in _get_models
    client = OpenRouter(api_key=entry.data[CONF_API_KEY])

2026-06-22 03:01:50.892 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('.globals', 'openrouter.models.internal') inside the event loop by integration 'open_router' at homeassistant/components/open_router/config_flow.py, line 118: client = OpenRouter(api_key=entry.data[CONF_API_KEY]) (offender: /home/vscode/.local/ha-venv/lib/python3.14/site-packages/openrouter/models/internal/__init__.py, line 22: return import_module(modname, __package__)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+open_router%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
Traceback (most recent call last):
  File "/home/vscode/.local/ha-venv/bin/hass", line 10, in <module>
    sys.exit(main())
  File "/workspaces/core/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/workspaces/core/homeassistant/runner.py", line 289, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
    self.run_forever()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
    self._run_once()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 2049, in _run_once
    handle._run()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/events.py", line 94, in _run
    self._context.run(self._callback, *self._args)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 675, in start
    task = asyncio.Task(coro, loop=loop, eager_start=True)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 575, in _handle_request
    resp = await request_handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/security_filter.py", line 90, in security_filter_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/forwarded.py", line 86, in forwarded_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/auth.py", line 261, in auth_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/headers.py", line 39, in headers_middleware
    response = await handler(request)
  File "/workspaces/core/homeassistant/helpers/http.py", line 88, in handle
    result = await handler(request, **request.match_info)
  File "/workspaces/core/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/http/data_validator.py", line 72, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/config/config_entries.py", line 313, in post
    return await super()._post_impl(request, data)
  File "/workspaces/core/homeassistant/helpers/data_entry_flow.py", line 80, in _post_impl
    result = await self._flow_mgr.async_init(
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 314, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 482, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 140, in async_step_user
    return await self.async_step_init(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 170, in async_step_init
    await self._get_models()
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 118, in _get_models
    client = OpenRouter(api_key=entry.data[CONF_API_KEY])

2026-06-22 03:01:50.894 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('.values', 'openrouter.utils') inside the event loop by integration 'open_router' at homeassistant/components/open_router/config_flow.py, line 118: client = OpenRouter(api_key=entry.data[CONF_API_KEY]) (offender: /home/vscode/.local/ha-venv/lib/python3.14/site-packages/openrouter/utils/__init__.py, line 169: return import_module(modname, __package__)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+open_router%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
Traceback (most recent call last):
  File "/home/vscode/.local/ha-venv/bin/hass", line 10, in <module>
    sys.exit(main())
  File "/workspaces/core/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/workspaces/core/homeassistant/runner.py", line 289, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
    self.run_forever()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
    self._run_once()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/base_events.py", line 2049, in _run_once
    handle._run()
  File "/home/vscode/.local/share/uv/python/cpython-3.14.5-linux-x86_64-gnu/lib/python3.14/asyncio/events.py", line 94, in _run
    self._context.run(self._callback, *self._args)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 675, in start
    task = asyncio.Task(coro, loop=loop, eager_start=True)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_protocol.py", line 575, in _handle_request
    resp = await request_handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_app.py", line 559, in _handle
    return await handler(request)
  File "/home/vscode/.local/ha-venv/lib/python3.14/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/security_filter.py", line 90, in security_filter_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/forwarded.py", line 86, in forwarded_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/auth.py", line 261, in auth_middleware
    return await handler(request)
  File "/workspaces/core/homeassistant/components/http/headers.py", line 39, in headers_middleware
    response = await handler(request)
  File "/workspaces/core/homeassistant/helpers/http.py", line 88, in handle
    result = await handler(request, **request.match_info)
  File "/workspaces/core/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/http/data_validator.py", line 72, in wrapper
    return await method(view, request, data, *args, **kwargs)
  File "/workspaces/core/homeassistant/components/config/config_entries.py", line 313, in post
    return await super()._post_impl(request, data)
  File "/workspaces/core/homeassistant/helpers/data_entry_flow.py", line 80, in _post_impl
    result = await self._flow_mgr.async_init(
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 314, in async_init
    return await self._async_handle_step(flow, flow.init_step, data)
  File "/workspaces/core/homeassistant/data_entry_flow.py", line 482, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 140, in async_step_user
    return await self.async_step_init(user_input)
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 170, in async_step_init
    await self._get_models()
  File "/workspaces/core/homeassistant/components/open_router/config_flow.py", line 118, in _get_models
    client = OpenRouter(api_key=entry.data[CONF_API_KEY])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions