Deployment names are same as describled in the doc, but this error happened: The API deployment for this resource does not exist when using Azure openai service #285

Closed
opened 2026-02-21 17:26:39 -05:00 by yindo · 1 comment
Owner

Originally created by @zyh3826 on GitHub (Jul 19, 2023).

Dify version: Cloud | Self Host
Self Host 0.3.10

Steps To Reproduce

  1. docker compose up -d
  2. configure Azure openai service key
  3. send request

The current behavior

My Azure deployment:
image
My Azure key in dify:
image
configuration succeed, deployment names are same as described in the doc.
error log in docker-api-1:

Traceback (most recent call last):
  File "/app/api/core/llm/wrappers/openai_wrapper.py", line 14, in wrapper
    return func(*args, **kwargs)
  File "/app/api/core/llm/streamable_azure_open_ai.py", line 61, in generate
    return super().generate(prompts, stop, callbacks, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 279, in generate
    output = self._generate_helper(
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 223, in _generate_helper
    raise e
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 210, in _generate_helper
    self._generate(
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 308, in _generate
    for stream_resp in completion_with_retry(
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 90, in completion_with_retry
    return _completion_with_retry(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
  File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
  File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 314, in iter
    return fut.result()
  File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 88, in _completion_with_retry
    return llm.client.create(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/openai/api_resources/completion.py", line 25, in create
    return super().create(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
    response, _, api_key = requestor.request(
  File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 298, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 700, in _interpret_response
    self._interpret_response_line(
  File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 763, in _interpret_response_line
    raise self.handle_error_response(
openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.
INFO:openai:error_code=DeploymentNotFound error_message='The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.' error_param=None error_type=None message='OpenAI API error received' stream_error=False
ERROR:root:The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.
ERROR:root:Invalid request to OpenAI API.

But I test on my own, and everything is fine, Azure is available, code like this:

# Get configuration settings 
load_dotenv()
azure_oai_endpoint = os.getenv("AZURE_OAI_ENDPOINT")
azure_oai_key = os.getenv("AZURE_OAI_KEY")
azure_oai_model = os.getenv("AZURE_OAI_MODEL")

# Read text from file
text = 'The process of making maple syrup begins by tapping a spout (sometimes called a spile) into the sugar maple tree. The spile is inserted into the tree about 2 inches deep and the sap is collected as it flows out. The sap is then taken to a sugar shack where it is boiled down to concentrate the sugars. As the sap boils, water in the sap is evaporated and the syrup becomes more and more thick. Once the syrup reaches the right sugar content, which is usually when the boiling point reaches 219 degrees Fahrenheit, it is bottled and enjoyed.'

# Set OpenAI configuration settings
openai.api_type = "azure"
openai.api_base = azure_oai_endpoint
openai.api_version = "2023-03-15-preview"
openai.api_key = azure_oai_key

# Send request to Azure OpenAI model
print("Sending request for summary to Azure OpenAI endpoint...\n\n")
response = openai.ChatCompletion.create(
  engine=azure_oai_model,
  temperature=0.7,
  max_tokens=120,
  messages=[
  {"role": "system", "content": "You are a helpful assistant. Summarize the following text in 60 words or less."},
      {"role": "user", "content": text}
  ]
)

print("Summary: " + response.choices[0].message.content + "\n")

@takatost hope you can help me, thanks

Originally created by @zyh3826 on GitHub (Jul 19, 2023). <!-- Please provide a clear and concise description of what the bug is. Include screenshots if needed. Please test using the latest version of the relevant Dify packages to make sure your issue has not already been fixed. --> Dify version: Cloud | Self Host Self Host 0.3.10 ## Steps To Reproduce <!-- Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than Dify. Issues without reproduction steps or code examples may be immediately closed as not actionable. --> 1. docker compose up -d 2. configure Azure openai service key 3. send request ## The current behavior My Azure deployment: ![image](https://github.com/langgenius/dify/assets/31238754/f5785067-a66c-4272-8269-7b28ec46baab) My Azure key in dify: ![image](https://github.com/langgenius/dify/assets/31238754/279635a7-a125-441e-8bf2-8bbe364a942a) **configuration succeed, deployment names are same as described in the [doc](https://docs.dify.ai/getting-started/faq/llms-use-faq#1.-how-to-configure-and-use-azure-openai).** error log in `docker-api-1`: ``` Traceback (most recent call last): File "/app/api/core/llm/wrappers/openai_wrapper.py", line 14, in wrapper return func(*args, **kwargs) File "/app/api/core/llm/streamable_azure_open_ai.py", line 61, in generate return super().generate(prompts, stop, callbacks, **kwargs) File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 279, in generate output = self._generate_helper( File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 223, in _generate_helper raise e File "/usr/local/lib/python3.10/site-packages/langchain/llms/base.py", line 210, in _generate_helper self._generate( File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 308, in _generate for stream_resp in completion_with_retry( File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 90, in completion_with_retry return _completion_with_retry(**kwargs) File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f return self(f, *args, **kw) File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__ do = self.iter(retry_state=retry_state) File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 314, in iter return fut.result() File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 451, in result return self.__get_result() File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result raise self._exception File "/usr/local/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__ result = fn(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/langchain/llms/openai.py", line 88, in _completion_with_retry return llm.client.create(**kwargs) File "/usr/local/lib/python3.10/site-packages/openai/api_resources/completion.py", line 25, in create return super().create(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 298, in request resp, got_stream = self._interpret_response(result, stream) File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 700, in _interpret_response self._interpret_response_line( File "/usr/local/lib/python3.10/site-packages/openai/api_requestor.py", line 763, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again. INFO:openai:error_code=DeploymentNotFound error_message='The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.' error_param=None error_type=None message='OpenAI API error received' stream_error=False ERROR:root:The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again. ERROR:root:Invalid request to OpenAI API. ``` But I test on my own, and everything is fine, Azure is available, code like this: ```python # Get configuration settings load_dotenv() azure_oai_endpoint = os.getenv("AZURE_OAI_ENDPOINT") azure_oai_key = os.getenv("AZURE_OAI_KEY") azure_oai_model = os.getenv("AZURE_OAI_MODEL") # Read text from file text = 'The process of making maple syrup begins by tapping a spout (sometimes called a spile) into the sugar maple tree. The spile is inserted into the tree about 2 inches deep and the sap is collected as it flows out. The sap is then taken to a sugar shack where it is boiled down to concentrate the sugars. As the sap boils, water in the sap is evaporated and the syrup becomes more and more thick. Once the syrup reaches the right sugar content, which is usually when the boiling point reaches 219 degrees Fahrenheit, it is bottled and enjoyed.' # Set OpenAI configuration settings openai.api_type = "azure" openai.api_base = azure_oai_endpoint openai.api_version = "2023-03-15-preview" openai.api_key = azure_oai_key # Send request to Azure OpenAI model print("Sending request for summary to Azure OpenAI endpoint...\n\n") response = openai.ChatCompletion.create( engine=azure_oai_model, temperature=0.7, max_tokens=120, messages=[ {"role": "system", "content": "You are a helpful assistant. Summarize the following text in 60 words or less."}, {"role": "user", "content": text} ] ) print("Summary: " + response.choices[0].message.content + "\n") ``` @takatost hope you can help me, thanks
yindo closed this issue 2026-02-21 17:26:39 -05:00
Author
Owner

@zyh3826 commented on GitHub (Jul 20, 2023):

I find the solution, seems like the default model is text-davinci-003, but as 584 says, so need to set the model to gpt-35-turbo manually in prompt eng, maybe this is a bug

@zyh3826 commented on GitHub (Jul 20, 2023): I find the solution, seems like the default model is `text-davinci-003`, but as [584](https://github.com/langgenius/dify/issues/584) says, so need to set the model to `gpt-35-turbo` manually in `prompt eng`, maybe this is a bug
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#285