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.js
receives the client's request. - Authentication and Routing:
api-server.js
performs 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.js
converts the request body to the format required by the internal target LLM. - Strategy Application:
provider-strategies.js
loads and executes the corresponding strategy based on the target LLM protocol, handling LLM-specific logic (e.g., merging system prompts). - API Call:
adapter.js
obtains the correspondingApiServiceAdapter
instance based on the determined target LLM provider and calls itsgenerateContent
orlistModels
method. This method internally calls the specific*-core.js
module to communicate with the actual LLM. - Response Reception and Conversion (From Internal -> Client): After the LLM returns a native response, the
*-core.js
module returns it toadapter.js
. If the client's desired response format differs from the LLM's native format,convert.js
intervenes again to convert the response to the format expected by the client. - Response Sending:
api-server.js
sends 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.