Workflow Overview
When a client sends a request to the AIClient-2-API's API service, the general workflow is as follows:
- Request Reception:
api-server.jsreceives the client's request. - Authentication and Routing:
api-server.jsperforms API key authentication and determines the target LLM provider and request type (content generation, model list) based on the request path and header information. - Request Conversion (From Client -> Internal): If the client's request format does not match the native format of the internal target LLM,
convert.jsconverts the request body to the format required by the internal target LLM. - Strategy Application:
provider-strategies.jsloads and executes the corresponding strategy based on the target LLM protocol, handling LLM-specific logic (e.g., merging system prompts). - API Call:
adapter.jsobtains the correspondingApiServiceAdapterinstance based on the determined target LLM provider and calls itsgenerateContentorlistModelsmethod. This method internally calls the specific*-core.jsmodule to communicate with the actual LLM. - Response Reception and Conversion (From Internal -> Client): After the LLM returns a native response, the
*-core.jsmodule returns it toadapter.js. If the client's desired response format differs from the LLM's native format,convert.jsintervenes again to convert the response to the format expected by the client. - Response Sending:
api-server.jssends the final response 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, while providing a unified access experience for users.