Class CopilotRequestHandler

java.lang.Object
com.github.copilot.CopilotRequestHandler

public class CopilotRequestHandler extends Object
The base class for SDK consumers who want to observe or replace the LLM inference requests the runtime issues (for both CAPI and BYOK providers).

When set as the requestHandler on CopilotClientOptions, the runtime routes its model-layer HTTP and WebSocket traffic through this handler instead of issuing the calls itself. Subclass and override sendRequest(HttpRequest, CopilotRequestContext) to mutate or replace HTTP calls, or openWebSocket(CopilotRequestContext) to mutate the handshake or return a fully custom CopilotWebSocketHandler.

Since:
1.0.0
  • Constructor Details

    • CopilotRequestHandler

      public CopilotRequestHandler()
  • Method Details

    • httpClient

      protected HttpClient httpClient()
      The HttpClient used to forward HTTP requests. Override to supply a custom client (proxy, TLS, timeouts). The default never follows redirects, so 3xx responses are forwarded verbatim.
      Returns:
      the HTTP client
    • sendRequest

      protected HttpResponse<InputStream> sendRequest(HttpRequest request, CopilotRequestContext ctx) throws Exception
      Forwards an HTTP request and returns the upstream response. The default sends request through httpClient() and cancels the in-flight call when the runtime cancels the request. Override to mutate the request before sending, post-process the response, or replace the call entirely.
      Parameters:
      request - the request built from the runtime's inference request
      ctx - the per-request context
      Returns:
      the upstream response, with the body as an InputStream
      Throws:
      Exception - if the request could not be completed
    • openWebSocket

      protected CopilotWebSocketHandler openWebSocket(CopilotRequestContext ctx) throws Exception
      Returns a per-connection WebSocket handler for a WebSocket request. The default opens a transparent forwarding connection to the request URL. Override to mutate the handshake (via ctx) or return a fully custom handler.
      Parameters:
      ctx - the per-request context
      Returns:
      the WebSocket handler
      Throws:
      Exception - if the handler could not be created