Model Design Rules
This document defines in detail the core concepts and structures for Dify model plugin development, including model providers (Provider), AI model entities (AIModelEntity), model types (ModelType), configuration methods (ConfigurateMethod), model features (ModelFeature), parameter rules (ParameterRule), price configuration (PriceConfig), and detailed data structure specifications for various credential modes.
- Model provider rules are based on the Provider entity.
- Model rules are based on the AIModelEntity entity.
All entities below are based on
Pydantic BaseModel
, and can be found in theentities
module.
Provider
provider
(string) Provider identifier, e.g.:openai
label
(object) Provider display name, i18n, can set bothen_US
(English) andzh_Hans
(Chinese) languageszh_Hans
(string) [optional] Chinese label, if not set, will default to usingen_US
en_US
(string) English label
description
(object) [optional] Provider description, i18nzh_Hans
(string) [optional] Chinese descriptionen_US
(string) English description
icon_small
(string) [optional] Provider small icon, stored in the_assets
directory under the corresponding provider implementation directory, same language strategy aslabel
zh_Hans
(string) [optional] Chinese iconen_US
(string) English icon
icon_large
(string) [optional] Provider large icon, stored in the_assets
directory under the corresponding provider implementation directory, same language strategy as labelzh_Hans
(string) [optional] Chinese iconen_US
(string) English icon
background
(string) [optional] Background color value, e.g.: #FFFFFF, if empty, will display the frontend default color valuehelp
(object) [optional] Help informationtitle
(object) Help title, i18nzh_Hans
(string) [optional] Chinese titleen_US
(string) English title
url
(object) Help link, i18nzh_Hans
(string) [optional] Chinese linken_US
(string) English link
supported_model_types
(array[ModelType]) Supported model typesconfigurate_methods
(array[ConfigurateMethod]) Configuration methodsprovider_credential_schema
([ProviderCredentialSchema]) Provider credential specificationsmodel_credential_schema
([ModelCredentialSchema]) Model credential specifications
AIModelEntity
model
(string) Model identifier, e.g.:gpt-3.5-turbo
label
(object) [optional] Model display name, i18n, can set bothen_US
(English) andzh_Hans
(Chinese) languageszh_Hans
(string) [optional] Chinese labelen_US
(string) English label
model_type
(ModelType) Model typefeatures
(array[ModelFeature]) [optional] List of supported featuresmodel_properties
(object) Model propertiesmode
(LLMMode) Mode (available for model typellm
)context_size
(int) Context size (available for model typesllm
andtext-embedding
)max_chunks
(int) Maximum number of chunks (available for model typestext-embedding moderation
)file_upload_limit
(int) Maximum file upload limit, unit: MB. (available for model typespeech2text
)supported_file_extensions
(string) Supported file extension formats, e.g.: mp3,mp4 (available for model typespeech2text
)default_voice
(string) Default voice, required: alloy,echo,fable,onyx,nova,shimmer (available for model typetts
)voices
(list) List of available voices.mode
(string) Voice model. (available for model typetts
)name
(string) Voice model display name. (available for model typetts
)language
(string) Supported languages for voice model. (available for model typetts
)
word_limit
(int) Word limit for single conversion, defaults to paragraph segmentation (available for model typetts
)audio_type
(string) Supported audio file extension formats, e.g.: mp3,wav (available for model typetts
)max_workers
(int) Number of concurrent tasks supported for text-to-audio conversion (available for model typetts
)max_characters_per_chunk
(int) Maximum characters per chunk (available for model typemoderation
)
parameter_rules
(array[ParameterRule]) [optional] Model call parameter rulespricing
([PriceConfig]) [optional] Pricing informationdeprecated
(bool) Whether deprecated. If deprecated, the model list will no longer display it, but those already configured can continue to be used. Default is False.
ModelType
llm
Text generation modeltext-embedding
Text embedding modelrerank
Rerank modelspeech2text
Speech to texttts
Text to speechmoderation
Content moderation
ConfigurateMethod
predefined-model
Predefined model
Indicates that the user only needs to configure unified provider credentials to use predefined models under the provider.
customizable-model
Customizable model
The user needs to add credential configuration for each model.
fetch-from-remote
Fetch from remote
Similar to the predefined-model
configuration method, only unified provider credentials are needed, but the models are fetched from the provider using the credential information.
ModelFeature
agent-thought
Agent reasoning, generally models over 70B have chain-of-thought capabilities.vision
Vision, i.e.: image understanding.tool-call
Tool callingmulti-tool-call
Multiple tool callingstream-tool-call
Streaming tool calling
FetchFrom
predefined-model
Predefined modelfetch-from-remote
Remote model
LLMMode
completion
Text completionchat
Chat
ParameterRule
name
(string) Actual parameter name for model calluse_template
(string) [optional] Use template
For details on using templates, you can refer to the examples in Creating a New Model Provider.
There are 5 pre-configured variable content templates by default:
temperature
top_p
frequency_penalty
presence_penalty
max_tokens
You can directly set the template variable name in use_template
, which will use the default configuration from entities.defaults.PARAMETER_RULE_TEMPLATE without needing to set any parameters other than name
and use_template
. If additional configuration parameters are set, they will override the default configuration. You can refer to openai/llm/gpt-3.5-turbo.yaml
for examples.
label
(object) [optional] Label, i18nzh_Hans
(string) [optional] Chinese labelen_US
(string) English labeltype
(string) [optional] Parameter typeint
Integerfloat
Floating pointstring
Stringboolean
Boolean
help
(string) [optional] Help informationzh_Hans
(string) [optional] Chinese help informationen_US
(string) English help informationrequired
(bool) Whether required, default is False.default
(int/float/string/bool) [optional] Default valuemin
(int/float) [optional] Minimum value, only applicable to numeric typesmax
(int/float) [optional] Maximum value, only applicable to numeric typesprecision
(int) [optional] Precision, decimal places to retain, only applicable to numeric typesoptions
(array[string]) [optional] Dropdown option values, only applicable whentype
isstring
, if not set or is null, then option values are not restricted
PriceConfig
input
(float) Input unit price, i.e., Prompt unit priceoutput
(float) Output unit price, i.e., returned content unit priceunit
(float) Price unit, e.g., if priced per 1M tokens, then the unit token number corresponding to the unit price is0.000001
currency
(string) Currency unit
ProviderCredentialSchema
credential_form_schemas
(array[CredentialFormSchema]) Credential form specifications
ModelCredentialSchema
model
(object) Model identifier, default variable name ismodel
label
(object) Model form item display nameen_US
(string) Englishzh_Hans
(string) [optional] Chinese
placeholder
(object) Model prompt contenten_US
(string) Englishzh_Hans
(string) [optional] Chinese
credential_form_schemas
(array[CredentialFormSchema]) Credential form specifications
CredentialFormSchema
variable
(string) Form item variable namelabel
(object) Form item labelen_US
(string) Englishzh_Hans
(string) [optional] Chinese
type
(FormType) Form item typerequired
(bool) Whether requireddefault
(string) Default valueoptions
(array[FormOption]) Form item attribute specific toselect
orradio
, defines dropdown contentplaceholder
(object) Form item attribute specific totext-input
, form item placeholderen_US
(string) Englishzh_Hans
(string) [optional] Chinese
max_length
(int) Form item attribute specific totext-input
, defines maximum input length, 0 means no limit.show_on
(array[FormShowOnObject]) Display when other form item values meet conditions, empty means always display.
FormType
text-input
Text input componentsecret-input
Password input componentselect
Single-select dropdownradio
Radio componentswitch
Switch component, only supportstrue
andfalse
FormOption
label
(object) Labelen_US
(string) Englishzh_Hans
(string) [optional] Chinese
value
(string) Dropdown option valueshow_on
(array[FormShowOnObject]) Display when other form item values meet conditions, empty means always display.
FormShowOnObject
variable
(string) Other form item variable namevalue
(string) Other form item variable value
Related Resources
- Model Architecture Details - Deep dive into the architecture specifications of model plugins
- Quickly Integrate a New Model - Learn how to apply these rules to add new models
- General Specifications - Understand the configuration of plugin manifest files
- Create a New Model Provider - Develop brand new model provider plugins