OpenAI Upload Completion Needs an Exact Byte Check
OpenAI Upload completion requires the bytes represented by the ordered part IDs to match the byte count declared when the Upload was created. A production client should calculate that total before completion, retain local part evidence, use the optional MD5 check when appropriate, and treat the returned File as a separate object with its own size field and lifecycle.

OpenAI's Uploads API makes the byte contract before the first part moves. The client declares bytes when it creates an Upload, adds parts that can arrive in parallel, then submits an ordered list of part IDs to complete the object. Completion requires the uploaded byte total to equal the original declaration. A green progress bar can reach 100% while the ordered completion set still omits a part or includes the wrong one.
I want the client to catch that mismatch before the completion request leaves. The provider remains the final authority, but a local completion receipt gives an operator something better than a failed POST and a pile of anonymous part IDs.
TL;DR
- Record the declared byte count, source-file digest, and Upload ID before sending any part.
- Track every part ID with its local byte count, digest, and source offset because the returned part object carries no byte total.
- Build the completion request from one ordered manifest and require its byte sum to equal the declared count.
- Preserve the completion response and created File ID as a new lifecycle record.
The byte contract begins at Upload creation
OpenAI's Create upload reference requires bytes, filename, mime_type, and purpose. The documented Upload limit is 8 GB, and the pending Upload expires one hour after creation. Those values belong in the local record alongside the source object's actual byte count and digest.
Calculate the source size from the exact byte stream that will be split. A character count, decoded text length, or pre-compression size is the wrong unit. If a worker normalizes line endings after the declaration, the transfer has already diverged from its contract.
Assign a stable local operation ID before creating the Upload. Bind it to the authenticated principal, tenant, source object version, declared byte count, hash, purpose, filename, MIME type, and creation response. The AI data lineage guide covers the wider chain between source material and model output. This record owns the narrower transition between one source byte stream and one OpenAI Upload.
Part evidence has to stay local
The Add upload part reference permits parts up to 64 MB and allows parallel uploads. Its returned Upload Part object identifies the part and parent Upload, but it publishes no byte-count or digest field for the part. A reliable client therefore keeps its own manifest.
Each manifest row should retain the OpenAI part ID, local sequence number, source offset, byte length, digest, attempt number, and transport outcome. Keep duplicate attempts as separate evidence. Select exactly one accepted part ID for each source range when building the completion set.
Completion order comes from the submitted part_ids array rather than network arrival order. Imagine three 64 MB tiles on a terminal screen finishing in the order 2, 1, 3. The completion manifest still needs 1, 2, 3. Sorting by response time quietly assembles a different file.
My blunt opinion is that a bare array of part IDs should fail production review. It proves almost nothing about which bytes the client believes each ID represents.
Completion needs a deterministic preflight
OpenAI's Complete upload reference states that the bytes uploaded at completion must match the number declared at creation. It also says the client controls part order through the ordered part_ids list. No parts can be added after completion.
Run four checks before the POST:
- Every source range appears exactly once in the selected manifest.
- Selected ranges are contiguous, start at byte zero, and end at the declared size.
- The sum of selected part byte lengths equals the declared
bytesvalue. - Reassembling the selected local chunks in completion order produces the original source digest.
The final digest check catches an equal-size substitution. Two parts can have the same byte length while carrying different content. Size equality closes one failure class; content identity closes another.
Do not invent a provider error code for a failed byte check. The current reference documents the completion requirement without promising one universal status or message. Preserve the actual response status, body, and request identifier received during the attempt.
The optional MD5 field adds a provider-side check
The completion request accepts an optional md5 value for verifying that uploaded bytes match the expected file content. Use it when the route's integrity policy permits MD5 for this compatibility check, while retaining a modern local digest such as SHA-256 for custody and later comparison.
The two values serve different records. OpenAI receives the optional MD5 as part of completion. A local SHA-256 stays with the application's source and part manifest. Never label MD5 as the audit digest merely because the API accepts it.
Record the checksum value sent, its encoding, the source bytes used to calculate it, and the completion response. If a route omits md5, store that omission as a deliberate state rather than leaving an ambiguous blank field.
The AI gateway file upload scanning guide addresses malware, type detection, tenant binding, and later file use. Completion integrity is a separate gate. A file can be byte-perfect and still violate content policy.
The created File starts another lifecycle
A successful completion response returns the Upload with status completed and a nested File object ready for use elsewhere on the platform. Store the Upload ID and File ID in separate fields. One identifies the multipart assembly operation; the other identifies the resulting platform object.
The reference allows the File object's bytes value to be null in a completed upload response when size is not yet available. The declared count and local manifest sum must already agree before completion. A null nested File size creates a follow-up observation state rather than permission to substitute zero or mark the record inconsistent.
Preserve the returned status, File ID, reported File bytes when present, purpose, expiry, and completion timestamp. A later model request that references the File ID needs its own authorization decision. The OpenAI API gateway pattern explains where that request-level control sits.
A destructive fixture should expose equal-size mistakes
Build a test source that spans four parts, with the final part shorter than 64 MB. Upload the parts in parallel and retain the source offset for each response. First, attempt local preflight with one part omitted. The byte sum should fail. Then replace a selected part with a different part of equal length. The sum should pass while the reassembled SHA-256 fails.
Next, scramble the part ID order. The preflight should reject the source-range sequence even though all expected IDs are present. Repeat completion after the Upload's one-hour expiry and preserve the provider's actual response without translating it into a made-up local cause.
Finally, simulate a connection loss after the completion POST leaves. Retrieve or reconcile the Upload state before sending another completion attempt. The test report should show one operation ID, each transport attempt, the observed Upload status, and the resulting File ID when one exists.
DeepInspect
DeepInspect can enforce policy on authenticated user or agent HTTP calls deliberately routed through its proxy, including OpenAI Upload creation, part, and completion requests. It can bind the caller and route policy to each allowed or denied exchange and preserve the provider response metadata that crosses the routed path.
The application owns source-byte calculation, chunk boundaries, local part digests, ordered-manifest construction, checksum generation, ambiguous-outcome reconciliation, and later File authorization. Calls that bypass the proxy remain outside DeepInspect's visibility. Keep the completion receipt in the application ledger and correlate it with the routed decision record.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Does OpenAI calculate the completion byte total?
OpenAI documents that the uploaded bytes at completion must match the count declared at Upload creation. The application should still calculate the total before dispatch so it can explain its selected part set and catch a mismatch without spending the completion attempt.
- Can the client use part response order as file order?
No. Parts can upload in parallel, and the client specifies final order through the
part_idsarray. Use source offsets or an immutable local sequence to build that array.- Is the optional MD5 value enough for the audit record?
Keep the MD5 sent to OpenAI as completion evidence. Retain a separate local SHA-256 digest for the source stream and reconstructed selected parts, together with the byte manifest and authenticated owner.
- What if the returned File bytes field is null?
Treat it as a pending observation. The current reference permits null when file size is not yet available in the completed response. Keep the validated declared count and local part total, then record the File size when the platform exposes it.