Workflow Overview
When a client sends a request to AIClient-2-API, the general workflow is as follows:
- Request Reception:
api-server.jsreceives the client's request. - Auth & Protocol Identification: The system validates the API key, and
api-manager.jsidentifies the request protocol (OpenAI/Gemini/Claude). - Request Conversion (Converter):
ConverterFactoryconverts the request body into a unified internal format based on the identified protocol. - Routing & Provider Scheduling: In
automode, the system selects the optimal provider pool fromProviderPoolManagerbased on the requested model name. - Adapter Execution (Adapter):
src/providers/adapter.jscalls the corresponding Core module (e.g.,gemini-core.js) to communicate with the actual LLM API. - Response Conversion (Converter): Once the LLM returns a native response, the converter transforms it back into the protocol format expected by the client.
- Plugin Hook Triggering: Before and after sending the response, the system triggers plugin hooks (e.g.,
onStreamChunk), allowing custom logic to intercept and process data. - Response Sending: The final result is sent back to the client.
Through this layered and modular design, AIClient-2-API achieves a high degree of flexibility and maintainability, allowing for easy expansion to support new LLMs or API formats.