Azure openai chat :403 Forbidden #6155

Closed
opened 2026-02-21 18:14:18 -05:00 by yindo · 6 comments
Owner

Originally created by @dale22 on GitHub (Oct 18, 2024).

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.9.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

1,Setup azure openai model is ok
2,but use this model chat, docker-api logs:403
logs;docker-api-1
2024-10-18 04:16:55,655.655 INFO [Thread-4 (_generate_worker)] [_client.py:1038] - HTTP Request: POST https://xxxxxx/openai/deployments/GPT-4o-2024-05-13/chat/completions?api-version=2024-05-01-preview "HTTP/1.1 403 Forbidden"

✔️ Expected Behavior

return result

Actual Behavior

return 403

Originally created by @dale22 on GitHub (Oct 18, 2024). ### 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.9.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1,Setup azure openai model is ok 2,but use this model chat, docker-api logs:403 logs;docker-api-1 2024-10-18 04:16:55,655.655 INFO [Thread-4 (_generate_worker)] [_client.py:1038] - HTTP Request: POST https://xxxxxx/openai/deployments/GPT-4o-2024-05-13/chat/completions?api-version=2024-05-01-preview "HTTP/1.1 403 Forbidden" ### ✔️ Expected Behavior return result ### ❌ Actual Behavior return 403
yindo added the 🐞 bug label 2026-02-21 18:14:18 -05:00
yindo closed this issue 2026-02-21 18:14:19 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 18, 2024):

Hello @dale22! I'm here to help you with any bugs, questions, or contributions you have regarding Dify. Let's tackle this issue together!

I found some similar discussions and issues related to the 403 Forbidden error when using Azure OpenAI with Dify:

  1. Help: I attempted to add my OpenAI key to my self-hosted Dify but was unsuccessful. - This discussion is unsolved and might provide some insights into similar issues.
  2. Connection error when set up model provider - Another unsolved discussion that might be relevant.
  3. APIError: HTTP code 403 from API - This issue is closed, but it might contain useful information.

To troubleshoot and resolve the 403 Forbidden error, consider the following steps:

  • Verify API Key and Endpoint: Ensure that the API key and endpoint URL in your .env file are correct. The specific environment variables related to Azure OpenAI configuration are AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_VERSION, and AZURE_OPENAI_DEPLOYMENT_NAME [1][2].

  • Check for Common Misconfigurations: Make sure that the deployment name and API version match the ones configured in Azure. Any mismatch can lead to authentication errors.

  • Authentication and Authorization: Dify uses an API key and Azure endpoint for authentication. Ensure that these credentials are correctly set up in your configuration files [3].

  • Quota and Rate Limits: Check if your Azure OpenAI account has exceeded its quota or rate limits. This can also result in a 403 error [4][5].

