How to continue incomplete response of openai API
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
An incomplete model response is usually a workflow problem rather than a model defect. In current OpenAI APIs, the practical approach is to detect why generation stopped, persist the partial output you already received, and then continue from that point with either the Responses API's stateful chaining features or an explicit continuation prompt.
First Identify Why the Response Stopped
Do not treat every truncated output as the same failure. A response may stop because:
- the model hit an output token limit
- the client timed out or the network dropped during streaming
- your own application cancelled the request
- the model refused or otherwise ended for a non-length reason
In the current OpenAI platform, the Responses API exposes response status details and supports chaining via previous_response_id. Older Chat Completions flows typically require checking finish_reason, especially length, and then continuing manually with more conversation context.
Continue a Response With the Responses API
If you are using the newer Responses API, keep the previous response ID and continue from it rather than reconstructing the conversation from scratch each time.
This is the cleanest pattern because the API can continue from the stored prior response rather than forcing you to replay a long transcript on every retry.
Recover Cleanly From Streaming Interruptions
If you are streaming output to the user, persist each chunk as it arrives. That way a connection drop does not erase everything the model already produced.
If the stream breaks, store text_so_far and either continue from the saved response ID or, if you are running statelessly, send the saved partial output back with a continuation instruction.
Continuation Without Stored Server State
Sometimes you do not want server-side response state, or you are bridging older code that uses Chat Completions. In that case, include the partial answer in context and ask the model to continue without repeating it.
In Chat Completions, inspect finish_reason. If it is length, that usually means the model reached the configured output limit and a continuation call is appropriate.
Prevent Duplicate Text When You Merge Chunks
Even with a careful prompt, continuation calls can overlap slightly with the previous chunk. Add a lightweight overlap merge step before presenting the final answer.
This avoids duplicated prefixes and makes the output look intentional instead of patched together.
Common Pitfalls
One common mistake is retrying the exact same request after a partial output without giving the model any continuation context. That often produces repeated text rather than a true continuation.
Another issue is assuming every stop means truncation. A refusal, timeout, cancellation, and token limit are operationally different events and should not be handled by one blind retry path.
Developers also often keep continuation loops unbounded. Put hard limits on rounds, total tokens, and elapsed time so a rare failure mode does not become a runaway cost problem.
Finally, do not discard partial output during streaming. Persisting chunks as they arrive is one of the simplest reliability improvements you can make.
Summary
- Detect why the response stopped before deciding how to continue it.
- With the Responses API, prefer chaining with
previous_response_idwhen possible. - In older stateless flows, send the partial answer back with an explicit continuation instruction.
- Merge resumed chunks carefully to avoid duplicate text.
- Put continuation logic behind clear limits for retries, rounds, and total output size.
Related reading
- How to control when to compute evaluation vs training using the Estimator API of tensorflow?
- How to convert a Hibernate proxy to a real entity object
- How to convert a Java 8 Stream to an Array?
- How to cope with x-forwarded-headers in Spring Boot 2.2.0? Spring Web MVC behind reverse proxy
- How to correct TypeError Unicode-objects must be encoded before hashing?
- How to cp file only if it does not exist, throw error otherwise?
- How to count objects in Tensorflow Object Detection API
- How to create a distributed system that performs a task and come to a consensus of result?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.