[GH-ISSUE #21] deepseek-reasoner does not support successive user or assistant messages #21

Closed
opened 2026-10-26 21:10:51 +00:00 by bsakaguchi · 22 comments
Owner

Originally created by @Sariel2 on GitHub (Jan 21, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/21

{"error":{"message":"deepseek-reasoner does not support successive user or assistant messages (messages[1] and messages[2] in your input). You should interleave the user/assistant messages in the message sequence.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

when i use deepseek-reasoner in cursor, error like this.

Originally created by @Sariel2 on GitHub (Jan 21, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/21 > {"error":{"message":"deepseek-reasoner does not support successive user or assistant messages (messages[1] and messages[2] in your input). You should interleave the user/assistant messages in the message sequence.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}} when i use deepseek-reasoner in cursor, error like this.
bsakaguchi 2026-10-26 21:10:51 +00:00
Author
Owner

@YuBai630 commented on GitHub (Jan 21, 2025):

I meet the same problem.

<!-- gh-comment-id:2603778213 --> @YuBai630 commented on GitHub (Jan 21, 2025): I meet the same problem.
Author
Owner

@Sariel2 commented on GitHub (Jan 21, 2025):

In the same CONFIG, deepseek-chat model could reply success.

<!-- gh-comment-id:2603793912 --> @Sariel2 commented on GitHub (Jan 21, 2025): In the same CONFIG, deepseek-chat model could reply success.
Author
Owner

@Julianlaue commented on GitHub (Jan 21, 2025):

I encountered the same issue. It's very weird. I tried multiple times with and without context. Interestingly, it worked without context when using the @ symbol. After having a normal conversation without context and gradually introducing context, it started working. Now, it consistently works, even when directly introducing context via the @ symbol. It’s very strange, but I suggest trying it multiple times with different versions of context until it works.

<!-- gh-comment-id:2603858056 --> @Julianlaue commented on GitHub (Jan 21, 2025): I encountered the same issue. It's very weird. I tried multiple times with and without context. Interestingly, it worked without context when using the @ symbol. After having a normal conversation without context and gradually introducing context, it started working. Now, it consistently works, even when directly introducing context via the @ symbol. It’s very strange, but I suggest trying it multiple times with different versions of context until it works.
Author
Owner

@engalisabry commented on GitHub (Jan 21, 2025):

Issue Description

The error occurs when using deepseek-reasoner with successive user or assistant messages (e.g., messages[1] and messages[2] being of the same role). The model expects interleaved user/assistant messages in the message sequence.

Why This Happens

  • The deepseek-reasoner model is designed to follow a strict conversational format, where user and assistant messages must alternate.
  • Successive messages of the same role (e.g., two user messages in a row) violate this format, leading to the invalid_request_error.

Workarounds and Solutions

  1. Interleave Messages Correctly:
    Ensure that the message sequence alternates between user and assistant roles. For example:

    [
      {"role": "user", "content": "Hello!"},
      {"role": "assistant", "content": "Hi! How can I help?"},
      {"role": "user", "content": "Tell me about DeepSeek R1."}
    ]
    
    
  2. Avoid Successive Same-Role Messages:
    If your input contains multiple user or assistant messages in a row, merge them into a single message. For example:

  • Before::

        [
          {"role": "user", "content": "Hello!"},
          {"role": "user", "content": "Tell me about DeepSeek R1."}
       ]
    
    
  • After::

      [
       {"role": "user", "content": "Hello! Tell me about DeepSeek R1."}
     ]
    
    

3. Gradually Introduce Context (As Reported by @Julianlaue)

  • Start with a simple conversation (no context).
  • Gradually introduce context using the @ symbol or other methods.
  • This approach seems to help the model adapt to the input format.

Why deepseek-chat Works Differently

The deepseek-chat model may have a more flexible input format, allowing successive messages of the same role. This difference in behavior is due to the distinct training and design goals of the two models.

<!-- gh-comment-id:2604700253 --> @engalisabry commented on GitHub (Jan 21, 2025): #### **Issue Description** The error occurs when using `deepseek-reasoner` with successive user or assistant messages (e.g., `messages[1]` and `messages[2]` being of the same role). The model expects **interleaved user/assistant messages** in the message sequence. #### **Why This Happens** - The `deepseek-reasoner` model is designed to follow a **strict conversational format**, where user and assistant messages must alternate. - Successive messages of the same role (e.g., two user messages in a row) violate this format, leading to the `invalid_request_error`. --- #### **Workarounds and Solutions** 1. **Interleave Messages Correctly:** Ensure that the message sequence alternates between `user` and `assistant` roles. For example: ```json [ {"role": "user", "content": "Hello!"}, {"role": "assistant", "content": "Hi! How can I help?"}, {"role": "user", "content": "Tell me about DeepSeek R1."} ] 2. **Avoid Successive Same-Role Messages:** If your input contains multiple user or assistant messages in a row, merge them into a single message. For example: - **Before::** ```json [ {"role": "user", "content": "Hello!"}, {"role": "user", "content": "Tell me about DeepSeek R1."} ] - **After::** ```json [ {"role": "user", "content": "Hello! Tell me about DeepSeek R1."} ] #### **3. Gradually Introduce Context (As Reported by @Julianlaue)** - Start with a simple conversation (no context). - Gradually introduce context using the `@` symbol or other methods. - This approach seems to help the model adapt to the input format. --- #### **Why `deepseek-chat` Works Differently** The `deepseek-chat` model may have a more flexible input format, allowing successive messages of the same role. This difference in behavior is due to the distinct training and design goals of the two models.
Author
Owner

@Zijie-Tian commented on GitHub (Jan 22, 2025):

Same Issue !!!

<!-- gh-comment-id:2607110645 --> @Zijie-Tian commented on GitHub (Jan 22, 2025): Same Issue !!!
Author
Owner

@namp commented on GitHub (Jan 22, 2025):

Possible solution?

https://x.com/rohanpaul_ai/status/1881378066603126874

<!-- gh-comment-id:2607437769 --> @namp commented on GitHub (Jan 22, 2025): Possible solution? https://x.com/rohanpaul_ai/status/1881378066603126874
Author
Owner

@xiaoxu193 commented on GitHub (Jan 24, 2025):

Running into this while using Cursor with deepseek-reasoner.

<!-- gh-comment-id:2611359111 --> @xiaoxu193 commented on GitHub (Jan 24, 2025): Running into this while using Cursor with deepseek-reasoner.
Author
Owner

@CH0918 commented on GitHub (Jan 24, 2025):

Remove the global settings for Rules for AI and you're good to go.

Image
<!-- gh-comment-id:2612829423 --> @CH0918 commented on GitHub (Jan 24, 2025): Remove the global settings for Rules for AI and you're good to go. <img width="582" alt="Image" src="https://github.com/user-attachments/assets/591af199-d382-4229-89f8-7192384d9cc3" />
Author
Owner

@Slim0729 commented on GitHub (Jan 25, 2025):

Remove the global settings for Rules for AI and you're good to go.

Image

Thanks. It works!

<!-- gh-comment-id:2613739652 --> @Slim0729 commented on GitHub (Jan 25, 2025): > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc3NzMyNDIsIm5iZiI6MTczNzc3Mjk0MiwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDAyNDIyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM4OTBjMzI5MTI2Nzg5MzMwOTM4YTNjMzMzN2Q0ODAyNTE5MTIzNTk2Nzc2Y2FiNmUzNTM4NmFkMGEyOTI0YTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3li6GkoTH5j0-irTrUdQ1euXEk1aduiGLw07eOAKxJI"> Thanks. It works!
Author
Owner

@fengerzh commented on GitHub (Jan 25, 2025):

Remove the global settings for Rules for AI and you're good to go.

Image

No, I've already empty the setting for Rules for AI, and even uncheck the Include .cursorrules file option, but it still refuse to answer.

<!-- gh-comment-id:2613974541 --> @fengerzh commented on GitHub (Jan 25, 2025): > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc4MTM1NjUsIm5iZiI6MTczNzgxMzI2NSwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDEzNTQyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkOGFlYjA3MzhmZDU1MzkzZjc2MTIxYjYxOTI4NzJmYzM1NTY1ODBlODM1OWY3ZWQzMjgyZWE4MGVjYTRjNTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.89B2qs9lsCCsuEi7NK-7k7nhsOM6sKvxads9TbrmXX0"> No, I've already empty the setting for Rules for AI, and even uncheck the `Include .cursorrules file` option, but it still refuse to answer.
Author
Owner

@li2109 commented on GitHub (Jan 25, 2025):

Remove the global settings for Rules for AI and you're good to go.
Image

No, I've already empty the setting for Rules for AI, and even uncheck the Include .cursorrules file option, but it still refuse to answer.

+1

<!-- gh-comment-id:2613991058 --> @li2109 commented on GitHub (Jan 25, 2025): > > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc4MTM1NjUsIm5iZiI6MTczNzgxMzI2NSwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDEzNTQyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkOGFlYjA3MzhmZDU1MzkzZjc2MTIxYjYxOTI4NzJmYzM1NTY1ODBlODM1OWY3ZWQzMjgyZWE4MGVjYTRjNTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.89B2qs9lsCCsuEi7NK-7k7nhsOM6sKvxads9TbrmXX0"> > > No, I've already empty the setting for Rules for AI, and even uncheck the `Include .cursorrules file` option, but it still refuse to answer. +1
Author
Owner

@di-su commented on GitHub (Jan 25, 2025):

Remove the global settings for Rules for AI and you're good to go.

Image

weird, sometimes work, sometimes doesnt

<!-- gh-comment-id:2614120932 --> @di-su commented on GitHub (Jan 25, 2025): > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc4NDE5NzUsIm5iZiI6MTczNzg0MTY3NSwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDIxNDc1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYxNTM5ZWY2MzA5NzIxNTg5YmNjZWYxNTgxMTExZjFlOTBhOTVlNDc2MzE4OGQ4YTVhMTBjZDVhYTEzNWFlYzgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.PJk5ZJzWPD_HZdGlEjwUXjVyl_15oOfdxukvXH1Omf8"> weird, sometimes work, sometimes doesnt
Author
Owner

@clinchcc commented on GitHub (Jan 26, 2025):

The same isuue

<!-- gh-comment-id:2614290623 --> @clinchcc commented on GitHub (Jan 26, 2025): The same isuue
Author
Owner

@akilcelen commented on GitHub (Jan 26, 2025):

anyone found a solution?

<!-- gh-comment-id:2614543900 --> @akilcelen commented on GitHub (Jan 26, 2025): anyone found a solution?
Author
Owner

@Hanif-adedotun commented on GitHub (Jan 27, 2025):

Remove the global settings for Rules for AI and you're good to go.
Image

No, I've already empty the setting for Rules for AI, and even uncheck the Include .cursorrules file option, but it still refuse to answer.

+1

Thanks, this worked for me.

<!-- gh-comment-id:2615227188 --> @Hanif-adedotun commented on GitHub (Jan 27, 2025): > > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc4MTM1NjUsIm5iZiI6MTczNzgxMzI2NSwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDEzNTQyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkOGFlYjA3MzhmZDU1MzkzZjc2MTIxYjYxOTI4NzJmYzM1NTY1ODBlODM1OWY3ZWQzMjgyZWE4MGVjYTRjNTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.89B2qs9lsCCsuEi7NK-7k7nhsOM6sKvxads9TbrmXX0"> > > No, I've already empty the setting for Rules for AI, and even uncheck the `Include .cursorrules file` option, but it still refuse to answer. +1 Thanks, this worked for me.
Author
Owner

@luojiyin1987 commented on GitHub (Jan 31, 2025):

Image

no include .cursorrrules files.

<!-- gh-comment-id:2626714261 --> @luojiyin1987 commented on GitHub (Jan 31, 2025): ![Image](https://github.com/user-attachments/assets/23ea522b-f89b-4742-8e45-cf8935983d36) no include .cursorrrules files.
Author
Owner

@AuroraGeeker commented on GitHub (Feb 8, 2025):

Image

Modifying the value of the Base URL makes it work. To do this, delete the suffix "/v1" in the Base URL.

<!-- gh-comment-id:2644389809 --> @AuroraGeeker commented on GitHub (Feb 8, 2025): ![Image](https://github.com/user-attachments/assets/17ebc2f6-b4c8-47b2-9428-eb347f74d9bd) Modifying the value of the `Base URL` makes it work. To do this, **delete the suffix `"/v1"` in the `Base URL`**.
Author
Owner

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

Image

修改 的值Base URL即可使其起作用。为此,请删除中的****后缀"/v1"``Base URL。

我这没用

<!-- gh-comment-id:2712697251 --> @kikyoulg commented on GitHub (Mar 11, 2025): > ![Image](https://github.com/user-attachments/assets/17ebc2f6-b4c8-47b2-9428-eb347f74d9bd) > > 修改 的值`Base URL`即可使其起作用。为此,请删除**中的****后缀`"/v1"``Base URL`**。 我这没用
Author
Owner

@gykxjtu commented on GitHub (Apr 4, 2025):

Same issue in Emacs gptel when resume previous session.

<!-- gh-comment-id:2778660746 --> @gykxjtu commented on GitHub (Apr 4, 2025): Same issue in Emacs gptel when resume previous session.
Author
Owner

@Mr-houzi commented on GitHub (Apr 21, 2025):

Remove the global settings for Rules for AI and you're good to go.
Image

No, I've already empty the setting for Rules for AI, and even uncheck the Include .cursorrules file option, but it still refuse to answer.

use a new chat

<!-- gh-comment-id:2817892058 --> @Mr-houzi commented on GitHub (Apr 21, 2025): > > Remove the global settings for Rules for AI and you're good to go. > > <img alt="Image" width="582" src="https://private-user-images.githubusercontent.com/23649507/406497322-591af199-d382-4229-89f8-7192384d9cc3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzc4MTM1NjUsIm5iZiI6MTczNzgxMzI2NSwicGF0aCI6Ii8yMzY0OTUwNy80MDY0OTczMjItNTkxYWYxOTktZDM4Mi00MjI5LTg5ZjgtNzE5MjM4NGQ5Y2MzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAxMjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMTI1VDEzNTQyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJkOGFlYjA3MzhmZDU1MzkzZjc2MTIxYjYxOTI4NzJmYzM1NTY1ODBlODM1OWY3ZWQzMjgyZWE4MGVjYTRjNTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.89B2qs9lsCCsuEi7NK-7k7nhsOM6sKvxads9TbrmXX0"> > > No, I've already empty the setting for Rules for AI, and even uncheck the `Include .cursorrules file` option, but it still refuse to answer. use a new chat
Author
Owner

@github-actions[bot] commented on GitHub (Jun 1, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!

<!-- gh-comment-id:2926056725 --> @github-actions[bot] commented on GitHub (Jun 1, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
Author
Owner

@github-actions[bot] commented on GitHub (Jun 18, 2025):

false

<!-- gh-comment-id:2982177296 --> @github-actions[bot] commented on GitHub (Jun 18, 2025): false
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-R1#21
No description provided.