Home / Function/ _resolve_sync_and_async_api_keys() — langchain Function Reference

_resolve_sync_and_async_api_keys() — langchain Function Reference

Architecture documentation for the _resolve_sync_and_async_api_keys() function in _client_utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  076a7d30_885e_1ffb_85a5_96b646443089["_resolve_sync_and_async_api_keys()"]
  15814c96_373f_f86b_f2fa_7830cc4d0ae3["_client_utils.py"]
  076a7d30_885e_1ffb_85a5_96b646443089 -->|defined in| 15814c96_373f_f86b_f2fa_7830cc4d0ae3
  style 076a7d30_885e_1ffb_85a5_96b646443089 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/_client_utils.py lines 115–142

def _resolve_sync_and_async_api_keys(
    api_key: SecretStr | Callable[[], str] | Callable[[], Awaitable[str]],
) -> tuple[str | None | Callable[[], str], str | Callable[[], Awaitable[str]]]:
    """Resolve sync and async API key values.

    Because OpenAI and AsyncOpenAI clients support either sync or async callables for
    the API key, we need to resolve separate values here.
    """
    if isinstance(api_key, SecretStr):
        sync_api_key_value: str | None | Callable[[], str] = api_key.get_secret_value()
        async_api_key_value: str | Callable[[], Awaitable[str]] = (
            api_key.get_secret_value()
        )
    elif callable(api_key):
        if inspect.iscoroutinefunction(api_key):
            async_api_key_value = api_key
            sync_api_key_value = None
        else:
            sync_api_key_value = cast(Callable, api_key)

            async def async_api_key_wrapper() -> str:
                return await asyncio.get_event_loop().run_in_executor(
                    None, cast(Callable, api_key)
                )

            async_api_key_value = async_api_key_wrapper

    return sync_api_key_value, async_api_key_value

Domain

Subdomains

Frequently Asked Questions

What does _resolve_sync_and_async_api_keys() do?
_resolve_sync_and_async_api_keys() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/_client_utils.py.
Where is _resolve_sync_and_async_api_keys() defined?
_resolve_sync_and_async_api_keys() is defined in libs/partners/openai/langchain_openai/chat_models/_client_utils.py at line 115.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free