[GH-ISSUE #2272] [BUG]: Error Creating New Thread with userId in Workspace API #1483

Closed
opened 2026-02-22 18:25:03 -05:00 by yindo · 4 comments
Owner

Originally created by @MrSimonC on GitHub (Sep 12, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2272

How are you running AnythingLLM?

Docker (local)

What happened?

(Sorry - no pull request from me this time - it's too in depth 😄 )
When attempting to create a new thread in a workspace using the API and providing a userId, an error occurs. This issue can be reproduced using the provided code or directly in the Swagger UI.

Environment:

  • Running AnythingLLM in Docker
  • Version: 1.2.2 (also tested in 1.2.1)
  • Tested on Windows WSL2 Docker and Ubuntu in GitHub Codespaces

Are there known steps to reproduce?

  1. Run AnythingLLM in Docker:

    export STORAGE_LOCATION=$HOME/anythingllm && \
    mkdir -p $STORAGE_LOCATION && \
    touch "$STORAGE_LOCATION/.env" && \
    docker run -d -p 3001:3001 \
    --cap-add SYS_ADMIN \
    -v ${STORAGE_LOCATION}:/app/server/storage \
    -v ${STORAGE_LOCATION}/.env:/app/server/.env \
    -e STORAGE_DIR="/app/server/storage" \
    --restart always \
    mintplexlabs/anythingllm:1.2.2
    
  2. Fill in a new AI provider.

  3. Generate a new API key (e.g., <MY_API_KEY>).

HTTP REST Example:

POST http://localhost:3001/api/v1/workspace/my-workspace-slug/thread/new
Authorization: Bearer <MY_API_KEY>
Content-Type: application/json

{
  "userId": 1
}

CURL Example:

curl -X 'POST' \
  'http://127.0.0.1:3001/api/v1/workspace/my-workspace-slug/thread/new' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <MY_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
  "userId": 1
}'

Result:
The API responds with:

HTTP/1.1 200 OK
X-Powered-By: Express
Vary: Origin
Content-Type: application/json; charset=utf-8
Content-Length: 148
ETag: W/"94-Y14XDftRy07iOWO+P2NlTX+rhlw"
Date: Thu, 12 Sep 2024 16:06:54 GMT
Connection: keep-alive
keep-alive: timeout=5

{
  "thread": null,
  "message": "\nInvalid `prisma.workspace_threads.create()` invocation:\n\n\nForeign key constraint failed on the field: `foreign key`"
}

Expected Behavior:
The thread should be created successfully when a valid userId is provided.

Originally created by @MrSimonC on GitHub (Sep 12, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2272 ### How are you running AnythingLLM? Docker (local) ### What happened? _(Sorry - no pull request from me this time - it's too in depth 😄 )_ When attempting to create a new thread in a workspace using the API and providing a `userId`, an error occurs. This issue can be reproduced using the provided code or directly in the Swagger UI. **Environment:** - Running AnythingLLM in Docker - Version: 1.2.2 (also tested in 1.2.1) - Tested on Windows WSL2 Docker and Ubuntu in GitHub Codespaces ### Are there known steps to reproduce? 1. Run AnythingLLM in Docker: ```bash export STORAGE_LOCATION=$HOME/anythingllm && \ mkdir -p $STORAGE_LOCATION && \ touch "$STORAGE_LOCATION/.env" && \ docker run -d -p 3001:3001 \ --cap-add SYS_ADMIN \ -v ${STORAGE_LOCATION}:/app/server/storage \ -v ${STORAGE_LOCATION}/.env:/app/server/.env \ -e STORAGE_DIR="/app/server/storage" \ --restart always \ mintplexlabs/anythingllm:1.2.2 ``` 2. Fill in a new AI provider. 3. Generate a new API key (e.g., `<MY_API_KEY>`). **HTTP REST Example:** ```http POST http://localhost:3001/api/v1/workspace/my-workspace-slug/thread/new Authorization: Bearer <MY_API_KEY> Content-Type: application/json { "userId": 1 } ``` **CURL Example:** ```bash curl -X 'POST' \ 'http://127.0.0.1:3001/api/v1/workspace/my-workspace-slug/thread/new' \ -H 'accept: application/json' \ -H 'Authorization: Bearer <MY_API_KEY>' \ -H 'Content-Type: application/json' \ -d '{ "userId": 1 }' ``` **Result:** The API responds with: ``` HTTP/1.1 200 OK X-Powered-By: Express Vary: Origin Content-Type: application/json; charset=utf-8 Content-Length: 148 ETag: W/"94-Y14XDftRy07iOWO+P2NlTX+rhlw" Date: Thu, 12 Sep 2024 16:06:54 GMT Connection: keep-alive keep-alive: timeout=5 { "thread": null, "message": "\nInvalid `prisma.workspace_threads.create()` invocation:\n\n\nForeign key constraint failed on the field: `foreign key`" } ``` **Expected Behavior:** The thread should be created successfully when a valid `userId` is provided.
yindo added the possible bug label 2026-02-22 18:25:03 -05:00
yindo closed this issue 2026-02-22 18:25:03 -05:00
Author
Owner

@ImaginePilot commented on GitHub (Sep 12, 2024):

same here, I just don't have a clue why only creating new threads have this problem

@ImaginePilot commented on GitHub (Sep 12, 2024): same here, I just don't have a clue why only creating new threads have this problem
Author
Owner

@timothycarambat commented on GitHub (Sep 12, 2024):

Are you in multi-user mode?

@timothycarambat commented on GitHub (Sep 12, 2024): Are you in multi-user mode?
Author
Owner

@timothycarambat commented on GitHub (Sep 12, 2024):

This seems to be the issue.

I am not sure if this is the intention, but this endpoint is more for "UI automation" or management of the threads also visible in the UI. We recently introduced the sessionId key on workspace/(chat or stream-chat) endpoint that you can now use some external identifier per request and keep chat history per call without making threads or polluting the UI with threads/chats for any specific user.
https://github.com/Mintplex-Labs/anything-llm/blob/906eb70ca15b7cea2470e9571ad7113416ddccfe/server/endpoints/api/workspace/index.js#L549

@timothycarambat commented on GitHub (Sep 12, 2024): This seems to be the issue. I am not sure if this is the intention, but this endpoint is more for "UI automation" or management of the threads also visible in the UI. We recently introduced the `sessionId` key on `workspace/(chat or stream-chat)` endpoint that you can now use some external identifier per request and keep chat history per call without making threads or polluting the UI with threads/chats for any specific user. https://github.com/Mintplex-Labs/anything-llm/blob/906eb70ca15b7cea2470e9571ad7113416ddccfe/server/endpoints/api/workspace/index.js#L549
Author
Owner

@MrSimonC commented on GitHub (Sep 13, 2024):

Thanks @timothycarambat it was a bit of both - but ultimately the sessionId (which I've tested - and works great) will be the winner for my + other's use cases. Great!

@MrSimonC commented on GitHub (Sep 13, 2024): Thanks @timothycarambat it was a bit of both - but ultimately the `sessionId` (which I've tested - and works great) will be the winner for my + other's use cases. Great!
yindo changed title from [BUG]: Error Creating New Thread with userId in Workspace API to [GH-ISSUE #2272] [BUG]: Error Creating New Thread with userId in Workspace API 2026-06-05 14:41:00 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1483