Is there any method using openai format api to request the chat application #8785

Closed
opened 2026-02-21 18:27:36 -05:00 by yindo · 7 comments
Owner

Originally created by @gabrielpondc on GitHub (Feb 28, 2025).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

Is there any method using openai format api to request the Chat App API of the dify

for example

{
  "model": "gpt-4-turbo",
  "messages": [
    {"role": "system", "content": "hellow"},
    {"role": "user", "content": "Hello,OpenAI API"}
  ],
  "temperature": 0.7,
  "max_tokens": 100,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}

if i using the original API

{
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123",
    "files": [
      {
        "type": "image",
        "transfer_method": "remote_url",
        "url": "https://cloud.dify.ai/logo/logo-site.png"
      }
    ]
}

is not easy integrate the dify to own project with OpenAI package and if i need to control the messages i need control the history.Since have chosen to open-source the project, wouldn’t it be better to use a universal interface and adhere to open-source standards. What I don't understand is that when initially developing an open-source project, one should consider that the very purpose of open-source projects is to reduce repetitive development work for future developers. If, when using OpenAI's SDK, simply entering the URL does not allow us to successfully call the API, then what is the purpose of providing an open API? Is it intended for secondary development for the personal project?

Originally created by @gabrielpondc on GitHub (Feb 28, 2025). ### Self Checks - [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 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. ### Provide a description of requested docs changes Is there any method using openai format api to request the Chat App API of the dify for example ``` { "model": "gpt-4-turbo", "messages": [ {"role": "system", "content": "hellow"}, {"role": "user", "content": "Hello,OpenAI API"} ], "temperature": 0.7, "max_tokens": 100, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0 } ``` if i using the original API ``` { "inputs": {}, "query": "What are the specs of the iPhone 13 Pro Max?", "response_mode": "streaming", "conversation_id": "", "user": "abc-123", "files": [ { "type": "image", "transfer_method": "remote_url", "url": "https://cloud.dify.ai/logo/logo-site.png" } ] } ``` is not easy integrate the dify to own project with OpenAI package and if i need to control the messages i need control the history.Since have chosen to open-source the project, wouldn’t it be better to use a universal interface and adhere to open-source standards. What I don't understand is that when initially developing an open-source project, one should consider that the very purpose of open-source projects is to reduce repetitive development work for future developers. If, when using OpenAI's SDK, simply entering the URL does not allow us to successfully call the API, then what is the purpose of providing an open API? Is it intended for secondary development for the personal project?
yindo added the 📚 documentation label 2026-02-21 18:27:36 -05:00
yindo closed this issue 2026-02-21 18:27:36 -05:00
Author
Owner

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

To request the Chat App API of Dify using the OpenAI format API and integrate it into a project while controlling message history, you can follow these steps:

  1. Generate an API Key: First, generate an API key for security purposes to access the AI application. Ensure that the API key is managed securely and not exposed in front-end code to prevent misuse.

  2. Retrieve a Session ID: After initiating a chat with the AI application, obtain a session ID (conversation_id) from the API response. This ID is crucial for maintaining the conversation history.

  3. Invoke the API: Use the following sample request code to call the AI application via the API. Initially, use an empty conversation_id to start a new conversation. The system will generate and return a new conversation_id, which should be used in subsequent requests to maintain the conversation history.

curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "query": "eh",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123"
}'

Replace ENTER-YOUR-SECRET-KEY with your actual API key. For subsequent requests, update the conversation_id with the one received in the response to continue the chat.

Additionally, Dify API will be compatible with the OpenAI SDK in version 1.0.0 through two plugins: oaicompat_dify_model and oaicompat_dify_app. These plugins will be available in the Dify marketplace, allowing for seamless integration into any OpenAI SDK-compatible location without requiring separate development for each integration point. You can find these plugins at:

This method allows you to integrate the Dify Chat App API into your project using the OpenAI package while controlling the message history by managing the conversation_id [1][2][3].

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 28, 2025): <!-- Answer --> To request the Chat App API of Dify using the OpenAI format API and integrate it into a project while controlling message history, you can follow these steps: 1. **Generate an API Key**: First, generate an API key for security purposes to access the AI application. Ensure that the API key is managed securely and not exposed in front-end code to prevent misuse. 2. **Retrieve a Session ID**: After initiating a chat with the AI application, obtain a session ID (`conversation_id`) from the API response. This ID is crucial for maintaining the conversation history. 3. **Invoke the API**: Use the following sample request code to call the AI application via the API. Initially, use an empty `conversation_id` to start a new conversation. The system will generate and return a new `conversation_id`, which should be used in subsequent requests to maintain the conversation history. ```bash curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ "inputs": {}, "query": "eh", "response_mode": "streaming", "conversation_id": "", "user": "abc-123" }' ``` Replace `ENTER-YOUR-SECRET-KEY` with your actual API key. For subsequent requests, update the `conversation_id` with the one received in the response to continue the chat. Additionally, Dify API will be compatible with the OpenAI SDK in version 1.0.0 through two plugins: `oaicompat_dify_model` and `oaicompat_dify_app`. These plugins will be available in the Dify marketplace, allowing for seamless integration into any OpenAI SDK-compatible location without requiring separate development for each integration point. You can find these plugins at: - https://marketplace.dify.ai/plugins/langgenius/oaicompat_dify_model - https://marketplace.dify.ai/plugins/langgenius/oaicompat_dify_app This method allows you to integrate the Dify Chat App API into your project using the OpenAI package while controlling the message history by managing the `conversation_id` <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/jp/learn-more/use-cases/build-an-notion-ai-assistant.md)</sup><sup>[[2]](https://github.com/langgenius/dify/issues/14131)</sup><sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/application-publishing/developing-with-apis.md)</sup>. <!-- 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/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7856a211-5d21-435f-a2f5-1080e37df748?feedback_type=other)</sup>
Author
Owner

