This is a thread I started discussing the very same question: Chat Completion Architechture
This is the new flowchart I put together which works to do exactly what you wish: Maintain the chat context between API calls:
And a video I put together showing the process in action: SolrAI: How the chat completion process with standalone question maintains conversational context - YouTube
Good luck!