Adding a New AI Provider
Relevant source files
The following files were used as context for generating this wiki page:Read Frog integrates with a variety of AI and translation services, referred to as "Providers". The system is designed to be extensible, allowing for the addition of new built-in providers and user-configured custom providers. This document outlines the architecture and key components involved in managing and adding AI providers for both "Read" (content analysis) and "Translate" (text translation) functionalities.
The provider configuration is a core part of the extension's settings, managed through the options page. It supports over 20 built-in providers and any OpenAI-compatible API. The system leverages the Vercel AI SDK for many integrations.
Provider Architecture
The provider system is built around a central configuration array, providersConfig, which stores the settings for all available providers. Providers are categorized into distinct groups based on their capabilities and configuration method.
Sources: src/utils/constants/providers.ts:503-514, src/locales/en.yml:45-57, src/utils/config/tests/example/v022.ts:9-81
Provider Categories
Providers are organized into three main groups within the "Add New Provider" dialog on the options page. This categorization helps users select the appropriate provider type for their needs.
This diagram shows the three categories of providers available to the user.
Sources: src/locales/en.yml:48-57, src/utils/constants/providers.ts:503-514
| Category | Description | Examples |
|---|---|---|
| Built-in LLM Providers | Large language model providers with pre-filled configurations like baseURL. | OpenAI, DeepSeek, Gemini, Anthropic |
| OpenAI Compatible Custom Providers | Allows configuration of any provider that adheres to the OpenAI API specification. | Zhipu AI, local models |
| Pure Translation Providers | Services focused solely on translation, without LLM capabilities. | DeepLX |
Sources: src/locales/en.yml:48-57, src/utils/constants/providers.ts:503-514
Underlying AI SDKs
The extension integrates a wide array of AI providers by leveraging their respective Vercel AI SDK packages. This modular approach simplifies the integration of new models and services.
Key dependencies from package.json include:
@ai-sdk/openai@ai-sdk/google@ai-sdk/anthropic@ai-sdk/deepseek@ai-sdk/groq@ai-sdk/mistral@openrouter/ai-sdk-provider@ai-sdk/openai-compatibleollama-ai-provider-v2
Sources: package.json:30-50
Provider Configuration Structure
Each provider's settings are stored as an object within the main providersConfig array in the extension's configuration. The structure of this object varies based on the provider's type (e.g., LLM vs. pure translation).
The diagram below illustrates the entity relationship for the provider configuration.
This ER diagram shows the structure of the providersConfig array and its nested objects.
Sources: src/utils/config/tests/example/v022.ts:9-81
Example providersConfig Entry
This code snippet shows a sample configuration for OpenAI and DeepLX providers, illustrating the difference in structure.
[
{
"name": "OpenAI",
"provider": "openai",
"apiKey": "sk-1234567890",
"baseURL": "https://api.openai.com/v1",
"models": {
"read": {
"model": "gpt-4o-mini",
"isCustomModel": true,
"customModel": "gpt-4.1-nano"
},
"translate": {
"model": "gpt-4o-mini",
"isCustomModel": true,
"customModel": "gpt-4.1-nano"
}
}
},
{
"name": "DeepLX",
"provider": "deeplx",
"apiKey": undefined,
"baseURL": "https://deeplx.vercel.app"
}
]
Sources: src/utils/config/tests/example/v022.ts:18-47, 74-79
Adding a New Built-in Provider
Adding a new provider to the core extension requires modifications in several key files. The process involves defining provider constants, adding UI text, and specifying default models.
This flowchart outlines the steps for a developer to add a new built-in provider.
1. Define Provider Metadata
The PROVIDER_ITEMS constant is the central registry for all providers. A new entry must be added here with its logo, name, and website.
| Property | Description | Example |
|---|---|---|
logo | A function returning the path to the provider's logo. | getLobeIconsCDNUrlFn('openai') |
name | The display name of the provider. | 'OpenAI' |
website | The official website for the provider. | 'https://platform.openai.com' |
Sources: src/utils/constants/providers.ts:245-250
2. Define Default Models and Configuration
For LLM providers, default models for both read and translate functions must be defined in DEFAULT_READ_MODELS and DEFAULT_TRANSLATE_MODELS.
A complete default configuration object must then be created in DEFAULT_PROVIDER_CONFIG. This object includes the provider's ID, name, description, and default model selections.
Sources: src/utils/constants/providers.ts:15-121, 123-229, 348-360
3. Add UI Text
User-facing text, such as the provider's description, must be added to the locale files (e.g., src/locales/en.yml) under options.apiProviders.providers.description.
# src/locales/en.yml
options:
apiProviders:
providers:
description:
openai: Provides models like GPT-4o
deepseek: Recommend to use in China
# Add new provider description here
Sources: src/locales/en.yml:76-99
4. Provider-Specific Logic (Optional)
Some providers may require special logic. For example, the DeepLX provider has a custom URL builder to handle different baseURL formats, including those with {{apiKey}} placeholders or specific domains like api.deeplx.org. This logic is tested to ensure it correctly constructs the final API endpoint.
Sources: src/utils/host/translate/api/tests/deeplx-url-builder.test.ts:5-21, 23-37
Summary
The provider system in Read Frog is a well-structured, extensible module that separates configuration, constants, and UI concerns. Adding a new built-in AI provider involves updating a central constants file with metadata and default settings, adding descriptive text for the UI, and potentially including a new AI SDK package. The system's reliance on Vercel AI SDK and a clear configuration schema facilitates the integration of a diverse and growing list of AI services for translation and content analysis.
Sources: src/utils/constants/providers.ts, package.json