AI Attachments
An AI attachment is a file the agent's AI sends to customers by itself: a menu, a price list, a catalog, a photo of the showroom, a short video. It's the dashboard's Attachments feature through the API, so your own system or an AI assistant can keep those files up to date. Everything lives under /v1/agents/{agentId}/attachments.
What is an AI attachment, and when does the AI send one?
An attachment is a photo, an album, a video or a document, plus when_to_send: your words for when the AI should send it. While an attachment is active, its name, when_to_send and description are part of the AI's instructions on every reply, and the AI sends its media when when_to_send fits the conversation.
Write when_to_send the way you'd brief a colleague: name the requests that should trigger it ("When the customer asks about prices, packages or costs") and any condition ("only after they say which branch"). description tells the AI what the file shows, so it can introduce it. The rules the AI follows when sending, such as one attachment per reply, are on Attachments. A change reaches the AI from its next reply.
How do I add an attachment end to end?
Three calls: create it, put its media on it, then switch it on. A new attachment starts switched off and without media, so nothing reaches a customer until the last step, which is the one a person should approve.
-
Create it. Keep the
idit returns.curl -X POST https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/attachments \-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \-H "Content-Type: application/json" \-d '{ "name": "Price list", "type": "document", "when_to_send": "When the customer asks about prices or costs." }' -
Put its media on it, here from a link (or upload the file; see the next question).
curl -X POST https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/attachments/ATTACHMENT_ID/media/import \-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \-H "Content-Type: application/json" \-d '{ "urls": ["https://example.com/files/prices.pdf"] }' -
Switch it on.
curl -X PATCH https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/attachments/ATTACHMENT_ID \-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \-H "Content-Type: application/json" \-d '{ "active": true }'
Have a person look at the file and the when_to_send text before step 3: from then on the AI sends that file to real customers. Every field and its limits are in the Add an AI attachment reference; name can't contain angle brackets.
Should I upload the file or import it from a link?
Upload when your system holds the file; import when the file is already online, or when the caller can't send a form with files, such as an AI assistant through the MCP server, which imports a Mojeeb upload of the file instead. Both replace whatever was stored, check every file the same way, and leave the attachment's on/off switch as it was.
Upload sends the file itself as multipart/form-data: one file in the field file for a photo, video or document, or an album's images in files, in the order they should arrive.
curl -X PUT https://api.mojeeb.app/v1/agents/YOUR_AGENT_ID/attachments/ATTACHMENT_ID/media \
-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
-F "file=@prices.pdf"
For an album, repeat the field: -F "files=@front.jpg" -F "files=@inside.jpg". See the Upload an AI attachment's media reference.
Import sends { "urls": [...] }: one link, or up to 10 for an album, in order. Each is an https link Mojeeb downloads, or the url of a Mojeeb upload of this agent, which Mojeeb reads from its own storage. A link Mojeeb downloads must answer 200 with the file itself within 20 seconds. Redirects aren't followed and links to addresses that aren't public are refused, so a file-sharing service's share page usually fails: use a direct link to the file, such as a public or signed storage link. Nothing stored changes until every file passes. See the Put media on an AI attachment from links reference.
Which files can an attachment hold?
Each type takes its own kind of file. Mojeeb checks what each file really is from its content, never from the Content-Type it was sent with, and refuses anything else with 422 invalid_media without changing what was stored.
type | Files | Formats | Size |
|---|---|---|---|
photo | One | JPEG, PNG or WebP | Up to 5 MB |
album | Up to 10 images, kept in order | JPEG, PNG or WebP | Up to 5 MB each |
video | One | MP4 or MOV | Up to 16 MB, before and after re-encoding |
document | One | PDF or DOCX | Up to 20 MB |
The photo limit is WhatsApp's own image limit, so a photo that uploads never fails later when the AI sends it. Every video is re-encoded on the server to the format WhatsApp plays (H.264 video, AAC audio, MP4) at up to 720p and 30 fps, so a MOV comes back as an .mp4 file; one still over 16 MB after that, or one that takes longer than 150 seconds to re-encode, is refused. Instagram takes documents as PDF only, so prefer PDF to DOCX. An upload's whole body may be up to 51 MB, enough for a full album: it's the one /v1 endpoint whose body may be larger than 1 MB.
How do I switch an attachment on or off, and how many can be on?
Send a PATCH with "active": true or "active": false. Switching one on needs its media stored (409 attachment_has_no_media) and room under the agent's limit of 100 active attachments (409 too_many_active_attachments). Switching off keeps the attachment and its files; the AI just stops sending it.
The limit exists because every active attachment's text goes into the AI's instructions on every reply. An attachment that's already on stays editable when the agent is at the limit. To make room, list the active ones with active=true and switch off those the agent no longer needs, such as last season's menu. priority sets an attachment's place among the others in the AI's instructions, highest first.
Why can't I change an attachment's type?
Its files were checked against its type, so type can change only while no media is stored. Once media is on it, a new type answers 409 attachment_type_locked and nothing changes. To turn a photo into an album, or a PDF into a video, add a new attachment of the type you want, put its media on it, switch it on, and switch the old one off.
How do I download an attachment's files?
GET /v1/agents/{agentId}/attachments/{attachmentId}/media returns a read-only link to each stored file, in order, all valid for 15 minutes from the call (expires_at). Download the files within that time or ask again, and never store the links. Listing or reading attachments describes their files without links.
An attachment without media has no files. See the Get links to an AI attachment's files reference, and the List an agent's AI attachments reference for the type, active and search filters.
What do replacing and deleting do to messages the AI already sent?
Messages the AI already sent stay in their conversations, but their media stops opening there. Replacing an attachment's media removes the files stored before, and deleting an attachment removes it and its files for good, so the earlier sends lose their media either way.
To change a file without breaking those messages, add a new attachment with the new file, switch it on, and switch the old one off rather than replacing or deleting it. Delete an attachment only when its earlier sends no longer matter. See the Delete an AI attachment reference.
Which errors should I expect?
Besides the errors every endpoint can return, these are the ones attachments add. Each leaves everything stored as it was. The full list is on Errors.
| Error | What to do |
|---|---|
409 attachment_has_no_media | Upload or import the attachment's media, then switch it on. |
409 too_many_active_attachments | The agent has 100 active attachments: switch one off first. |
409 attachment_type_locked | Add a new attachment of the type you want. |
422 invalid_media | A file isn't what the type takes, is empty or too large, or there are too many files. The message names the file. A video can also take longer than 150 seconds to re-encode: send a shorter clip or one exported at 720p. |
422 attachment_media_url_invalid | An import link failed (param: urls): it isn't https or public, redirects, didn't answer 200 with the file in time, sent a file too large for the type, or names an upload that isn't this agent's or is past its 24 hours. |
413 request_body_too_large | The upload is larger than 51 MB. |
503 media_processing_busy | Videos are re-encoded a few at a time across Mojeeb, and every slot stayed busy for 30 seconds. Send the same request again after Retry-After. |
Common questions
Does putting media on an attachment switch it on?
No. Uploading or importing media never changes the switch: a new attachment stays off until you send "active": true, and one that's already on stays on with its new files.
Are these the same attachments as in the dashboard?
Yes. An attachment added through the API appears on the agent's Agent Knowledge page in the dashboard, and one added there can be read and changed through the API. The same file limits apply in both. See Attachments.
Can an AI assistant add attachments?
Yes, through the MCP server: it can list, read, add, change, switch and delete attachments, and get links to their files. An assistant can't send a form with files, so it puts media on an attachment with import_attachment_media: from links, or from a file you give it, which it first makes a Mojeeb upload. The multipart upload isn't one of its tools. Use a client that asks you before switching an attachment on.
How many uploads and imports can I send?
Uploading and importing media share 10 requests a minute per key with the other endpoints that have a lower limit, such as the WhatsApp template endpoints, because each stores files and may re-encode a video. The other attachment calls count against the default 60 a minute. See Rate Limits.
What if a create's response never arrives?
Check before you create again. Creating an attachment takes no idempotency key, so a retried create adds a second one. List the agent's attachments with search set to the name, and carry on with the one you find.
Which scopes do these calls need?
attachments:read to list and read attachments and get links to their files, and attachments:write to add, change, switch, delete them and put their media on them. Every key holds both today; see Authentication.