Skip to main content
Compared to traditional models, large language models let you anchor personas with custom prompts and pass conversation context, making multi-turn dialogs straightforward. Stepfun’s Chat Completion API accepts an array as the message list. Simply store user and assistant messages in order and send them back to the model to enable multi-turn conversations.

Implementing multi-turn chat

Persist conversations and messages in your system to build the conversation history.
  • Create a Chat when the user starts a conversation.
  • When the user sends a message, create a Message; fetch Messages in chronological order and pass them to the model so it can generate with context.
  • When the model responds, create another Message.

Conversation flow

Code example

Managing conversation context

step-5-preview supports a 1M-token context window; step-3.7-flash and the Step 3.5 Flash series support 256K. Manage history according to the selected model’s window and reserve space for output. Conversation history counts toward input tokens and cost, so choose an appropriate history length rather than always sending the full conversation.
  • For casual chat, keep roughly 10 turns.
  • For deep, high-context scenarios, pass the full conversation to the model.

FAQ

  • To achieve correct multi-turn behavior, store timestamps and supply messages to the model in chronological order so it can understand the context properly.