[GH-ISSUE #2510] [BUG]: 401 error with /api/v1/openai/chat/completions while other methods work #1624

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

Originally created by @IrvenFier on GitHub (Oct 21, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2510

How are you running AnythingLLM?

Local development

What happened?

Hello AnythingLLM Team! 👋
I've just started using your product, read tons of docs and still face the next problem: when requesting /api/v1/openai/chat/completions using Swagger or python library openai I got Error code: 401
Anything LLM version: 1.6.7 for single user (I do not use cloud version so I even don't have multi-user option in instance settings)
LLM Provider: LM Studio
Model: qwen2.5-coder-7b-instruct
Api key: valid, from admin account (other methods work properly)

Are there known steps to reproduce?

Preconditions

  1. Settings
    Снимок экрана 2024-10-21 в 22 18 45
    Снимок экрана 2024-10-21 в 22 20 10
    Снимок экрана 2024-10-21 в 22 20 41
  2. Authorize with valid api key
    Steps:
  3. Use /api/v1/openai/chat/completions method
    Снимок экрана 2024-10-21 в 21 58 49
    Result:
    removed

In order to identify potential bugs in my own code, I used both examples from https://github.com/Mintplex-Labs/anything-llm/issues/2450, /v1/workspace/chat - works, openai/chat/completions - doesn't work
I also read information from Discord where found only the same questions with no answers
Снимок экрана 2024-10-21 в 22 07 05
Could you please check if this situation requires additional settings or I face a real bug and can stop reading new and new topics?)
Thank you in advance 😊

Originally created by @IrvenFier on GitHub (Oct 21, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2510 ### How are you running AnythingLLM? Local development ### What happened? Hello AnythingLLM Team! :wave: I've just started using your product, read tons of docs and still face the next problem: when requesting /api/v1/openai/chat/completions using Swagger or python library openai I got Error code: 401 Anything LLM version: 1.6.7 for single user (I do not use cloud version so I even don't have multi-user option in instance settings) LLM Provider: LM Studio Model: qwen2.5-coder-7b-instruct Api key: valid, from admin account (other methods work properly) ### Are there known steps to reproduce? **Preconditions** 1. Settings ![Снимок экрана 2024-10-21 в 22 18 45](https://github.com/user-attachments/assets/4efed3bd-25c7-40da-9a80-4042852fc338) ![Снимок экрана 2024-10-21 в 22 20 10](https://github.com/user-attachments/assets/b1250123-16b9-4c78-9584-6cbf9c1d5f42) ![Снимок экрана 2024-10-21 в 22 20 41](https://github.com/user-attachments/assets/4dc25e35-0e11-4c40-a6a2-14e09bb9a0af) 2. Authorize with valid api key **Steps:** 1. Use /api/v1/openai/chat/completions method ![Снимок экрана 2024-10-21 в 21 58 49](https://github.com/user-attachments/assets/47f3c957-0a27-49e7-84f3-68b118e69e2c) **Result:** _removed_ In order to identify potential bugs in my own code, I used both examples from https://github.com/Mintplex-Labs/anything-llm/issues/2450, /v1/workspace/chat - works, openai/chat/completions - doesn't work I also read information from Discord where found only the same questions with no answers ![Снимок экрана 2024-10-21 в 22 07 05](https://github.com/user-attachments/assets/84608e4e-2ba9-469d-ad99-87022a442583) Could you please check if this situation requires additional settings or I face a real bug and can stop reading new and new topics?) Thank you in advance :blush:
yindo added the possible bug label 2026-02-22 18:25:45 -05:00
yindo closed this issue 2026-02-22 18:25:45 -05:00
Author
Owner

@timothycarambat commented on GitHub (Oct 21, 2024):

The model parameter is a slug that represents a workspace not a model.

  1. This allows you to use a workspace with its entire document set as a "model" that is already using your system model as well.

  2. Change model to a workspace slug, which you can find by hitting the openai compatible /models endpoint. This is denoted in the description of the endpoint in your screenshot!
    https://github.com/Mintplex-Labs/anything-llm/blob/36af69b4a84cf09b8a2397402d64ee58acef69dc/server/endpoints/api/openai/index.js#L89

Since the model you included is not the slug of a workspace - you get a 401!
https://github.com/Mintplex-Labs/anything-llm/blob/36af69b4a84cf09b8a2397402d64ee58acef69dc/server/endpoints/api/openai/index.js#L123

@timothycarambat commented on GitHub (Oct 21, 2024): The `model` parameter is a slug that represents a workspace not a model. 1. This allows you to use a workspace with its entire document set as a "model" that _is already_ using your system model as well. 2. Change `model` to a workspace slug, which you can find by hitting the openai compatible `/models` endpoint. This is denoted in the description of the endpoint in your screenshot! https://github.com/Mintplex-Labs/anything-llm/blob/36af69b4a84cf09b8a2397402d64ee58acef69dc/server/endpoints/api/openai/index.js#L89 Since the model you included is not the slug of a workspace - you get a 401! https://github.com/Mintplex-Labs/anything-llm/blob/36af69b4a84cf09b8a2397402d64ee58acef69dc/server/endpoints/api/openai/index.js#L123
Author
Owner

@IrvenFier commented on GitHub (Oct 21, 2024):

Thank you very much for the answer! Now everything works!)
I read description, but tried to use model_name/workspace/workspace_name/ as a model and didn't guess to use only workspace_slug without model_name. And even 'sample-workspace' was not a hint for me and many people in Discord, ah... I am sorry for disturbing you! And thank you once again)
Here is the screenshot for anybody who faces the same problem and would try to find the solution
Request
Снимок экрана 2024-10-22 в 00 14 28
Снимок экрана 2024-10-22 в 00 18 07
Response
Снимок экрана 2024-10-22 в 00 19 50

@IrvenFier commented on GitHub (Oct 21, 2024): Thank you very much for the answer! Now everything works!) I read description, but tried to use model_name/workspace/workspace_name/ as a model and didn't guess to use only workspace_slug without model_name. And even 'sample-workspace' was not a hint for me and many people in Discord, ah... I am sorry for disturbing you! And thank you once again) Here is the screenshot for anybody who faces the same problem and would try to find the solution Request ![Снимок экрана 2024-10-22 в 00 14 28](https://github.com/user-attachments/assets/c31b7442-de90-43ce-a4a3-9810695e9466) ![Снимок экрана 2024-10-22 в 00 18 07](https://github.com/user-attachments/assets/a64eb8c9-6738-4d9f-802e-3f7324d39766) Response ![Снимок экрана 2024-10-22 в 00 19 50](https://github.com/user-attachments/assets/2f7a214f-c80e-4447-9510-071e9d57dd24)
Author
Owner

@wojiushibuhui commented on GitHub (Jun 7, 2025):

Hi everyone,

I'm also encountering this issue with the /api/v1/openai/chat/completions endpoint on AnythingLLM Desktop version [Your AnythingLLM Desktop Version, e.g., v1.X.X] running on [Your OS, e.g., Windows 10, macOS Sonoma].

I've performed extensive troubleshooting, including:

  1. Ensuring the correct API endpoint URL (http://localhost:3001/api/v1/openai/chat/completions).
  2. Using the POST method with the correct Content-Type: application/json header.
  3. Generating a brand new Developer API Key from the "API Keys" section in settings.
  4. Testing via direct fetch calls from the browser console (from about:blank to rule out CSP issues).

In all external API calls, I consistently receive a 403 Forbidden status with the response body:
{"error":"No valid api key found."}

Crucially, I also tested this directly within the AnythingLLM built-in API documentation page (Swagger UI):

  • I used the "Authorize" button and provided the newly generated Developer API Key in the Bearer <token> format.
  • I then executed a POST request to /api/v1/openai/chat/completions via the "Try it out" feature with a valid JSON body.
  • The result was the same: 403 Forbidden with {"error":"No valid api key found."} (as shown in the attached screenshot/my previous diagnostic steps).

This strongly suggests the issue lies within AnythingLLM's internal handling or validation of Developer API Keys for this endpoint, as even the built-in testing tool fails with a newly generated key. Internal chat functionalities within the AnythingLLM application itself work correctly.

Hoping this information helps in diagnosing and resolving the bug.

Thanks!

@wojiushibuhui commented on GitHub (Jun 7, 2025): Hi everyone, I'm also encountering this issue with the `/api/v1/openai/chat/completions` endpoint on AnythingLLM Desktop version [Your AnythingLLM Desktop Version, e.g., v1.X.X] running on [Your OS, e.g., Windows 10, macOS Sonoma]. I've performed extensive troubleshooting, including: 1. Ensuring the correct API endpoint URL (`http://localhost:3001/api/v1/openai/chat/completions`). 2. Using the POST method with the correct `Content-Type: application/json` header. 3. Generating a brand new Developer API Key from the "API Keys" section in settings. 4. Testing via direct `fetch` calls from the browser console (from `about:blank` to rule out CSP issues). In all external API calls, I consistently receive a `403 Forbidden` status with the response body: `{"error":"No valid api key found."}` **Crucially, I also tested this directly within the AnythingLLM built-in API documentation page (Swagger UI):** * I used the "Authorize" button and provided the newly generated Developer API Key in the `Bearer <token>` format. * I then executed a POST request to `/api/v1/openai/chat/completions` via the "Try it out" feature with a valid JSON body. * **The result was the same: `403 Forbidden` with `{"error":"No valid api key found."}` (as shown in the attached screenshot/my previous diagnostic steps).** This strongly suggests the issue lies within AnythingLLM's internal handling or validation of Developer API Keys for this endpoint, as even the built-in testing tool fails with a newly generated key. Internal chat functionalities within the AnythingLLM application itself work correctly. Hoping this information helps in diagnosing and resolving the bug. Thanks!
Author
Owner

@timothycarambat commented on GitHub (Jun 9, 2025):

@wojiushibuhui It is not within our internal API and is wholly user error. Its always user error in this case. If you have a code snippet to share you always get a 403 on I can paste in my key and show it working.

The validation step would not just randomly fail intermittently. If it says you have an invalid key you are incorrectly passing in said key. The fact the same key says it is invalid in the swagger UI would be related to the fact the key isnt valid or there is some formatting issue (extra spaces possibly?)

https://github.com/user-attachments/assets/98bfed64-ccac-46d1-b385-1021125dda24

@timothycarambat commented on GitHub (Jun 9, 2025): @wojiushibuhui It is not within our internal API and is wholly user error. Its always user error in this case. If you have a code snippet to share you always get a 403 on I can paste in my key and show it working. The validation step would not just randomly fail intermittently. If it says you have an invalid key you are incorrectly passing in said key. The fact the same key says it is invalid in the swagger UI would be related to the fact the key isnt valid _or_ there is some formatting issue (extra spaces possibly?) https://github.com/user-attachments/assets/98bfed64-ccac-46d1-b385-1021125dda24
Author
Owner

@tzhengus commented on GitHub (Aug 2, 2025):

@timothycarambat Thank you for pointing out the model parameter is actually a workspace name. It took me a while to find the correct answer until I searched 401 in the github issues. Is it possible for you to include it in the documentation? Thank you!

@tzhengus commented on GitHub (Aug 2, 2025): @timothycarambat Thank you for pointing out the `model` parameter is actually a workspace name. It took me a while to find the correct answer until I searched 401 in the github issues. Is it possible for you to include it in the documentation? Thank you!
yindo changed title from [BUG]: 401 error with /api/v1/openai/chat/completions while other methods work to [GH-ISSUE #2510] [BUG]: 401 error with /api/v1/openai/chat/completions while other methods work 2026-06-05 14:41:48 -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#1624