Skip to main content

Uploads

A Mojeeb upload is a file you hand to Mojeeb for 24 hours, so any field that takes a media link can take it without you hosting the file anywhere. It's made for clients that can't put a file on a public address, AI assistants above all. Each upload belongs to one agent, under /v1/agents/{agentId}/uploads.

What is an upload, and when should I use one?​

An upload is one file Mojeeb keeps for 24 hours under one agent, with a url you put wherever the API takes a media link. Use one when the file isn't online: on a laptop, in a chat with an AI assistant, or behind a login. A file that already has a direct https link doesn't need an upload: send the link.

The upload's url is the API's own address for it, https://api.mojeeb.app/v1/agents/{agentId}/uploads/{uploadId}. A field given that url reads the file from Mojeeb's storage instead of downloading it.

How do I upload a file from my own system?​

Two calls: create the upload with the file's name and exact size, then send the file itself, once. The second call takes no API key: the upload's own token is its credential.

  1. Create it. size_bytes is the file's exact size in bytes (wc -c < photo.png prints it).

    curl -X POST https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/uploads \
    -H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
    -H "Content-Type: application/json" \
    -d '{ "file_name": "photo.png", "size_bytes": 412318 }'

    The answer is 201 with the upload, pending, and upload: the URL, method (PUT) and headers to send the file with, valid for 15 minutes.

  2. Send the whole file as the request body with those headers, with the token from upload.headers in place of … and upload.url as UPLOAD_URL:

    curl -X PUT -H "X-Upload-Token: …" -H "Content-Type: application/octet-stream" --data-binary @photo.png "$UPLOAD_URL"

    The answer is 200 with the upload, ready, with the type its bytes are and their SHA-256.

The token works for that upload only, for 15 minutes, and only for a body of exactly size_bytes. An upload is written once: to send another file, create another upload. Any Content-Type will do, because the bytes decide the type. See the Create an upload reference and the Send an upload's bytes reference.

Send file instead of file_name and size_bytes: its download_url and file_id, and, if you have them, mime_type and file_name. It's the shape in which ChatGPT passes a file the user attached. Mojeeb downloads the file in the same call, so the upload comes back ready and there's no second call.

curl -X POST https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/uploads \
-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{ "file": { "download_url": "https://files.example.com/tmp/menu.pdf", "file_id": "file_123" } }'

The link must be https, at a public address, and answer 200 with the file itself within 20 seconds; up to 3 redirects are followed, each to a public https address too. mime_type isn't trusted: the bytes decide. Send file, or file_name with size_bytes, never both (422 invalid_request_body).

Where can I use an upload's url?​

In every field that takes a media link, for the same agent, within the upload's 24 hours. The field reads the file when your request arrives, from Mojeeb's storage:

FieldWhat it isGuide
header.media_urlA WhatsApp template's header sample, when you create or edit the templateCreate and Manage WhatsApp Templates
template.header_media_urlThe header file of one template send; Mojeeb hands it to WhatsApp itselfSend a WhatsApp Template
media_urlThe file of a WhatsApp messageSend a WhatsApp Message
media_urlThe file of a reply in a conversationConversations and Messages
urlsAn AI attachment's media, put on it from linksAI Attachments
media_urlsA saved reply's mediaSaved Replies

Each field checks the file against its own types and sizes, as it checks a downloaded file, so a file a field doesn't take is refused there, not when you upload it. Another agent's upload, or one past its 24 hours, is refused like a link that fails.

Which files can an upload hold?​

A JPEG, PNG or WebP image, an MP4 or MOV video, or a PDF or DOCX document, up to 20 MB. Mojeeb reads the type from the file's bytes, never from the Content-Type it was sent with. Anything else is refused with 422 upload_type_not_allowed.

Each field then applies its own rules, which are narrower: a template header, for example, takes fewer kinds of file than a reply. Check the reference of the field you have in mind before you upload, as the table in Where can I use an upload's url? links to each guide.

How long does an upload last?​

A new upload waits 15 minutes for its file; after that its token stops working, and you create a new upload. Once the file is stored, the upload can be used for 24 hours. After that, and for an upload whose file never arrived, reading it answers 404 upload_not_found and the media fields refuse its url.

expires_at says when: while the upload is pending, when its token stops working; once it's ready, when it can no longer be used. What a field made with the upload doesn't depend on it afterwards: an attachment, a saved reply or a sent message keeps its file once the upload is gone. No call deletes an upload.

How do I check an upload arrived whole?​

Read it with GET on its id. A stored upload answers ready with the type its bytes are, its size, the SHA-256 of its bytes and when it expires; compare the SHA-256 with your own copy's (shasum -a 256 photo.png). An upload whose file never arrived answers 404 upload_not_found. See the Get an upload reference.

Which errors should I expect?​

Besides the errors every endpoint can return, these are the ones uploads add. The full list is on Errors.

ErrorWhat to do
403 upload_token_invalidX-Upload-Token is missing, isn't this upload's, or is past its 15 minutes. Create a new upload.
409 upload_already_writtenThis upload's file was already sent. Create a new upload to send another file.
404 upload_not_foundNo upload of this agent has that id, its file never arrived, or it's past its 24 hours. Create a new upload.
422 upload_too_largesize_bytes is 0 or over 20 MB.
422 upload_size_mismatchThe body you sent isn't exactly size_bytes long. Create a new upload with the file's exact size.
422 upload_type_not_allowedThe file isn't one of the kinds an upload holds. The message names it.
422 upload_url_invalidMojeeb couldn't download file.download_url.
413 request_body_too_largeThe body you sent is over 20 MB.

Where you use the url, a field that can't read it answers with its own media error: media_url_invalid for a message's, a reply's or a saved reply's media, template_header_media_url_invalid for a template header, and attachment_media_url_invalid for an AI attachment's import.

Common questions​

Can an AI assistant use uploads?​

Yes, through the MCP server, with create_upload and get_upload. An assistant that can run commands creates the upload with the file's name and size, sends the file with one PUT as above, then passes the upload's url to the tool that needs it. In ChatGPT on the web and desktop, you attach the file and ChatGPT passes it as create_upload's file; ChatGPT's mobile apps don't pass files.

Which scopes do these calls need?​

uploads:write to create an upload and uploads:read to read one. Sending an upload's file takes no key and no scope: its token is the credential. Using the url needs the scope of the endpoint you put it in, such as attachments:write for an attachment's media. Every key holds them all today; see Authentication.

How many uploads can I create?​

Creating an upload shares 10 requests a minute per key with the other endpoints that have a lower limit, such as the WhatsApp template endpoints and AI attachment media uploads, because each one stores a file. Reading an upload counts against the default 60 a minute. Sending an upload's bytes takes no key, so it counts per IP address: the default 60 a minute from one address. See Rate Limits.

What if a create's response never arrives?​

Create another upload. Creating one takes no idempotency key, and an upload whose file never arrives does nothing: its token stops working after 15 minutes. Use only the upload whose answer you received.

Can I make a knowledge base from an uploaded document?​

No. The API takes knowledge as text, and no field turns an upload into a knowledge base; upload documents in the dashboard, where Mojeeb extracts their text. Through the API, a document reaches an agent only as an AI attachment, a file the AI sends to customers. See Agent Knowledge.