mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
How to add llm credentials through dify official apis? #863
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @RobertWangWang on GitHub (Dec 10, 2025).
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Hello! I am trying to add some llm models to the dify framework. It seems I can not find relevant apis to use python to add them. So:
Thank you and have a nice day!
2. Additional context or comments
No response
3. Can you help us with this feature?
@dosubot[bot] commented on GitHub (Dec 10, 2025):
You can add LLM credentials to Dify using its official REST APIs. For provider-level credentials, use the endpoint:
with a JSON payload like:
For model-specific credentials, use:
with:
You can interact with these endpoints using Python's
requestslibrary. Authentication and admin privileges are required for these operations. There are also endpoints for updating, deleting, validating, and switching credentials. See details in the API controller code and model credential controller.Plugins (such as for new LLMs or datasources) must be installed manually using the CLI, e.g.:
There is currently no API for automated plugin downloads. See the GitLab plugin README.
For API-key encryption, Dify uses a hybrid RSA/AES scheme. Tokens are encrypted with a tenant-specific RSA public key and base64 encoded. The encryption function generates a random AES key, encrypts your secret with AES, then encrypts the AES key with RSA. The private key is stored securely per tenant. See the implementation in
encrypter.pyandrsa.py.Let me know if you need example Python code for these API calls!
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@RobertWangWang commented on GitHub (Dec 10, 2025):
can you show me a minimal workable version of python code? thank you
@dosubot[bot] commented on GitHub (Dec 10, 2025):
Here’s a minimal Python example for adding LLM credentials to Dify using its REST API. You don’t need to encrypt credentials client-side—just send them in plaintext; Dify will handle encryption and validation server-side. Required credential fields depend on the provider/model schema (e.g., for OpenAI-compatible providers, usually
api_key,endpoint_url, etc.). If any required fields are missing or invalid, the API will return a validation error.Replace all placeholders with your actual values. If you’re unsure which fields are required, check your provider’s plugin documentation or try adding credentials in the Dify UI to see the expected fields. If you send incomplete or invalid data, the API will return a descriptive error message.
Encryption and validation are handled server-side—no need to do anything special in your Python code.
Reference: Dify API controller and service code
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@RobertWangWang commented on GitHub (Dec 10, 2025):
where can I find the english name for the variable '{provider}' ? I tried using 'deepseek' but it gave me the 400 error:
Provider credential response: {'code': 'invalid_param', 'message': 'Provider deepseek/credentials does not exist.', 'status': 400}
@dosubot[bot] commented on GitHub (Dec 10, 2025):
To find the correct value for the
{provider}variable in Dify's API, use the internal provider ID—not the human-readable name. The provider ID is defined by the plugin or integration and must match exactly what Dify has registered.Here’s how to find it:
/workspaces/current/model-providersand look for theproviderfield in the response. Use that string as{provider}in your requests.openai,anthropic, ordeepseek. For plugin-based providers, it may be a compound string likeopenai_api_compatible/openaiorlanggenius/deepseek/deepseekdepending on how the plugin registers it. Dify will internally expand a single word (e.g.,deepseek) tolanggenius/deepseek/deepseekif needed, but only if the provider is installed and registered in your workspace. If the provider is not registered, you’ll get a 400 error like you saw source.Troubleshooting:
If you get a "provider does not exist" error, double-check that the provider is installed, initialized, and visible in your Dify UI. For DeepSeek, the correct provider ID may be
deepseek,deepseek-chat, ordeepseek-coderdepending on your plugin version and registration source. Always use the exact string shown in your Dify UI or returned by the provider list API.If you need to inspect the canonical list of built-in provider IDs, you can find them in the Dify codebase at
_position.yaml.Let me know if you need help with a specific provider or want to check your provider list via API!
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@RobertWangWang commented on GitHub (Dec 10, 2025):
Another question:
how does dify load the plugins after the plugin is installed?
@dosubot[bot] commented on GitHub (Dec 10, 2025):
Dify loads plugins by scanning specific directories for extension modules at application startup. When you install a plugin (for example, using the CLI or uploading a
.difypkgfile), the plugin files are placed in the appropriate directory. On the next app start or reload, Dify's extension system scans these directories, dynamically imports the plugin modules, and registers any new providers or tools it finds. No hot-reload is needed—just ensure the plugin files are present and restart the app if necessary for them to be picked up. The core scanning and loading logic is implemented in thescan_extensionsmethod of theExtensiblebase class (see code).If you upload a plugin via the web UI or CLI, the plugin daemon processes the package, installs dependencies, and moves the plugin into the active directory. This activation step requires Python and, often, internet access for dependency installation. If the daemon can't activate the plugin (for example, due to missing Python or dependencies), the plugin won't appear in the UI or API, even if the upload succeeds (details).
If a plugin doesn't show up after installation, check the plugin daemon logs for errors, verify that all dependencies are installed, and restart the Dify app to trigger a rescan. In offline or restricted environments, you may need to pre-bundle dependencies or set up a local PyPI mirror for the plugin daemon.
In summary: install the plugin, ensure dependencies are met, and restart the app to load new plugins. No manual registration is needed beyond this process.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other