Repository navigation
feat(openapi): add delete endpoints for models and model credentials - #45340
Open
mesrop2008 wants to merge 8 commits into
Open
mesrop2008 wants to merge 8 commits into
mesrop2008 wants to merge 8 commits into
Conversation
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45340 +/- ##
=======================================
Coverage 89.77% 89.77%
=======================================
Files 6239 6239
Lines 390902 390917 +15
Branches 79285 79285
=======================================
+ Hits 350933 350952 +19
+ Misses 33870 33866 -4
Partials 6099 6099
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-02 14:13:33.023314244 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-02 14:13:18.843231808 +0000
@@ -2522,6 +2522,10 @@
--> tests/unit_tests/controllers/openapi/test_human_input_form.py:203:22
ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
--> tests/unit_tests/controllers/openapi/test_human_input_form.py:229:20
+ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
+ --> tests/unit_tests/controllers/openapi/test_model_providers.py:330:20
+ERROR Object of class `FunctionType` has no attribute `__handler__` [missing-attribute]
+ --> tests/unit_tests/controllers/openapi/test_model_providers.py:351:20
ERROR Object of class `FunctionType` has no attribute `view_class` [missing-attribute]
--> tests/unit_tests/controllers/openapi/test_oauth_device.py:91:16
ERROR Object of class `FunctionType` has no attribute `view_class` [missing-attribute]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #45219
Summary
This PR adds OpenAPI delete endpoints for self-hosted / custom models and individual model credentials under
/openapi/v1/workspaces/{workspace_id}/model-providers/{provider}/...:DELETE /openapi/v1/workspaces/{workspace_id}/model-providers/{provider}/models(delete.model):model(string) andmodel_type(ModelType).ModelProviderService().remove_model(...).200 OKwith{"result": "success"}(SimpleResultResponse).DELETE /openapi/v1/workspaces/{workspace_id}/model-providers/{provider}/models/credentials/{credential_id}(delete.model.credential):credential_id(string).model(string) andmodel_type(ModelType).ModelProviderService().remove_model_credential(...).200 OKwith{"result": "success"}(SimpleResultResponse).Motivation & Context
Previously, OpenAPI operations existed to inspect providers, list models, and create/update models and credentials, but no operations existed to delete them. This forced CLI and automated script users (such as
difyctlsetup/teardown pipelines) to fall back to the internal Console API (DELETE /console/api/workspaces/current/model-providers/{provider}/models) to clean up self-hosted models (e.g.langgenius/openai_api_compatible).Because
difyctlautomatically builds its command tree from the OpenAPI catalog (GET /openapi/v1/_catalog), addingdelete.modelanddelete.model.credentialenables:difyctl delete model --provider <id> --model <name> --model-type <type>difyctl delete model credential --provider <id> --model <name> --model-type <type> --credential-id <id>Both operations are marked destructive and protected by
_MANAGE(RBACPermission.CREDENTIAL_MANAGEand privileged admin roles).Testing & Verifications
1. Unit Tests
api/tests/unit_tests/controllers/openapi/test_model_providers.py:test_delete_model: Verifies parameter extraction, context binding, and delegation toModelProviderService.remove_model.test_delete_model_credential: Verifies parameter extraction, credential ID lookup, and delegation toModelProviderService.remove_model_credential.200 OK,401 Unauthorized,403 Forbidden,404 Not Found) across the OpenAPI auth matrix inapi/tests/unit_tests/controllers/openapi/auth/test_requirements.py:models.deletemodels.credential.deletetest__catalog.py,test__contract.py).2. Live Database & Runtime Verification
port 5433) and Redis (port 6380):ProviderModel) and multiple credentials (ProviderModelCredential) in the database.DELETE .../models/credentials/{cred_id2}request with OAuth Bearer token and current catalog hash (X-Dify-Catalog).200 OK{"result": "success"}.cred_id2was deleted from PostgreSQL whilecred_id1remained intact.DELETE .../modelsrequest with Bearer auth andX-Dify-Catalog.200 OK{"result": "success"}.ProviderModelrecord and all associated credentials were removed.Screenshots
N/A (backend changes only)
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods