Skip to main content

Overview

This example demonstrates how to create a custom AI provider executor and integrate it with the CLI Proxy API server. You’ll learn how to:
  • Implement the Executor interface for a custom provider
  • Register custom translators for request/response transformation
  • Integrate authentication and credentials
  • Register custom models in the model registry
  • Add custom middleware and logging

Use Case

Use this pattern when you need to integrate an AI provider that isn’t natively supported by CLI Proxy API. The example creates a custom provider called “myprov” that can:
  • Handle authentication via API keys
  • Transform requests between OpenAI format and the provider’s format
  • Support both streaming and non-streaming responses
  • Register custom models that appear in /v1/models

Complete Source Code

Key Concepts

1. Executor Interface

The Executor interface requires implementing several methods:
  • Identifier() - Returns a unique string identifier for your provider
  • PrepareRequest() - Injects authentication headers and credentials
  • Execute() - Handles non-streaming requests
  • ExecuteStream() - Handles streaming requests
  • HttpRequest() - Executes arbitrary HTTP requests with credentials
  • CountTokens() - Implements token counting (optional)
  • Refresh() - Refreshes authentication tokens (optional)

2. Request/Response Translation

The init() function registers translators that transform requests and responses between OpenAI format and your provider’s format. In a production implementation, you would implement actual transformation logic here.

3. Authentication

Authentication is handled through the Auth struct with an Attributes map. The example uses an api_key attribute that gets injected as a Bearer token in the PrepareRequest method.

4. Model Registration

The OnAfterStart hook registers custom models that will appear in the /v1/models endpoint, making them discoverable by clients.

5. Custom Middleware

The example shows how to add custom middleware and request logging through the builder’s WithServerOptions method.

How to Run

  1. Create a config.yaml file with your server configuration:
  1. Run the example:
  1. The server will start and register the custom “myprov” provider with the model “myprov-pro-1”.

Configuration

You can configure the custom provider through the Auth.Attributes map:
  • api_key - API key for authentication (injected as Bearer token)
  • endpoint - Custom upstream endpoint URL (defaults to httpbin.org in the example)