Invalid Authorization token when using app.chat.invoke in plugin (Dify v1.4.1) #129

Closed
opened 2026-02-16 00:19:59 -05:00 by yindo · 0 comments
Owner

Originally created by @sergik86 on GitHub (May 30, 2025).

Description:

I’m developing a plugin for Dify version 1.4.1, implemented as an Endpoint class. In the plugin code, I try to call self.session.app.chat.invoke(...), passing the app_id from the plugin settings and using a token obtained from the Plugin Debug tool.

However, the call fails with the error:

{
  "message": "Internal Server Error",
  "code": "unknown"
}

In the Dify API container logs, I see this message:

Exception: Invalid Authorization token.

Steps to reproduce:

  • Create a Python plugin with an Endpoint class.
  • In the _invoke method, call self.session.app.chat.invoke(...) using the app_id from settings and the token from Plugin Debug.
  • Send a request to the plugin (e.g., via Mattermost).
  • Receive a 500 error and the "Invalid Authorization token" message in logs.

Expected behavior:

  • The plugin should successfully invoke the specified app using the token.

Actual behavior:

  • The invocation fails with a 500 error and "Invalid Authorization token" in logs, although the token was taken from Plugin Debug.

Environment info:

  • Dify version: 1.4.1
  • Plugin type: Python Endpoint
  • Deployment: local (docker)
  • dify_plugin>=0.2.0,<0.3.0

Additional notes:

  • It seems the token provided by Plugin Debug is not suitable for calling app.chat.invoke from the plugin.
  • It would be helpful if the error returned a more informative status (e.g., 401 Unauthorized).
  • Please clarify in the docs which token should be used and how to properly call app.chat.invoke from a plugin.

Traceback:
2025-05-30 15:07:03,118.118 ERROR [Dummy-2005] [app.py:875] - Exception on /inner/api/invoke/app [POST] Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper resp = resource(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 199, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/wraps.py", line 76, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/wraps.py", line 85, in decorated_view return view_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/wraps.py", line 109, in decorated_view return view_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/plugin.py", line 220, in post response = PluginAppBackwardsInvocation.invoke_app( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/plugin/backwards_invocation/app.py", line 74, in invoke_app return cls.invoke_chat_app(app, user, conversation_id, query, stream, inputs, files) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/plugin/backwards_invocation/app.py", line 101, in invoke_chat_app return AdvancedChatAppGenerator().generate( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 187, in generate return self._generate( ^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 420, in _generate response = self._handle_advanced_chat_response( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 545, in _handle_advanced_chat_response return generate_task_pipeline.process() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 170, in process return self._to_blocking_response(generator) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 179, in _to_blocking_response raise stream_response.err Exception: Invalid Authorization token.

Originally created by @sergik86 on GitHub (May 30, 2025). **Description**: I’m developing a plugin for Dify version 1.4.1, implemented as an Endpoint class. In the plugin code, I try to call self.session.app.chat.invoke(...), passing the app_id from the plugin settings and using a token obtained from the Plugin Debug tool. However, the call fails with the error: ``` { "message": "Internal Server Error", "code": "unknown" } ``` In the Dify API container logs, I see this message: `Exception: Invalid Authorization token.` **Steps to reproduce**: - Create a Python plugin with an Endpoint class. - In the _invoke method, call self.session.app.chat.invoke(...) using the app_id from settings and the token from Plugin Debug. - Send a request to the plugin (e.g., via Mattermost). - Receive a 500 error and the "Invalid Authorization token" message in logs. **Expected behavior**: - The plugin should successfully invoke the specified app using the token. **Actual behavior**: - The invocation fails with a 500 error and "Invalid Authorization token" in logs, although the token was taken from Plugin Debug. **Environment info**: - Dify version: 1.4.1 - Plugin type: Python Endpoint - Deployment: local (docker) - dify_plugin>=0.2.0,<0.3.0 **Additional notes**: - It seems the token provided by Plugin Debug is not suitable for calling app.chat.invoke from the plugin. - It would be helpful if the error returned a more informative status (e.g., 401 Unauthorized). - Please clarify in the docs which token should be used and how to properly call app.chat.invoke from a plugin. **Traceback**: `2025-05-30 15:07:03,118.118 ERROR [Dummy-2005] [app.py:875] - Exception on /inner/api/invoke/app [POST] Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 489, in wrapper resp = resource(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(**kwargs) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_restful/__init__.py", line 604, in dispatch_request resp = meth(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 199, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/wraps.py", line 76, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/wraps.py", line 85, in decorated_view return view_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/wraps.py", line 109, in decorated_view return view_func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/inner_api/plugin/plugin.py", line 220, in post response = PluginAppBackwardsInvocation.invoke_app( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/plugin/backwards_invocation/app.py", line 74, in invoke_app return cls.invoke_chat_app(app, user, conversation_id, query, stream, inputs, files) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/plugin/backwards_invocation/app.py", line 101, in invoke_chat_app return AdvancedChatAppGenerator().generate( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 187, in generate return self._generate( ^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 420, in _generate response = self._handle_advanced_chat_response( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 545, in _handle_advanced_chat_response return generate_task_pipeline.process() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 170, in process return self._to_blocking_response(generator) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 179, in _to_blocking_response raise stream_response.err Exception: Invalid Authorization token.`
yindo closed this issue 2026-02-16 00:19:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-daemon#129