X media upload APPEND: 5 MB chunks, and how to split a Sume MP4

The X API v2 APPEND step takes chunks of at most 5 MB. Count the segments for a Sume MP4 with a short script before you upload to the initialize endpoint.

5 min readSume
All posts

On the X API v2, each APPEND request carries one chunk of at most 5 MB, after INIT returns a media_id and before FINALIZE completes the upload. For a Sume MP4, read the file in 5 MB pieces, number each piece as a segment, and upload them in order.

What are the four steps?

The chunked quickstart lists four endpoints.

X chunked media upload steps (read 2026-10-05)
StepRequestNotes
INITPOST /2/media/upload/initializeReturns media_id; send media_type, total_bytes, media_category
APPENDPOST /2/media/upload/{id}/appendChunks of at most 5 MB each
FINALIZEPOST /2/media/upload/{id}/finalizeMay return processing_info
STATUSGET /2/media/uploadPoll while processing

How many chunks will my file need?

Use 5,000,000 bytes as the chunk size to stay under 5 MB however the vendor counts a megabyte. The script builds a stand-in file, so it runs anywhere; point path at your downloaded MP4 for a real count.

import math, os, tempfile

CHUNK = 5_000_000

def chunks(path):
    with open(path, "rb") as f:
        index = 0
        while block := f.read(CHUNK):
            yield index, block
            index += 1

with tempfile.NamedTemporaryFile(delete=False) as t:
    t.write(os.urandom(12_000_000))
size = os.path.getsize(t.name)
print(size, "bytes ->", math.ceil(size / CHUNK), "chunks")
print([(i, len(b)) for i, b in chunks(t.name)])
os.unlink(t.name)

What does Sume add?

Sume returns a durable media.sume.com MP4, which you download before the upload. The X page says media uploads can fail validation at post time when they exceed the entitlements of the authenticated user, so trim first if the file is close to a limit. A trim job costs $0.02 per the Sume docs.

Sources

Related posts

More in Integrations

All Integrations posts

Written by Sume