Upload and attach media
Upload local images, GIFs, and videos, then attach them using asset IDs.
File uploads require SDK version
0.1.0-beta.2 and the matching API release.Call client.media.upload(files, options?) with a key that has media:upload. The response contains private asset IDs and file metadata in upload order. Pass the IDs in mediaIds when you schedule or publish. You can also reuse assets already in your library.
Upload and schedule an image
Run this as media.mjs with a local launch.jpg and a connected Instagram test account. Set LUMOPILOT_API_KEY to a key with accounts:read, media:upload, and posts:write. Set LUMOPILOT_SCHEDULE_AT to a future ISO 8601 timestamp and keep it fixed on a retry.
import { readFile } from 'node:fs/promises';
import { LumoPilot, LumoPilotError } from '@lumopilot/sdk';
const apiKey = process.env.LUMOPILOT_API_KEY;
if (!apiKey) throw new Error('Set LUMOPILOT_API_KEY first.');
const client = new LumoPilot({ apiKey });
try {
const account = (await client.accounts.list()).find(({ platform }) => platform === 'instagram');
if (!account) throw new Error('Connect an Instagram test account first.');
const media = await client.media.upload([
{
filename: 'launch.jpg',
data: new Blob([await readFile('launch.jpg')], { type: 'image/jpeg' }),
},
], { idempotencyKey: 'launch-image-001' });
const post = await client.posts.schedule({
accountIds: [account.id],
caption: 'A preview of our next release.',
contentType: 'image',
mediaIds: media.map(({ id }) => id),
scheduledAt: process.env.LUMOPILOT_SCHEDULE_AT,
idempotencyKey: 'launch-preview-001',
});
console.log(post.id, post.status);
} catch (error) {
const status = error instanceof LumoPilotError ? error.status : undefined;
console.warn('LumoPilot media example failed.', { status });
}
File limits and retries
- Each batch accepts 10 MB combined (10,000,000 file bytes). The SDK sends multipart binary data.
- Use JPEG, PNG, WebP, GIF, MP4, MOV, WebM, or MPEG. Set the MIME type to match the file.
- Set
contentTypetoimagefor one image,videofor one video, orcarouselfor a supported collection of still images. Useimagefor a single GIF when posting to X. LumoPilot checks every destination before saving the post. - For TikTok, send one video. The account owner finishes publishing from the TikTok inbox.
- Retry an upload with the same key and identical files in the same order to get the original asset IDs. Use 1–120 printable ASCII characters without spaces for the upload key.
- Save the returned IDs, original schedule, and post key with your job. Reuse the post payload and key if you retry scheduling.