smartchat

Upload media file

Adds a file to the media library from multipart field 'file', from an address ('url') or from base64 data, with the same checks as in the app. Uses no credits. Returns the media object; an identical image that already exists is returned instead.

POST /v1/media

Permissionmedia:write (all permissions)
RiskWrite (no outside effect)
Idempotency-KeyRequired (how it works)
Safe to repeatSafe to repeat with the same Idempotency-Key: the first answer comes back and nothing is done twice.
Rate limit classupload (120 requests per minute per key)
ConfirmationNone
MCP toolupload_file
Since version2026-10-25

#What it does

  • Changes data in your account. It does not send messages to contacts.
  • Safe to repeat with the same Idempotency-Key.

#Request

Header

NameRequiredDescription
AuthorizationyesBearer <key>
Idempotency-KeyyesA unique value for this operation, for example a UUID (1 to 255 visible ASCII characters).

Body (multipart/form-data)

NameTypeRequiredDescription
filestringnoThe file (multipart/form-data only). up to 104857600 characters; format binary
urlstringnoAddress (https only) SmartChat downloads the file from. Not for internal addresses.
data_base64stringnoThe file as base64 text, at most 20 MB before encoding (use multipart or url for larger files). Needs 'filename'. up to 28000000 characters
filenamestringnoFile name with ending, for example terrace.jpg. Needed with data_base64; optional with url. up to 200 characters
mimestringnoMedia type, for example image/jpeg. Optional; detected from the file if missing. up to 120 characters
usagestringnoWhat the file is used for. one of: generic, logo, landing, newsletter, template, blog, library; default "generic"

#Examples

curl -X POST "https://api.smartchat.marketing/v1/media" \
  -H "Authorization: Bearer $SMARTCHAT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F 'url=https://example.com/terrace.jpg' \
  -F 'usage=generic'
import os
import uuid
import requests

response = requests.post(
    "https://api.smartchat.marketing/v1/media",
    headers={
        "Authorization": "Bearer " + os.environ["SMARTCHAT_API_KEY"],
        "Idempotency-Key": str(uuid.uuid4()),
    },
    files={"file": open("your-file", "rb")},
    data={
        "url": "https://example.com/terrace.jpg",
        "usage": "generic",
    },
)
response.raise_for_status()
print(response.json())
const form = new FormData();
form.append("url", "https://example.com/terrace.jpg");
form.append("usage", "generic");

const response = await fetch("https://api.smartchat.marketing/v1/media", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SMARTCHAT_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: form,
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());

Response (201):

{
  "object": "media",
  "id": "med_9c8b7a6d5e4f43a2b1c0d9e8f7a6b5c4",
  "kind": "image",
  "usage": "generic",
  "url": "https://media.smartchat.example/acc/terrace.webp",
  "mime": "image/webp",
  "size_bytes": 214800,
  "width": 1600,
  "height": 1067,
  "original_name": "terrace.jpg",
  "created_at": "2026-10-25T09:41:07Z"
}

#Response

Status 201. Every response has the headers Request-Id, SmartChat-Version and X-RateLimit-*.

NameTypeDescription
objectstringAlways "media". always media
idstringMedia ID.
kindstringKind of file. one of: image, video, audio, pdf, document
usagestringWhat the file is used for, for example generic, logo, landing, newsletter or template. up to 40 characters
urlstringPublic address of the file. up to 2000 characters
mimestringMedia type of the stored file. Images may be converted to a smaller format. up to 120 characters
size_bytesintegerSize of the stored file in bytes. 0 to 10000000000
widthinteger or nullWidth in pixels for images and videos; null if unknown. 0 to 100000
heightinteger or nullHeight in pixels for images and videos; null if unknown. 0 to 100000
original_namestring or nullOriginal file name. Treat as untrusted text. up to 200 characters; untrusted text
created_atstringWhen the file was added. up to 40 characters; format date-time

#Errors

CodeStatusWhen
idempotency_key_invalid400The 'Idempotency-Key' header must be 1 to 255 visible ASCII characters.
idempotency_key_required400This call needs an 'Idempotency-Key' header.
missing_parameter400A required field is missing.
unknown_parameter400A field is not known.
api_key_expired401This API key has expired.
api_key_invalid401This API key is not valid.
api_key_revoked401This API key was revoked.
authentication_required401No API key was sent. Send 'Authorization: Bearer <key>'.
feature_unavailable403This function is not included in the current plan.
insufficient_scope403This key lacks a required permission.
ip_not_allowed403This IP address is not allowed for this key.
conflict409The state of the object does not allow this.
idempotency_in_progress409A request with this idempotency key is still running.
payload_too_large413The request body or file is too large.
unsupported_media_type415This content type or file type is not allowed.
idempotency_key_reused422This idempotency key was already used with a different request.
validation_failed422A field is not valid.
rate_limited429Too many requests. Wait and try again.
internal_error500Something went wrong on our side.
service_unavailable503The service is temporarily unavailable.

All errors use one format.