got errMsg "Invalid user account" when use datasetsAPI "create_by_file" #18125

Closed
opened 2026-02-21 19:43:51 -05:00 by yindo · 0 comments
Owner

Originally created by @luoluoter on GitHub (Sep 24, 2025).

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

1.9.0

Cloud or Self Hosted

Cloud

Steps to reproduce

  1. Call the dataset documents list API with a Dataset API Key → works fine.

  2. Attempt to upload a file with the same Dataset API Key:

    const formData = new FormData();
    formData.append("file", file);
    formData.append("data", JSON.stringify({
      indexing_technique: "high_quality",
      process_rule: {
        rules: {
          pre_processing_rules: [{ id: "remove_extra_spaces", enabled: true }]
        },
        segmentation: { separator: "\n\n", max_tokens: 2000, chunk_overlap: 200 },
        mode: "custom"
      }
    }));
    
    fetch(`${baseUrl}/v1/datasets/${datasetId}/document/create_by_file`, {
      method: "POST",
      headers: { Authorization: `Bearer ${datasetApiKey}` },
      body: formData
    });
    

✔️ Expected Behavior

  1. Documentation should explicitly state the required token type for create_by_file.

  2. Cloud/Sandbox users should either:

    • be allowed to use Workspace API Keys for file uploads, or
    • be provided with an official way to generate EndUser tokens.
  3. Consistency across dataset APIs (list vs upload) so that the developer experience is predictable.

Actual Behavior

Response is always { "code": "invalid_param", "message": "Invalid user account", "status": 400 }


My code hasn't been modified, it was still working normally a few weeks ago

Source Code Analysis

Looking into the backend implementation, the endpoint checks:

if not isinstance(current_user, EndUser):
    raise ValueError("Invalid user account")

This means create_by_file only works when called with an EndUser token???
But in Cloud/Sandbox mode, users only have Workspace API Keys, with no way to generate EndUser tokens.

Originally created by @luoluoter on GitHub (Sep 24, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/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 1.9.0 ### Cloud or Self Hosted Cloud ### Steps to reproduce 1. Call the dataset documents list API with a Dataset API Key → works fine. 2. Attempt to upload a file with the same Dataset API Key: ```js const formData = new FormData(); formData.append("file", file); formData.append("data", JSON.stringify({ indexing_technique: "high_quality", process_rule: { rules: { pre_processing_rules: [{ id: "remove_extra_spaces", enabled: true }] }, segmentation: { separator: "\n\n", max_tokens: 2000, chunk_overlap: 200 }, mode: "custom" } })); fetch(`${baseUrl}/v1/datasets/${datasetId}/document/create_by_file`, { method: "POST", headers: { Authorization: `Bearer ${datasetApiKey}` }, body: formData }); ``` ### ✔️ Expected Behavior 1. Documentation should explicitly state the required token type for `create_by_file`. 2. Cloud/Sandbox users should either: * be allowed to use Workspace API Keys for file uploads, **or** * be provided with an official way to generate EndUser tokens. 3. Consistency across dataset APIs (list vs upload) so that the developer experience is predictable. ### ❌ Actual Behavior Response is always `{ "code": "invalid_param", "message": "Invalid user account", "status": 400 }` --- My code hasn't been modified, it was still working normally a few weeks ago ### Source Code Analysis Looking into the backend implementation, the endpoint checks: ```python if not isinstance(current_user, EndUser): raise ValueError("Invalid user account") ``` This means `create_by_file` only works when called with an **EndUser token**??? But in **Cloud/Sandbox mode**, users only have **Workspace API Keys**, with no way to generate EndUser tokens.
yindo closed this issue 2026-02-21 19:43:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#18125