Documentation Index
Fetch the complete documentation index at: https://mintlify.com/router-for-me/CLIProxyAPI/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This example demonstrates how to usecoreauth.Manager.HttpRequest and coreauth.Manager.NewHttpRequest to execute arbitrary HTTP requests with provider credentials automatically injected. This is useful when you need to make custom API calls to a provider while leveraging the authentication system.
Use Case
Use this pattern when you need to:- Make custom API calls to a provider beyond standard completion requests
- Execute HTTP requests with automatic credential injection
- Test authentication and header injection logic
- Build custom integrations that need provider credentials
Complete Source Code
Key Concepts
1. Two Approaches for HTTP Requests
The example demonstrates two different approaches:Approach 1: NewHttpRequest + Custom Client
Usecore.NewHttpRequest() to build a prepared request with credentials injected, then execute it with your own HTTP client:
Approach 2: HttpRequest (All-in-One)
Usecore.HttpRequest() to both inject credentials and execute the request:
2. Executor Integration
TheEchoExecutor implements the minimal executor interface with:
Identifier()- Returns the provider key “echo”PrepareRequest()- Injects the Authorization header fromauth.Attributes["api_key"]HttpRequest()- Executes the HTTP request with credentials
3. Authentication
Authentication is provided through theAuth struct:
api_key attribute is extracted by PrepareRequest() and injected as a Bearer token.
4. Request Lifecycle
- Create an
Authobject with credentials - Register an executor with the
Manager - Build or create an HTTP request
- Call
NewHttpRequest()orHttpRequest()on the manager - The manager finds the appropriate executor and calls its
PrepareRequest()method - Credentials are injected into the request headers
- The request is executed and the response is returned
How to Run
- Run the example:
-
The example will make two requests to httpbin.org:
- A GET request using
NewHttpRequest+ manual execution - A POST request using
HttpRequest(automatic execution)
- A GET request using
-
Both responses will show the injected
Authorization: Bearer demo-api-keyheader.
Expected Output
Use Cases
Custom API Endpoints
Make requests to provider-specific endpoints that aren’t part of the standard completion API:File Uploads
Upload files to providers with automatic authentication:Testing Authentication
Test that your executor’s authentication logic works correctly:Related Documentation
- Authentication Manager - Authentication system overview
- Executor Interface - Detailed executor interface documentation
- Custom Provider Example - Full custom provider implementation