@gabrielpondc commented on GitHub (Feb 28, 2025):

but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem @dosu

@gabrielpondc commented on GitHub (Feb 28, 2025): but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem @dosu
Author
Owner

@crazywoola commented on GitHub (Mar 1, 2025):

For questions please use discussion instead.

@crazywoola commented on GitHub (Mar 1, 2025): For questions please use discussion instead.
Author
Owner

@dosubot[bot] commented on GitHub (Mar 1, 2025):

The last_user_message memory mode in the OpenAI Compatible Dify App means that only the most recent user message is retained in memory for processing. This can limit the ability to maintain a full conversation history, as it doesn't store previous interactions beyond the last message. This mode is useful for scenarios where only the latest input is relevant, but it may not be ideal for applications requiring context from earlier messages.

To address this limitation, you might need to implement additional logic in your application to manage and store conversation history externally, allowing you to reconstruct the context as needed for each API call. This approach can help you maintain a more comprehensive conversation history while using the last_user_message mode.

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 (Mar 1, 2025): <!-- Answer --> The `last_user_message` memory mode in the OpenAI Compatible Dify App means that only the most recent user message is retained in memory for processing. This can limit the ability to maintain a full conversation history, as it doesn't store previous interactions beyond the last message. This mode is useful for scenarios where only the latest input is relevant, but it may not be ideal for applications requiring context from earlier messages. To address this limitation, you might need to implement additional logic in your application to manage and store conversation history externally, allowing you to reconstruct the context as needed for each API call. This approach can help you maintain a more comprehensive conversation history while using the `last_user_message` mode. <!-- 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/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/bf76970e-4e35-4d20-bdfa-d2f49f5e2635?feedback_type=other)</sup>
Author
Owner

@hwb96 commented on GitHub (Mar 1, 2025):

but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem

What does this mean? Can't the control of historical sessions be resolved by passing in the history QAQA? I haven't used this new 1.0.0, I thought it was completely compatible with OpenAI.

@hwb96 commented on GitHub (Mar 1, 2025): > but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem What does this mean? Can't the control of historical sessions be resolved by passing in the history QAQA? I haven't used this new 1.0.0, I thought it was completely compatible with OpenAI.
Author
Owner

@gabrielpondc commented on GitHub (Mar 2, 2025):

but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem

What does this mean? Can't the control of historical sessions be resolved by passing in the history QAQA? I haven't used this new 1.0.0, I thought it was completely compatible with OpenAI.

yup,i have tried the OpenAI Compatible Dify App , it could not using history QAQA to control history, It's only support last user message

Image
@gabrielpondc commented on GitHub (Mar 2, 2025): > > but OpenAI Compatible Dify App only supports last_user_message memory mode , it still not deal the problem > > What does this mean? Can't the control of historical sessions be resolved by passing in the history QAQA? I haven't used this new 1.0.0, I thought it was completely compatible with OpenAI. yup,i have tried the OpenAI Compatible Dify App , it could not using history QAQA to control history, It's only support last user message <img width="411" alt="Image" src="https://github.com/user-attachments/assets/3fadc78e-127e-4afc-8315-28bc097e005f" />
Author
Owner

@gabrielpondc commented on GitHub (Mar 11, 2025):

if some one wanna use the function of these could use fastgpt platform as an alternative to solve this problem, directly using the class openai interface in the messages of the chat app and workflow to control the history of conversations, and I think fastgpt's workflow setup is a little more intuitive, will not be tied to the chatid, just if you pass the If you pass the chatid, it won't create a new conversation, but if you don't pass it, it will create a new conversation, I think this is very good, more suitable for enterprise development program.

@gabrielpondc commented on GitHub (Mar 11, 2025): if some one wanna use the function of these could use[ fastgpt](https://github.com/labring/FastGPT) platform as an alternative to solve this problem, directly using the class openai interface in the messages of the chat app and workflow to control the history of conversations, and I think fastgpt's workflow setup is a little more intuitive, will not be tied to the chatid, just if you pass the If you pass the chatid, it won't create a new conversation, but if you don't pass it, it will create a new conversation, I think this is very good, more suitable for enterprise development program.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#8785