mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
openAI compatible add-on faild to add LLM #860
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 @bionexit on GitHub (Dec 8, 2025).
Self Checks
Dify version
1.10.1-fix1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Tried several editions, all failed to connect LLM
✔️ Expected Behavior
new install dify 1.10.1-fix1 with nerdctl compose [similar as docker compose]
install OpenAI-API-compatible 0.0.26
input elements of OAC add-one and submit
error shows
❌ Actual Behavior
No response
@dosubot[bot] commented on GitHub (Dec 8, 2025):
This is a known bug in recent Dify versions: the UnboundLocalError happens because the plugin credential validation code tries to access the response variable before it's assigned, especially when credentials (like API keys) are missing or empty. This breaks the add-on flow for OpenAI-compatible LLMs and similar plugins in self-hosted Docker setups [details & workaround].
Workaround:
Patch the backend to skip credential validation if credentials are empty. In your Dify install, edit
api/core/plugin/impl/model.pyand update thevalidate_model_credentialsmethod like this:After saving, restart your API container. This is safe for self-hosted setups and only affects models with empty credentials [source].
Other things to check:
host.docker.internalor your host's LAN IP for endpoints, notlocalhostor127.0.0.1[network tips].If you can't patch the code, some users have worked around this by downgrading to Dify 0.15.3, which has more permissive credential validation logic [reference].
Let me know if you need step-by-step instructions for any of these changes.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@dosubot[bot] commented on GitHub (Dec 8, 2025):
This is a known bug in the OpenAI-compatible add-on for Dify when running self-hosted via Docker. The UnboundLocalError happens because the plugin's credential validation code tries to use the
responsevariable before it's assigned, especially if credentials are missing or empty. This breaks the add-on flow and prevents adding LLMs.Workaround:
Patch the backend code in
api/core/plugin/impl/model.pyin thevalidate_model_credentialsmethod. Add this check at the top of the method:This skips validation if credentials are empty and avoids the error. After making this change, restart your API container to apply the fix. This workaround is safe for self-hosted setups and only affects models with empty credentials.
Reference
If you can't patch the code, some users have worked around this by downgrading to Dify 0.15.3, which has more permissive credential validation logic, but this is not ideal for most setups.
Other things to check:
host.docker.internalor your host's LAN IP for endpoints, notlocalhostor127.0.0.1.An official fix may be pending in future releases. If you have constraints (like not being able to patch code), let me know so I can suggest alternatives.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@bionexit commented on GitHub (Dec 8, 2025):
@dosu
hence i deployed as docker-compose, how i make the modification
@dosubot[bot] commented on GitHub (Dec 8, 2025):
In your docker-compose deployment, the backend code is inside the container image and not directly editable from the host. You have two options to apply the patch:
Option 1: Patch inside the running container (quick, but not persistent)
nerdctl compose exec api /bin/bashif you're using nerdctl)validate_model_credentialsmethod:nerdctl compose restart api)Note: This change will be lost if you update or recreate the container.
Option 2: Rebuild the image with your patch (persistent)
api/core/plugin/impl/model.py.docker-compose.yamlto usemy-dify-api:patchedfor theapiservice.nerdctl compose up -d --force-recreate api)After patching, retry adding your LLM and check the logs for errors. If you update Dify in the future, you’ll need to reapply your patch.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@bionexit commented on GitHub (Dec 8, 2025):
@dosu
I rebuild the docker image followed your instruction, modified model.py as follwing
NOT WORKING , STILL IN ERROR
@dosubot[bot] commented on GitHub (Dec 8, 2025):
The error is still happening because the patch was only added to validate_provider_credentials, not to validate_model_credentials—which is the method actually used during the failing OpenAI-compatible add-on flow. To fix this, you need to add the following at the very start of the validate_model_credentials method in core/plugin/impl/model.py:
This will skip validation if credentials are empty and prevent the UnboundLocalError. After making this change, rebuild your API Docker image and restart the API container. This fix is confirmed by multiple sources and is the recommended workaround for this bug (reference).
If you’re using HTTPS endpoints with self-signed certificates, you may also need to disable certificate verification in the plugin code or import your LLM server’s cert into the plugin-daemon container to avoid related errors.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
@bionexit commented on GitHub (Dec 8, 2025):
LLM back end startup script
@dosu
this actions is done,still in error
@dosubot[bot] commented on GitHub (Dec 25, 2025):
Hi, @bionexit. I'm Dosu, and I'm helping the dify-official-plugins team manage their backlog and am marking this issue as stale.
Issue Summary:
validate_model_credentialsto skip validation if credentials are empty.Next Steps:
Thank you for your understanding and contribution!
@realamd commented on GitHub (Jan 11, 2026):
@dosu
Hi dosubot, I have applied the Option 2 and restart api successfully. But when I add local model, it still report the error.
What should I do?
@Alvs10735 commented on GitHub (Feb 9, 2026):
I've got the same error
dify
Version1.12.1
plugin OpenAI-API-compatible
version 0.0.34
I have used Option 2
error still the same
@bionexit commented on GitHub (Feb 9, 2026):
Run a curl for a post requst to the Llm server within credential inside the docker. my error happened due to network policy block the connection.
Wish help.