Documentation menu

API reference

Estimate

POST /v1/estimate tells you what a request would cost and produce, without sending or processing a file.

Endpoint

POST/v1/estimate

You describe a file and the request you plan to make. The API answers with the format the result would have, whether it can go as a direct request or needs a job, and what it would cost. No file is sent, nothing is processed, and the estimate itself is free. It works with a live key and with a test key.

Request

Send a JSON body. A field that is not listed here is refused with bad_request.

FieldTypeDescription
operation *stringcompress, convert or strip_metadata.
filename *stringThe name of the file. Its extension says what kind of file to estimate, because there are no bytes to inspect.
size *integerThe size of the file in bytes. A whole number greater than 0.
duration_secondsnumberThe length of the audio or video in seconds. Required for audio and video, which are priced by the minute.
pagesintegerThe number of pages of a PDF. Used when compressing a PDF, which is priced per started 100 pages. If it is left out, 100 pages or fewer is assumed.
widthintegerThe width of a video in pixels. If width or height is left out, 1920 by 1080 is assumed.
heightintegerThe height of a video in pixels.
optionsobjectThe options you plan to send, with the same shape and rules as options on a job. For convert, options.convert.to is required.

Response

Status 200.

200 OK
{
  "object": "estimate",
  "operation": "compress",
  "kind": "image",
  "input_format": "jpg",
  "output_format": "avif",
  "lane": "direct",
  "meter": "images",
  "quantity": 1,
  "amount_usd": 0.01,
  "notes": [
    "If the file cannot be made smaller it is returned unchanged and the request is free."
  ]
}
FieldTypeDescription
objectstringAlways "estimate".
operationstringThe operation you sent.
kindstringThe kind of file the extension stands for: image, pdf, video, audio, word, sheet, presentation, table or font.
input_formatstringThe format the extension stands for, for example jpg.
output_formatstringThe format the result is expected to have.
lanestringdirect when the file can be sent to a direct endpoint: its kind is accepted there and its size is within the direct limit. Otherwise job.
meterstringThe billing meter the request would be charged on: images, pdfs, documents, audio_minutes, video_units or files. See Billing.
quantitynumberThe number of units on that meter.
amount_usdnumberThe price in US dollars, at the unit prices. For images it takes into account how many images the account has already been billed for this month.
notesarray of stringsWhat was assumed, and anything that would stop or change the real request. Read them: an estimate with a note may not be what you get.
NoteMeaning
width and height were not given, so a 1920x1080 source was assumed.Send width and height for an exact video price.
pages was not given, so 100 pages or fewer was assumed.Send pages for an exact PDF price.
Video is in limited preview and is not enabled for this account.The real request would fail until support enables video.
HEIC output is in limited preview and is not enabled for this account.The real request would fail until support enables HEIC output.
The file is larger than this plan allows.The real request would be refused for its size.
If the file cannot be made smaller it is returned unchanged and the request is free.On every compress estimate. The price is what a successful compression costs.

How the estimate is made

  • From the name, not the content. The kind of file is read from the extension of filename. The real request reads it from the file's content. If the two disagree, the real request follows the content.
  • As if it succeeds. The amount is the charge for a successful request. A request that fails, or that returns the input unchanged, costs nothing.
  • Video. The price follows the size of the output. For a compress estimate, video.resolution is applied to the width and height you send, and video.codec and video.format decide the codec.
  • Limits are not checked, apart from the file size. A file over a pixel, page or length limit gets an estimate and then fails as a real request.
  • Spend cap and plan credit are not applied. The amount is the value of the usage, not what your next invoice will add.

Errors

CodeStatusWhen
bad_request400The body is not a JSON object or has an unknown field. operation, filename or size is missing or not valid. A number is not positive. duration_seconds is missing for audio or video.
invalid_options400An option is unknown or has a value that is not allowed. A convert estimate has no options.convert.to.
unsupported_input415The extension is not one the API handles, or the operation does not apply to that kind of file.
unsupported_target415The convert target is not available for that kind of file.
missing_key, invalid_key, revoked_key401The API key is missing, wrong or revoked.
no_payment_method, payment_required402A live key on an account with no plan, or with an unpaid invoice.
account_suspended, ip_not_allowed403The account is suspended, or the key may not be used from this IP address.

Examples

The price of compressing a JPEG to AVIF:

curl -X POST "https://api.smolmac.com/v1/estimate" \
  -H "Authorization: Bearer $SMOL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "compress",
    "filename": "photo.jpg",
    "size": 1614027,
    "options": { "image": { "format": "avif" } }
  }'

The price of compressing a video of 2 minutes 30 seconds at 1920 by 1080, with the default codec, H.265. Three started minutes, times 14 units for 1080, times 1.5 for H.265, is 63 units:

request body
{
  "operation": "compress",
  "filename": "talk.mov",
  "size": 262144000,
  "duration_seconds": 150,
  "width": 1920,
  "height": 1080
}
200 OK
{
  "object": "estimate",
  "operation": "compress",
  "kind": "video",
  "input_format": "mov",
  "output_format": "mp4",
  "lane": "job",
  "meter": "video_units",
  "quantity": 63,
  "amount_usd": 0.1575,
  "notes": [
    "If the file cannot be made smaller it is returned unchanged and the request is free."
  ]
}