Skip to content

Version 2.0.0-beta.2: Chat annotations Api Error #25506

Closed

Description

@guoshiqiufeng

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

2.0.0-beta.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Chat annotations Api Error

Request

  • request url:http://localhost/v1/apps/annotations,
  • request method:POST,
  • request headers:[Content-Type:"application/json", Accept:"application/json", Authorization:"***", Content-Length:"129"],
  • request body:{"apiKey":"app-oSWO5BZJrrauObe9NArLhrUz","userId":"1504","question":"Test annotation question","answer":"Test annotation answer"}

Response

  • requestId:e2901c68-819c-4675-ac36-018235be6774
  • status:500 INTERNAL_SERVER_ERROR
  • headers:[Server:"nginx/1.29.1", Date:"Thu, 11 Sep 2025 02:07:03 GMT", Content-Type:"application/json", Content-Length:"66", Connection:"keep-alive", Access-Control-Allow-Origin:"*", X-Version:"2.0.0-beta2", X-Env:"PRODUCTION", Vary:"Cookie"],
  • executionTime:18ms,
  • body:{"message":"Internal Server Error","code":"unknown","status":500}

✔️ Expected Behavior

Normal Creation

❌ Actual Behavior

No response

Activity

  1. added
    🐞 bug
    on Sep 11, 2025
  2. dosubot commented on Sep 11, 2025

    @dosubot

    The 500 INTERNAL_SERVER_ERROR is likely caused by either an incorrect endpoint or an invalid request payload. For creating chat annotations, the correct endpoint is /v1/apps/{app_id}/annotations (with the specific app_id in the URL), not /v1/apps/annotations. The JSON body should only include the fields question and answer—do not include apiKey or userId in the body. Authentication is handled via the Authorization header (Bearer token), and user context is managed internally, not by passing userId in the payload.

    Recent changes also fixed routing conflicts for this endpoint, so using the correct URL and payload structure is important to avoid server errors (see implementation details). If you still get a 500 error after correcting these, check your Docker 'api' container logs for more details (docker-compose logs api) (log guidance). Also, ensure your user has editor permissions for the app.

    To reply, just mention @dosu.


    How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

  3. quicksandznzn commented on Sep 11, 2025

    @quicksandznzn
    Contributor

    maybe this pr #24996 caused an error

  4. added
    Knowledge Pipeline
    on Sep 11, 2025
  5. dosubot commented on Oct 12, 2025

    @dosubot

    Hi, @guoshiqiufeng. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

    Issue Summary:

    • You reported a 500 Internal Server Error when using the chat annotations API on version 2.0.0-beta.2 with a self-hosted Docker setup.
    • The error occurs when POSTing to /v1/apps/annotations instead of the correct endpoint /v1/apps/{app_id}/annotations.
    • The request body should only include question and answer fields, and authentication must be done via the Authorization header.
    • A recent PR (more assert #24996) was suggested as a possible cause of the error.
    • Recommendations included checking Docker API container logs and verifying user permissions for further diagnosis.

    Next Steps:

    • Please confirm if this issue persists with the latest version of Dify and if the endpoint and request format are correctly used.
    • If the problem is still relevant, you can keep the discussion open by commenting here; otherwise, I will automatically close this issue in 15 days.

    Thank you for your understanding and contribution!

  6. guoshiqiufeng commented on Oct 13, 2025

    @guoshiqiufeng
    ContributorAuthor

    The problem still exists and was present in 1.9.x as well.

  7. Cursx commented on Oct 15, 2025

    @Cursx
    Contributor

    The problem still exists and was present in 1.9.x as well.

    I know how to fix it, but I don't know the cause. You can try the following approach:
    curl 'http://192.168.1.246/console/api/apps/{your code}/annotations?page=1&limit=10&keyword='
    -H 'authorization: Bearer {your key}' \

    and this is my response
    {
    "data": [
    {
    "id": "d869e27c-52a0-47cd-8069-5d6e224b547a",
    "question": "test",
    "answer": "ok",
    "hit_count": 0,
    "created_at": 1760507636
    },
    {
    "id": "31e830d7-485e-48fd-9d4b-0d0af03826b6",
    "question": "this is test",
    "answer": "ok",
    "hit_count": 0,
    "created_at": 1760507579
    },
    {
    "id": "68eef311-7d92-49f7-8a14-0d20c518050f",
    "question": "hello",
    "answer": "你好",
    "hit_count": 1,
    "created_at": 1760499735
    }
    ],
    "has_more": false,
    "limit": 10,
    "total": 3,
    "page": 1
    }

  8. Cursx commented on Oct 16, 2025

    @Cursx
    Contributor

    The problem still exists and was present in 1.9.x as well.

    • Although the controller accepts the App Token, the service layer implementation (api/services/annotation_service.py) calls current_account_with_tenant() for all annotation methods, which requires that the current_user is an Account and has loaded the current_tenant_id.

    • In the current implementation, using an App Token to call GET/POST /v1/apps/annotations will result in an error due to the absence of an Account context (current_user must be an Account instance). The update/delete interfaces explicitly assert isinstance(current_user, Account).

    • In other words, the annotation management of the service API does not currently support direct usage "solely with an App Token"; it requires the tenant's Account to be logged into the request context as an additional step.

  9. Cursx commented on Oct 16, 2025

    @Cursx
    Contributor

    Hi, @guoshiqiufeng. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

    Issue Summary:

    • You reported a 500 Internal Server Error when using the chat annotations API on version 2.0.0-beta.2 with a self-hosted Docker setup.
    • The error occurs when POSTing to /v1/apps/annotations instead of the correct endpoint /v1/apps/{app_id}/annotations.
    • The request body should only include question and answer fields, and authentication must be done via the Authorization header.
    • A recent PR (more assert #24996) was suggested as a possible cause of the error.
    • Recommendations included checking Docker API container logs and verifying user permissions for further diagnosis.

    Next Steps:

    • Please confirm if this issue persists with the latest version of Dify and if the endpoint and request format are correctly used.
    • If the problem is still relevant, you can keep the discussion open by commenting here; otherwise, I will automatically close this issue in 15 days.

    Thank you for your understanding and contribution!

    I think there are indeed some issues that haven't been resolved here

  10. Cursx commented on Oct 16, 2025

    @Cursx
    Contributor

    The problem still exists and was present in 1.9.x as well.

    in api/services/annotation_service.py
    Changing @ validate_app_token to @ validate_app_token (fetch_user_arg=...) may work

    Correspondingly, you also need to modify some code in other places.

    -GET/v1/apps/annotations originally had 500 because it required an Account, but using only @ validate_app_token would not automatically set the Account;

  11. Cursx commented on Oct 17, 2025

    @Cursx
    Contributor

    Self Checks

    • I have read the Contributing Guide and Language Policy.[x] This is only for bug report, if you would like to ask a question, please head to Discussions.[x] I have searched for existing issues search for existing issues, including closed ones.[x] I confirm that I am using English to submit this report, otherwise it will be closed.[x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)[x] Please do not modify this template :) and fill in all the required fields.

    Dify version

    2.0.0-beta.2

    Cloud or Self Hosted

    Self Hosted (Docker)

    Steps to reproduce

    Chat annotations Api Error

    Request

    • request url:http://localhost/v1/apps/annotations,
    • request method:POST,
    • request headers:[Content-Type:"application/json", Accept:"application/json", Authorization:"***", Content-Length:"129"],
    • request body:{"apiKey":"app-oSWO5BZJrrauObe9NArLhrUz","userId":"1504","question":"Test annotation question","answer":"Test annotation answer"}

    Response

    • requestId:e2901c68-819c-4675-ac36-018235be6774
    • status:500 INTERNAL_SERVER_ERROR
    • headers:[Server:"nginx/1.29.1", Date:"Thu, 11 Sep 2025 02:07:03 GMT", Content-Type:"application/json", Content-Length:"66", Connection:"keep-alive", Access-Control-Allow-Origin:"*", X-Version:"2.0.0-beta2", X-Env:"PRODUCTION", Vary:"Cookie"],
    • executionTime:18ms,
    • body:{"message":"Internal Server Error","code":"unknown","status":500}

    ✔️ Expected Behavior

    Normal Creation

    ❌ Actual Behavior

    No response

    The problem still exists and was present in 1.9.x as well.

    Recently, I conducted some tests to confirm my judgment. Now I confirm that it is because of the annotations in annotation.py and annotation_stervice. py@ validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY)) You can modify these two files in Docker or local source code to address the issue caused by the relevant code. I have provided some illustrations below, which may be helpful to you.

  12. Cursx commented on Oct 17, 2025

    @Cursx
    Contributor

    Self Checks

    • I have read the Contributing Guide and Language Policy.[x] This is only for bug report, if you would like to ask a question, please head to Discussions.[x] I have searched for existing issues search for existing issues, including closed ones.[x] I confirm that I am using English to submit this report, otherwise it will be closed.[x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)[x] Please do not modify this template :) and fill in all the required fields.

    Dify version

    2.0.0-beta.2

    Cloud or Self Hosted

    Self Hosted (Docker)

    Steps to reproduce

    Chat annotations Api Error

    Request

    • request url:http://localhost/v1/apps/annotations,
    • request method:POST,
    • request headers:[Content-Type:"application/json", Accept:"application/json", Authorization:"***", Content-Length:"129"],
    • request body:{"apiKey":"app-oSWO5BZJrrauObe9NArLhrUz","userId":"1504","question":"Test annotation question","answer":"Test annotation answer"}

    Response

    • requestId:e2901c68-819c-4675-ac36-018235be6774
    • status:500 INTERNAL_SERVER_ERROR
    • headers:[Server:"nginx/1.29.1", Date:"Thu, 11 Sep 2025 02:07:03 GMT", Content-Type:"application/json", Content-Length:"66", Connection:"keep-alive", Access-Control-Allow-Origin:"*", X-Version:"2.0.0-beta2", X-Env:"PRODUCTION", Vary:"Cookie"],
    • executionTime:18ms,
    • body:{"message":"Internal Server Error","code":"unknown","status":500}

    ✔️ Expected Behavior

    Normal Creation

    ❌ Actual Behavior

    No response

    Image Image Image Image

    This is the main area that needs to be modified. I have tested it on two devices, and you can use AI to assist in locating and modifying it. Below are screenshots of my successful API and console requests

  13. Cursx commented on Oct 22, 2025

    @Cursx
    Contributor

    The problem still exists and was present in 1.9.x as well.

    Although my previous method was able to solve this problem, there were many unreasonable modifications. Now I have probably solved this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Knowledge Pipeline🐞 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions