If an X API media upload fails with HTTP 400 and "One or more parameters to your request was invalid.", check which protocol you are speaking before you check the file. The old chunked upload posted command=INIT, command=APPEND and command=FINALIZE as form fields to /2/media/upload. X no longer accepts that shape. Its current docs split the flow into three paths: POST /2/media/upload/initialize with a JSON body, POST /2/media/upload/{id}/append per chunk, and POST /2/media/upload/{id}/finalize. Move to those and the 400 goes away. The working code is below.
What does the error look like?
The refusal comes back from the first upload call, before any bytes move. On 19 November 2026 our X lane tried to attach an image to a scheduled post and got this, with nothing else in the body worth reading:
X media upload failed at initialize for image 1 of 1: HTTP 400 - One or more parameters to your request was invalid. The first line is our own wrapper, which names the step and the file. The second is X's. The same code had published media to X without trouble until our last media post on 23 August 2026. Nothing changed on our side in between. The only trace we found afterwards is a changelog entry of 1 September 2026, which says the chunked upload quickstart now uses the v2 paths instead of the previous command-style flow. It reads like a docs update, not a shutdown notice, which is why the error looks like a bug in your request rather than a retired endpoint.
Two things make this one confusing. The message is generic, so it reads like a typo in a field. And if your code reports a failed upload as a failed post, the person reading the log goes looking for a problem in the caption. Ours did exactly that at first: the Studio said X had rejected the post as invalid, when X had refused only the image upload.
What changed in the X API media upload flow?
X moved chunked uploads to one path per step and left the base endpoint for small one-shot uploads. The chunked upload quickstart documents the current flow:
| Step | Old command-style request | Current request |
|---|---|---|
| Start | POST /2/media/upload with command=INIT | POST /2/media/upload/initialize, JSON { media_type, total_bytes, media_category } |
| Send bytes | POST /2/media/upload with command=APPEND | POST /2/media/upload/{id}/append, multipart segment_index + media |
| Finish | POST /2/media/upload with command=FINALIZE | POST /2/media/upload/{id}/finalize, no body |
| Check processing | GET /2/media/upload?command=STATUS&media_id=... | unchanged |
The status check is the one place command= survives, which is easy to miss when you search your code for it.
This is the second migration in a row. X's changelog records the launch of the v2 media upload endpoints on 16 January 2025 and the dedicated chunked endpoints on 30 April 2025. Code that moved from v1.1 to v2 by changing only the host kept the command fields, worked for a while, and now breaks. Ours did.
How do I upload media with the new endpoints?
Send three kinds of request and poll if X asks you to. This is the Node code from our X lane's fix of 19 November 2026, trimmed to the calls. It needs Node 18 or newer for fetch, FormData and Blob:
import fs from "node:fs"; import path from "node:path"; const MEDIA_API = "https://api.x.com/2/media"; const CHUNK = 4 * 1024 * 1024; // X advises at most 5 MB per segment async function call(method, url, { token, json, form } = {}) { const headers = { Authorization: `Bearer ${token}` }; let body; if (json) { headers["Content-Type"] = "application/json"; body = JSON.stringify(json); } if (form) body = form; const res = await fetch(url, { method, headers, body }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(`HTTP ${res.status} - ${data.detail || data.title || res.statusText}`); return data; } export async function uploadMedia(file, mime, category, token) { const buf = fs.readFileSync(file); const init = await call("POST", `${MEDIA_API}/upload/initialize`, { token, json: { media_type: mime, total_bytes: buf.length, media_category: category }, }); const id = init.data.id; for (let i = 0; i * CHUNK < buf.length; i++) { const form = new FormData(); form.append("segment_index", String(i)); form.append("media", new Blob([buf.subarray(i * CHUNK, (i + 1) * CHUNK)], { type: mime }), path.basename(file)); await call("POST", `${MEDIA_API}/upload/${id}/append`, { token, form }); } const fin = await call("POST", `${MEDIA_API}/upload/${id}/finalize`, { token }); let proc = fin.data?.processing_info; while (proc && proc.state !== "succeeded") { if (proc.state === "failed") throw new Error(`processing failed: ${proc.error?.message || "unknown"}`); await new Promise((r) => setTimeout(r, (proc.check_after_secs || 5) * 1000)); const s = await call("GET", `${MEDIA_API}/upload?command=STATUS&media_id=${id}`, { token }); proc = s.data?.processing_info; } return id; } Call it with uploadMedia("cover.jpg", "image/jpeg", "tweet_image", token), or video/mp4 with tweet_video, then create the post with POST /2/tweets and { "text": "...", "media": { "media_ids": [id] } }. A response without processing_info is ready to use, which is the normal case for images.
How do I add alt text, and which scope does the token need?
Alt text is one more call after finalize: POST /2/media/metadata with { "id": "<media id>", "metadata": { "alt_text": { "text": "..." } } }. X's metadata reference caps the text at 1000 characters, so we cut it there. Our lane treats this call as optional: if it fails, the post still goes out, without the description.
The bearer token is an OAuth 2.0 user token with the media.write scope on top of tweet.write. X's OAuth 2.0 guide lists it as the scope for uploading media. If you add the scope to an existing app, older tokens do not gain it: the user has to authorize again. We also sign the same endpoints with OAuth 1.0a user keys for accounts set up that way; the JSON and multipart bodies are not part of the signature, the status query parameters are.
Which other upload errors should I expect?
Most of the rest are size and type limits, and X checks some of them only when you attach the media to a post. As of December 2026, X's media docs list these limits:
| Media | Category | Limit |
|---|---|---|
| Image | tweet_image | 5 MB |
| Animated GIF | tweet_gif | 15 MB |
| Video, default account | tweet_video | 20 minutes, 8 GB |
| Video, X Premium or verified | tweet_video | 125 minutes, 16 GB |
| Per post | 4 images, or 1 GIF, or 1 video |
The video limit belongs to the account that posts, not to your API plan. The docs also warn that a finished upload can still be refused when you attach it: a video longer than that user may post comes back as 403 Forbidden on the post call, not on the upload.
A rough guide to the status codes we sort upload failures into:
| Status | What it usually means | What to do |
|---|---|---|
| 400 | Wrong protocol or a bad field | Check the endpoint shape first, then media_type and total_bytes |
| 401, 403 | Token or scope problem | Re-authorize with media.write |
| 413 | File too large | Compress or shorten |
| 415 | Media type not accepted | Re-encode to JPEG, PNG, GIF, WebP or MP4 |
| 429 | Rate limit | Back off and retry later |
How do I make the next silent change easier to spot?
Name the step and the file in every upload error, and keep the upload failure apart from the post failure. Our wrapper turns X's bare 400 into "X media upload failed at initialize for image 2 of 4", and the HTTP status stays in the message so the retry logic still sees it. A 400 at initialize on every file points at the protocol. A 400 at append on one file points at that file.
Second, keep a canary. If you publish media to X rarely, a quiet retirement can sit undetected for months, as ours did between August and November. A weekly test upload that never gets attached to a post (initialize, one append, finalize) tells you within days.
How does pendpost handle X media now?
pendpost's X lane moved to the initialize, append and finalize endpoints on 19 November 2026, for both OAuth 2.0 and OAuth 1.0a accounts. The fix is in the source since that day and ships with the first release after 2.14.0. With it, a refused upload reads "X refused the upload of image 2 of 4" in the post detail instead of a generic rejection, with X's raw words a click away. The X credential setup, including the media.write scope, is in the X credentials guide, and the platform's text and media limits are on the capabilities page.
For the rest of what the X API allows in 2026 (the reply restriction, long posts, credits), read what you can automate with the X API. For every platform's limits in one table, see social media API posting limits. And if an agent drafts your X posts, the MCP server keeps each one behind your approval until you say it goes.
Originally published on pendpost.com. pendpost is a free, open-source (MIT), local-first social media planner where an AI agent drafts posts behind a human approval gate.
