Skip to content

requesty_provider

Class info

Classes

Name Children Inherits
RequestyProvider
llmling_models.providers.requesty_provider
Provider for Requesty API.

    🛈 DocStrings

    Requesty provider implementation.

    RequestyProvider

    Bases: Provider[AsyncOpenAI]

    Provider for Requesty API.

    Source code in src/llmling_models/providers/requesty_provider.py
    class RequestyProvider(Provider[AsyncOpenAI]):
        """Provider for Requesty API."""
    
        @property
        def name(self) -> str:
            """The provider name."""
            return "requesty"
    
        @property
        def base_url(self) -> str:
            """The base URL for the provider API."""
            return os.environ.get("REQUESTY_BASE_URL", "https://router.requesty.ai/v1")
    
        @property
        def client(self) -> AsyncOpenAI:
            """Get a client configured for Requesty."""
            return self._client
    
        @overload
        def __init__(self) -> None: ...
    
        @overload
        def __init__(self, *, api_key: str) -> None: ...
    
        @overload
        def __init__(self, *, api_key: str, http_client: AsyncHTTPClient) -> None: ...
    
        @overload
        def __init__(self, *, openai_client: AsyncOpenAI | None = None) -> None: ...
    
        def __init__(
            self,
            *,
            api_key: str | None = None,
            openai_client: AsyncOpenAI | None = None,
            http_client: AsyncHTTPClient | None = None,
        ) -> None:
            """Initialize provider for Requesty.
    
            Args:
                api_key: The API key to use for authentication.
                         If not provided, the `REQUESTY_API_KEY`
                         environment variable will be used if available.
                openai_client: An existing AsyncOpenAI client to use. If provided, other parameters must be None.
                http_client: An existing AsyncHTTPClient to use for making HTTP requests.
            """  # noqa: E501
            api_key = api_key or os.environ.get("REQUESTY_API_KEY")
    
            if api_key is None and openai_client is None:
                msg = (
                    "Set the `REQUESTY_API_KEY` environment variable or pass it via "
                    "`RequestyProvider(api_key=...)` to use the Requesty provider."
                )
                raise ValueError(msg)
    
            if openai_client is not None:
                assert http_client is None, "Cannot provide both `openai_client` and `http_client`"
                assert api_key is None, "Cannot provide both `openai_client` and `api_key`"
                self._client = openai_client
            else:
                if http_client is None:
                    # Create HTTP client with Requesty headers
                    http_client = _create_http_client()
    
                    # Add Requesty-specific headers
                    http_client.headers["HTTP-Referer"] = "https://llmling.dev"
                    http_client.headers["X-Title"] = "LLMling"
    
                self._client = AsyncOpenAI(
                    base_url=self.base_url,
                    api_key=api_key,
                    http_client=http_client,
                )
    

    base_url property

    base_url: str
    

    The base URL for the provider API.

    client property

    client: AsyncOpenAI
    

    Get a client configured for Requesty.

    name property

    name: str
    

    The provider name.

    __init__

    __init__() -> None
    
    __init__(*, api_key: str) -> None
    
    __init__(*, api_key: str, http_client: AsyncClient) -> None
    
    __init__(*, openai_client: AsyncOpenAI | None = None) -> None
    
    __init__(
        *,
        api_key: str | None = None,
        openai_client: AsyncOpenAI | None = None,
        http_client: AsyncClient | None = None,
    ) -> None
    

    Initialize provider for Requesty.

    Parameters:

    Name Type Description Default
    api_key str | None

    The API key to use for authentication. If not provided, the REQUESTY_API_KEY environment variable will be used if available.

    None
    openai_client AsyncOpenAI | None

    An existing AsyncOpenAI client to use. If provided, other parameters must be None.

    None
    http_client AsyncClient | None

    An existing AsyncHTTPClient to use for making HTTP requests.

    None
    Source code in src/llmling_models/providers/requesty_provider.py
    def __init__(
        self,
        *,
        api_key: str | None = None,
        openai_client: AsyncOpenAI | None = None,
        http_client: AsyncHTTPClient | None = None,
    ) -> None:
        """Initialize provider for Requesty.
    
        Args:
            api_key: The API key to use for authentication.
                     If not provided, the `REQUESTY_API_KEY`
                     environment variable will be used if available.
            openai_client: An existing AsyncOpenAI client to use. If provided, other parameters must be None.
            http_client: An existing AsyncHTTPClient to use for making HTTP requests.
        """  # noqa: E501
        api_key = api_key or os.environ.get("REQUESTY_API_KEY")
    
        if api_key is None and openai_client is None:
            msg = (
                "Set the `REQUESTY_API_KEY` environment variable or pass it via "
                "`RequestyProvider(api_key=...)` to use the Requesty provider."
            )
            raise ValueError(msg)
    
        if openai_client is not None:
            assert http_client is None, "Cannot provide both `openai_client` and `http_client`"
            assert api_key is None, "Cannot provide both `openai_client` and `api_key`"
            self._client = openai_client
        else:
            if http_client is None:
                # Create HTTP client with Requesty headers
                http_client = _create_http_client()
    
                # Add Requesty-specific headers
                http_client.headers["HTTP-Referer"] = "https://llmling.dev"
                http_client.headers["X-Title"] = "LLMling"
    
            self._client = AsyncOpenAI(
                base_url=self.base_url,
                api_key=api_key,
                http_client=http_client,
            )