OpenAI embedding large model error when using knowledge #8443

Closed
opened 2026-02-21 18:25:43 -05:00 by yindo · 3 comments
Owner

Originally created by @mz-heesun on GitHub (Feb 19, 2025).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When I apply the OpenAI API key to the model provider in Dify and select the text-embedding-3-large model when generating knowledge, I get a 401 error because the key I registered is different from the one I applied.

step1
Image

step2

Image

I think it may be just me.
It is a docker environment and is deployed within eks.

I think something may have gone wrong during deployment or it may have been incorrectly stored somewhere.

I am using resources such as postgres, redis, and opensearch.
I want to check where the API key is stored, but I don't know where.

Please give me some clues!

✔️ Expected Behavior

Knowledge should be generated computationally using the text-embedding-3-large model.

Actual Behavior

An error occurred and the log is as follows.

Image
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/api/core/rag/embedding/cached_embedding.py", line 61, in embed_documents
    embedding_result = self._model_instance.invoke_text_embedding(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_manager.py", line 185, in invoke_text_embedding
    self._round_robin_invoke(
  File "/app/api/core/model_manager.py", line 334, in _round_robin_invoke
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 46, in invoke
    raise self._transform_invoke_error(e)
core.model_runtime.errors.invoke.InvokeAuthorizationError: [openai] Incorrect model credentials provided, please check and try again.
2025-02-20 03:57:02,087.087 ERROR [Dummy-9] [indexing_runner.py:96] - consume document failed
Traceback (most recent call last):
  File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 44, in invoke
    return self._invoke(model, credentials, texts, user, input_type)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_runtime/model_providers/openai/text_embedding/text_embedding.py", line 76, in _invoke
    embeddings_batch, embedding_used_tokens = self._embedding_invoke(
                                              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_runtime/model_providers/openai/text_embedding/text_embedding.py", line 166, in _embedding_invoke
    response = client.embeddings.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 125, in create
    return self._post(
           ^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1283, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 960, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1064, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************p8MA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/api/core/indexing_runner.py", line 80, in run
    self._load(
  File "/app/api/core/indexing_runner.py", line 570, in _load
    tokens += future.result()
              ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/indexing_runner.py", line 627, in _process_chunk
    index_processor.load(dataset, chunk_documents, with_keywords=False)
  File "/app/api/core/rag/index_processor/processor/paragraph_index_processor.py", line 78, in load
    vector.create(documents)
  File "/app/api/core/rag/datasource/vdb/vector_factory.py", line 156, in create
    embeddings = self._embeddings.embed_documents([document.page_content for document in texts])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/rag/embedding/cached_embedding.py", line 99, in embed_documents
    raise ex
  File "/app/api/core/rag/embedding/cached_embedding.py", line 61, in embed_documents
    embedding_result = self._model_instance.invoke_text_embedding(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_manager.py", line 185, in invoke_text_embedding
    self._round_robin_invoke(
  File "/app/api/core/model_manager.py", line 334, in _round_robin_invoke
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 46, in invoke
    raise self._transform_invoke_error(e)
core.model_runtime.errors.invoke.InvokeAuthorizationError: [openai] Incorrect model credentials provided, please check and try again.

Originally created by @mz-heesun on GitHub (Feb 19, 2025). ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When I apply the OpenAI API key to the model provider in Dify and select the text-embedding-3-large model when generating knowledge, I get a 401 error because the key I registered is different from the one I applied. step1 <img width="739" alt="Image" src="https://github.com/user-attachments/assets/46d2997d-d4fa-4c45-b1be-e3ecfb7dff33" /> step2 <img width="1090" alt="Image" src="https://github.com/user-attachments/assets/86df5628-b72b-4b9b-b772-5d2ea6a292e3" /> I think it may be just me. It is a docker environment and is deployed within eks. I think something may have gone wrong during deployment or it may have been incorrectly stored somewhere. I am using resources such as postgres, redis, and opensearch. I want to check where the API key is stored, but I don't know where. Please give me some clues! ### ✔️ Expected Behavior Knowledge should be generated computationally using the text-embedding-3-large model. ### ❌ Actual Behavior An error occurred and the log is as follows. <img width="1437" alt="Image" src="https://github.com/user-attachments/assets/85867efb-e59a-4d5e-b918-cf3cc0d2fb8a" /> ``` During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/api/core/rag/embedding/cached_embedding.py", line 61, in embed_documents embedding_result = self._model_instance.invoke_text_embedding( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_manager.py", line 185, in invoke_text_embedding self._round_robin_invoke( File "/app/api/core/model_manager.py", line 334, in _round_robin_invoke return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 46, in invoke raise self._transform_invoke_error(e) core.model_runtime.errors.invoke.InvokeAuthorizationError: [openai] Incorrect model credentials provided, please check and try again. 2025-02-20 03:57:02,087.087 ERROR [Dummy-9] [indexing_runner.py:96] - consume document failed Traceback (most recent call last): File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 44, in invoke return self._invoke(model, credentials, texts, user, input_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_runtime/model_providers/openai/text_embedding/text_embedding.py", line 76, in _invoke embeddings_batch, embedding_used_tokens = self._embedding_invoke( ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_runtime/model_providers/openai/text_embedding/text_embedding.py", line 166, in _embedding_invoke response = client.embeddings.create( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 125, in create return self._post( ^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1283, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 960, in request return self._request( ^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1064, in _request raise self._make_status_error_from_response(err.response) from None openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************p8MA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/api/core/indexing_runner.py", line 80, in run self._load( File "/app/api/core/indexing_runner.py", line 570, in _load tokens += future.result() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 456, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result raise self._exception File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/indexing_runner.py", line 627, in _process_chunk index_processor.load(dataset, chunk_documents, with_keywords=False) File "/app/api/core/rag/index_processor/processor/paragraph_index_processor.py", line 78, in load vector.create(documents) File "/app/api/core/rag/datasource/vdb/vector_factory.py", line 156, in create embeddings = self._embeddings.embed_documents([document.page_content for document in texts]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/rag/embedding/cached_embedding.py", line 99, in embed_documents raise ex File "/app/api/core/rag/embedding/cached_embedding.py", line 61, in embed_documents embedding_result = self._model_instance.invoke_text_embedding( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_manager.py", line 185, in invoke_text_embedding self._round_robin_invoke( File "/app/api/core/model_manager.py", line 334, in _round_robin_invoke return function(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/model_runtime/model_providers/__base/text_embedding_model.py", line 46, in invoke raise self._transform_invoke_error(e) core.model_runtime.errors.invoke.InvokeAuthorizationError: [openai] Incorrect model credentials provided, please check and try again. ```
yindo added the 🐞 bug label 2026-02-21 18:25:43 -05:00
yindo closed this issue 2026-02-21 18:25:43 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 19, 2025):

@mz-heesun Hello! I'm here to help you with any bugs, questions, or contributions you have. Let's get this issue sorted out!

I found a similar closed issue that might help you resolve the error you're encountering. The error message "Incorrect model credentials provided" suggests that the model credentials have not been properly configured in Dify. Here are some steps that might help:

  1. Check Model Provider Settings: Ensure that you have configured the model credentials correctly in the Settings --> Model Providers section. You need to obtain the API key from the model provider's official website and configure it in this section.

  2. Error Handling: Dify raises a ProviderTokenNotInitError when model credentials are not initialized. This typically means that the model's status is set to NO_CONFIGURE, which indicates missing or incorrect credentials.

  3. Validation Process: During the preprocessing stage, Dify uses a validate_credentials method to ensure that all necessary credentials are present and correctly formatted. If any credentials are missing or invalid, a CredentialsValidateFailedError is raised.

Additionally, the OpenAI API keys in the Dify codebase are stored and managed in the api/pytest.ini file under the environment variable OPENAI_API_KEY [1].

By following these steps and ensuring that your model credentials are correctly set up, you should be able to resolve the error. If the issue persists, double-check the credentials and configuration settings for any discrepancies.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Feb 19, 2025): <!-- Greeting --> @mz-heesun Hello! I'm here to help you with any bugs, questions, or contributions you have. Let's get this issue sorted out! <!-- Answer --> I found a similar closed issue that might help you resolve the error you're encountering. The error message "Incorrect model credentials provided" suggests that the model credentials have not been properly configured in Dify. Here are some steps that might help: 1. **Check Model Provider Settings**: Ensure that you have configured the model credentials correctly in the **Settings --> Model Providers** section. You need to obtain the API key from the model provider's official website and configure it in this section. 2. **Error Handling**: Dify raises a `ProviderTokenNotInitError` when model credentials are not initialized. This typically means that the model's status is set to `NO_CONFIGURE`, which indicates missing or incorrect credentials. 3. **Validation Process**: During the preprocessing stage, Dify uses a `validate_credentials` method to ensure that all necessary credentials are present and correctly formatted. If any credentials are missing or invalid, a `CredentialsValidateFailedError` is raised. Additionally, the OpenAI API keys in the Dify codebase are stored and managed in the `api/pytest.ini` file under the environment variable `OPENAI_API_KEY` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/pytest.ini)</sup>. By following these steps and ensuring that your model credentials are correctly set up, you should be able to resolve the error. If the issue persists, double-check the credentials and configuration settings for any discrepancies. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/05cd7bf9-c51f-4723-b6c5-c9a61176544b?feedback_type=other)</sup>
Author
Owner
@crazywoola commented on GitHub (Feb 20, 2025): https://github.com/langgenius/dify/blob/4dae0e514e1b149ea74e42056fcc520ad60b8c04/api/commands.py#L112-L139
Author
Owner

@mz-heesun commented on GitHub (Feb 20, 2025):

select * from providers

Image

select * from provider_models

Image

Why are the two models storing their open ai api keys differently?
Which one takes priority?

@mz-heesun commented on GitHub (Feb 20, 2025): select * from providers <img width="1029" alt="Image" src="https://github.com/user-attachments/assets/ca11ce03-ae3d-446f-827a-eb31fcbff20c" /> select * from provider_models <img width="1088" alt="Image" src="https://github.com/user-attachments/assets/7ccbe4d9-b4b5-4ea5-a68d-b00c06150f7c" /> Why are the two models storing their open ai api keys differently? Which one takes priority?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8443