Integration Types
OpenRouter Integration
For models accessed through OpenRouter (RAG, Simple Tool Chat, CustomGPT)Direct SDK Integration
For direct API integration (OpenAI, Claude, Groq, Mistral)Python Stack Integration
OpenRouter-Based Models
Service Layer:src/chatflow_langchain/service/
- Add model service folders (
custom_gpt
,title
,simple_chat
)
src/chatflow_langchain/controller/
- Update controllers for OpenRouter registration and routing
src/prompt/langchain/
- Define prompt templates and configuration
src/customlib/langchain/
- Implement MongoDB persistence
- Token usage tracking
- Streaming response management
Direct SDK Integration
Dependencies:requirements.txt
- Add required SDKs (
openai
,anthropic
,mistral
)
src/chatflow_langchain/service/model/config.py
- Add default behavior and token limits
- Define model metadata
chatopenai_cache.py
- Add caching logic (OpenAI-specific)
- Usage tracking and refresh/expiry logic
src/chatflow_langchain/controller/
- Add routing and provider logic
src/prompt/langchain/
- Align templates for model behavior
Node.js Backend Configuration
Constants Configuration
AI Model Constants:src/config/constants/aimodal.js
- Add new model constant
- Update
OPENROUTER_PROVIDER
,MODAL_NAME
src/config/constants/common.js
- Add model code in
MODEL_CODE
API Key Management
Company Service:src/services/company.js
- Extend
checkApiKey()
for new model support - Define API validation checker function
Next.js Frontend Integration
Assets and Constants
Model Icon: Place logo inpublic/
directory
Constant Mapping: src/utils/constant.ts
- Add model code, display name, image path
- Configure credit info and sequence list
Feature Support
Helper Functions:src/utils/helper.ts
- Update
allowImageGeneration
if supported - Update
allowImageConversation
if supported
Database Schema
Model Collection
Global model metadata:CompanyModel Collection
Company-specific model configuration:Integration Checklist
Component | Purpose | Path |
---|---|---|
Service Layer | Model-specific services | src/chatflow_langchain/service/ |
Controllers | Model routing and registration | src/chatflow_langchain/controller/ |
Prompt Templates | Model prompt configuration | src/prompt/langchain/ |
Callbacks | Token tracking and persistence | src/customlib/langchain/ |
Dependencies | Required SDKs | requirements.txt |
Node Constants | Model constants and codes | src/config/constants/ |
API Key Logic | Validation and checking | src/services/company.js |
Frontend Constants | UI metadata and configuration | src/utils/constant.ts |
Model Assets | Logos and icons | public/ |
Testing Requirements
- End-to-end testing from model selection to response
- Prompt behavior validation
- Tool compatibility verification
- API key validation testing
- Cost tracking accuracy
Always test the complete integration flow including model selection, prompt processing, response generation, and cost tracking before deployment.