How to Add a New Provider to AISuite Using the Provider Interface
To add a new provider to AISuite, subclass the abstract Provider base class from aisuite/provider.py, implement the chat_completion_create method, and register your concrete class in the ProviderFactory._registry dictionary.
AISuite is a unified LLM client framework by Andrew Ng that abstracts multiple AI providers behind a single interface. The library uses a pluggable provider architecture defined in aisuite/provider.py, allowing you to integrate custom LLM backends without altering core client logic. This guide walks through the exact implementation steps to add a new provider to aisuite, referencing the actual source code structure.
Understand the Provider Base Class
All providers in AISuite extend the abstract Provider class located in aisuite/provider.py. This base class defines the contract that every provider must fulfill and supplies HTTP helper methods including _post, _get, and _delete.
The critical method to implement is chat_completion_create, which accepts parameters like messages, model, and temperature, and returns a dictionary compatible with AISuite's ChatCompletionResponse format. The legacy ProviderInterface in aisuite/framework/provider_interface.py exists for backward compatibility, but new implementations should use the Provider base class.
Step 1 – Create the Provider Implementation
Create a new Python file in the aisuite/providers/ directory. Name it according to your service (e.g., mynew_provider.py). Import Provider from aisuite.provider and implement the required abstract methods.
# aisuite/providers/mynew_provider.py
from aisuite.provider import Provider
class MyNewProvider(Provider):
"""Concrete implementation for the MyNew LLM service."""
def __init__(self, api_key: str, endpoint: str = "https://api.mynew.com/v1"):
super().__init__()
self.api_key = api_key
self.endpoint = endpoint
def chat_completion_create(self, messages=None, model=None, temperature=0) -> dict:
"""
Send a chat-completion request to MyNew's REST API.
Returns raw JSON compatible with ChatCompletionResponse.
"""
payload = {
"model": model,
"messages": messages,
"temperature": temperature,
}
headers = {"Authorization": f"Bearer {self.api_key}"}
# Use inherited _post helper from Provider base class
response = self._post(
f"{self.endpoint}/chat/completions",
json=payload,
headers=headers
)
response.raise_for_status()
return response.json()
The Provider base class handles HTTP session management, so you can reuse methods like _post rather than importing requests directly.
Step 2 – Register with the Provider Factory
Open aisuite/provider.py and locate the ProviderFactory class. Add an import for your new provider class and insert an entry into the _registry dictionary, mapping a string identifier to your class.
# aisuite/provider.py
from aisuite.providers.mynew_provider import MyNewProvider
class ProviderFactory:
_registry = {
"openai": OpenAIProvider,
"anthropic": AnthropicProvider,
"azure": AzureProvider,
# ... existing providers ...
"mynew": MyNewProvider, # Register new provider
}
@classmethod
def get_provider(cls, provider_name: str):
return cls._registry.get(provider_name)
The factory uses this registry to instantiate providers dynamically based on configuration strings.
Step 3 – Add Configuration Support
AISuite reads provider-specific settings from YAML or JSON configuration files. To support configuration-driven initialization, extend the schema in aisuite/mcp/config.py to recognize your provider's parameters.
# aisuite.yaml example
providers:
mynew:
api_key: "${MYNEW_API_KEY}"
endpoint: "https://api.mynew.com/v1"
The configuration loader passes these values to your provider's __init__ method when instantiated through the client.
Step 4 – Write Tests and Documentation
Create unit tests under tests/providers/ that mock the HTTP responses and verify chat_completion_create returns the expected structure. Use aisuite/providers/openai_provider.py as a reference implementation for testing patterns.
Add documentation to the project README or a dedicated guide explaining how users can enable the new provider via configuration.
Using Your New Provider
Once registered, users can instantiate your provider through the AISuite client:
from aisuite.client import AISuiteClient
client = AISuiteClient(provider="mynew", config_path="aisuite.yaml")
response = client.chat(
messages=[{"role": "user", "content": "Hello, world!"}],
model="mynew-model-v1"
)
print(response["choices"][0]["message"]["content"])
Summary
- Subclass
Providerfromaisuite/provider.pyrather than the legacyProviderInterface. - Implement
chat_completion_createto handle LLM API calls and return standardized response dictionaries. - Register in
ProviderFactory._registryusing a unique string key inaisuite/provider.py. - Reuse HTTP helpers like
_postand_getinherited from the base class. - Extend configuration schema in
aisuite/mcp/config.pyto support YAML-based setup. - Reference
openai_provider.pyfor implementation patterns and test structure.
Frequently Asked Questions
What is the difference between Provider and ProviderInterface?
The Provider class in aisuite/provider.py is the modern abstract base class that provides HTTP helper methods and defines the chat_completion_create contract. ProviderInterface in aisuite/framework/provider_interface.py is a legacy interface maintained for backward compatibility. New implementations should always extend Provider to access the built-in HTTP utilities and factory registration system.
Do I need to modify the core library files to add a provider?
Yes, you must modify aisuite/provider.py to import your new class and add it to ProviderFactory._registry. Unlike plugin systems that use dynamic discovery, AISuite requires explicit registration in the factory dictionary. However, you do not need to modify the client logic or chat completion handling code.
How do I handle authentication in my custom provider?
Accept authentication parameters in your __init__ method, typically api_key, and store them as instance attributes. Use these credentials in chat_completion_create to set headers (e.g., Authorization: Bearer) when calling self._post or other HTTP helpers. The base class manages the session, but you control the authentication header construction.
Can I use environment variables instead of configuration files?
Yes. While AISuite supports YAML configuration through aisuite/mcp/config.py, your provider's __init__ method can read environment variables directly using os.environ or os.getenv. This allows fallback behavior when configuration files do not specify certain sensitive values like API keys.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →