Conversation Prefix Continuation (Beta)
DeepSeek releases conversation prefix continuation in beta, letting developers seed assistant responses via the Chat Completions API using a prefix parameter at the beta base URL.
Conversation prefix continuation uses the Chat Completion API, where users provide messages beginning with assistant to have the model complete the rest of the message. Notes When using conversation prefix continuation, users must ensure that the last message in the messages list has a role of assistant, and set the prefix parameter of the last message to True. Users need to set base_url="https://api.deepseek.com/beta" to enable Beta features. Sample Code Below is a complete Python code example for conversation prefix continuation. In this example, we set the message beginning with assistant to "```python\n" to force the model to output Python code, and set the stop parameter to ['```'] to prevent additional explanations from the model.
from openai import OpenAI client = OpenAI( api_key="", base_url="https://api.deepseek.com/beta", ) messages = [ {"role": "user", "content": "Please write quick sort code"}, {"role": "assistant", "content": "```python\n", "prefix": True} ] response = client.chat.completions.create( model="deepseek-v4-pro", messages=messages, stop=["```"], ) print(response.choices[0].message.content)
- api-docs.deepseek.comConversation Prefix Continuation (Beta)primary