Skip to content

CopilotHTTPClient

Base classes

Name Children Inherits
AsyncClient
httpx2
An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,

⋔ Inheritance diagram

graph TD
  1463936345["copilot_provider.CopilotHTTPClient"]
  2592624997["httpx2.AsyncClient"]
  3730132019["_client.BaseClient"]
  2751680898["builtins.object"]
  2592624997 --> 1463936345
  3730132019 --> 2592624997
  2751680898 --> 3730132019

🛈 DocStrings

Bases: AsyncClient

Custom client that adds fresh token headers before each request.

Source code in src/llmling_models/providers/copilot_provider.py
class CopilotHTTPClient(AsyncHTTPClient):
    """Custom client that adds fresh token headers before each request."""

    def __init__(self, token_manager: CopilotTokenManager, **kwargs: Any) -> None:
        super().__init__(**kwargs)
        self.token_manager = token_manager

    async def send(self, request: Request, *args: Any, **kwargs: Any) -> Response:
        header = await self.token_manager.generate_headers()
        # Remove conflicting auth headers that OpenAI client sets
        request.headers.pop("x-api-key", None)
        request.headers.pop("authorization", None)
        request.headers.update(header)
        return await super().send(request, *args, **kwargs)

:fa-brands-github: Show source on GitHub