These steps should help you identify and resolve the issue. If the problem persists, reviewing the logs for more detailed error messages might provide additional clues.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 18, 2024): <!-- Greeting --> Hello @dale22! I'm here to help you with any bugs, questions, or contributions you have regarding Dify. Let's tackle this issue together! <!-- Answer --> I found some similar discussions and issues related to the 403 Forbidden error when using Azure OpenAI with Dify: 1. [Help: I attempted to add my OpenAI key to my self-hosted Dify but was unsuccessful.](https://github.com/langgenius/dify/discussions/9383) - This discussion is unsolved and might provide some insights into similar issues. 2. [Connection error when set up model provider](https://github.com/langgenius/dify/discussions/7839) - Another unsolved discussion that might be relevant. 3. [APIError: HTTP code 403 from API](https://github.com/langgenius/dify/issues/1546) - This issue is closed, but it might contain useful information. To troubleshoot and resolve the 403 Forbidden error, consider the following steps: - **Verify API Key and Endpoint**: Ensure that the API key and endpoint URL in your `.env` file are correct. The specific environment variables related to Azure OpenAI configuration are `AZURE_OPENAI_API_BASE`, `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_API_VERSION`, and `AZURE_OPENAI_DEPLOYMENT_NAME` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/pytest.ini)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/azure_openai/azure_openai.yaml)</sup>. - **Check for Common Misconfigurations**: Make sure that the deployment name and API version match the ones configured in Azure. Any mismatch can lead to authentication errors. - **Authentication and Authorization**: Dify uses an API key and Azure endpoint for authentication. Ensure that these credentials are correctly set up in your configuration files <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/azure_openai/_common.py)</sup>. - **Quota and Rate Limits**: Check if your Azure OpenAI account has exceeded its quota or rate limits. This can also result in a 403 error <sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/learn-more/faq/llms-use-faq.md)</sup><sup>[[5]](https://github.com/langgenius/dify-docs/blob/main/jp/learn-more/faq/llms-use-faq.md)</sup>. These steps should help you identify and resolve the issue. If the problem persists, reviewing the logs for more detailed error messages might provide additional clues. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@dale22 commented on GitHub (Oct 18, 2024):

1,set model is ok,so API Key and Endpoint and deployment name is ok
image
2,Curl requests on the same machine are fine
image
3,but dify chat is error, docker-api logs:403
image

@dale22 commented on GitHub (Oct 18, 2024): 1,set model is ok,so API Key and Endpoint and deployment name is ok ![image](https://github.com/user-attachments/assets/e3bb19de-4835-4122-ac23-503a089c260e) 2,Curl requests on the same machine are fine ![image](https://github.com/user-attachments/assets/c4dd051d-aaf4-43d2-abea-7f952aca317a) 3,but dify chat is error, docker-api logs:403 ![image](https://github.com/user-attachments/assets/a7f7b449-1b12-48b1-8d63-b4c180ce1481)
Author
Owner

@dale22 commented on GitHub (Oct 18, 2024):

chat return
image

@dale22 commented on GitHub (Oct 18, 2024): chat return ![image](https://github.com/user-attachments/assets/1d3b321b-0238-4d15-ac47-d4b4697f437e)
Author
Owner

@crazywoola commented on GitHub (Oct 18, 2024):

Please check the deployment in Azure Console, the 403 error is not raised by us.

@crazywoola commented on GitHub (Oct 18, 2024): Please check the deployment in Azure Console, the 403 error is not raised by us.
Author
Owner

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

Azure Console, feedback,Streaming requests are not yet allowed.
open ai is not support streaming , how can I close streaming param.
[
2024-10-21 08:05:21,141.141 ERROR [Thread-141 (_generate_worker)] [logging_callback.py:169] - Error code: 403 - {'message': 'Streaming requests are not yet allowed.'}
Traceback (most recent call last):
]

@dale22 commented on GitHub (Oct 21, 2024): Azure Console, feedback,Streaming requests are not yet allowed. open ai is not support streaming , how can I close streaming param. [ 2024-10-21 08:05:21,141.141 ERROR [Thread-141 (_generate_worker)] [logging_callback.py:169] - Error code: 403 - {'message': 'Streaming requests are not yet allowed.'} Traceback (most recent call last): ]
Author
Owner

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

2024-10-21 08:05:21,141.141 ERROR [Thread-141 (_generate_worker)] [logging_callback.py:169] - Error code: 403 - {'message': 'Streaming requests are not yet allowed.'}
Traceback (most recent call last):
File "/app/api/core/model_runtime/model_providers/__base/large_language_model.py", line 110, in invoke
result = self._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream, user)
File "/app/api/core/model_runtime/model_providers/azure_openai/llm/llm.py", line 55, in _invoke
return self._chat_generate(
File "/app/api/core/model_runtime/model_providers/azure_openai/llm/llm.py", line 331, in _chat_generate
response = client.chat.completions.create(
File "/app/api/.venv/lib/python3.10/site-packages/openai/_utils/_utils.py", line 277, in wrapper
return func(*args, **kwargs)
File "/app/api/.venv/lib/python3.10/site-packages/openai/resources/chat/completions.py", line 590, in create
return self._post(
File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 1240, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 921, in request
return self._request(
File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 1020, in _request
raise self._make_status_error_from_response(err.response) from None
openai.PermissionDeniedError: Error code: 403 - {'message': 'Streaming requests are not yet allowed.'}

@dale22 commented on GitHub (Oct 21, 2024): 2024-10-21 08:05:21,141.141 ERROR [Thread-141 (_generate_worker)] [logging_callback.py:169] - Error code: 403 - {'message': 'Streaming requests are not yet allowed.'} Traceback (most recent call last): File "/app/api/core/model_runtime/model_providers/__base/large_language_model.py", line 110, in invoke result = self._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream, user) File "/app/api/core/model_runtime/model_providers/azure_openai/llm/llm.py", line 55, in _invoke return self._chat_generate( File "/app/api/core/model_runtime/model_providers/azure_openai/llm/llm.py", line 331, in _chat_generate response = client.chat.completions.create( File "/app/api/.venv/lib/python3.10/site-packages/openai/_utils/_utils.py", line 277, in wrapper return func(*args, **kwargs) File "/app/api/.venv/lib/python3.10/site-packages/openai/resources/chat/completions.py", line 590, in create return self._post( File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 1240, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 921, in request return self._request( File "/app/api/.venv/lib/python3.10/site-packages/openai/_base_client.py", line 1020, in _request raise self._make_status_error_from_response(err.response) from None openai.PermissionDeniedError: Error code: 403 - {'message': 'Streaming requests are not yet allowed.'}
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6155