Guides

Files and images

What it is for

Some questions need a document or a picture. Upload a file to /v1/files, then refer to it by id in any message. A file or an image can also go inside the message itself, read for that request only and not stored.

Upload and use a file

curl https://antarya.ai/v1/files \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -F file=@agreement.pdf

curl https://antarya.ai/v1/chat \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "file", "file_id": "file_01"},
          {"type": "text", "text": "Summarise the termination clause in this agreement."}
        ]
      }
    ]
  }'
Output
{
  "id": "req_07",
  "content": [
    {"type": "text", "text": "Either party can end the agreement with 30 days of written notice..."}
  ],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 1204, "output_tokens": 61}
}

Send a file without storing it

A file part can also hold the file itself as base64 text, with its name and media type. It is read for that request only and is not stored, so there is nothing to delete afterwards. The same types and the 10 MB limit apply.

import base64

with open("agreement.pdf", "rb") as f:
    data = base64.b64encode(f.read()).decode()

reply = client.chat.create(
    messages=[{
        "role": "user",
        "content": [
            {"type": "file", "source": {"type": "base64", "filename": "agreement.pdf", "media_type": "application/pdf", "data": data}},
            {"type": "text", "text": "Summarise the termination clause in this agreement."},
        ],
    }],
)

Send an image inline

An image part holds the picture as base64 text, with its media type.

import base64

with open("signature-page.png", "rb") as f:
    data = base64.b64encode(f.read()).decode()

reply = client.chat.create(
    messages=[{
        "role": "user",
        "content": [
            {"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": data}},
            {"type": "text", "text": "Who signed this page?"},
        ],
    }],
)

Manage files

GET /v1/files lists your files, GET /v1/files/{id} describes one and DELETE /v1/files/{id} removes it. Delete a file when you no longer need it.

Parameters

NameTypeRequiredDescription
filefileYesRequiredThe file to upload, sent as multipart form data to POST /v1/files.
contentarrayNoA list of parts, to put a file, image or text in one message.
typetextYesRequired"text", "image" or "file".
file_idtextNoThe id returned by an upload. Used with the "file" part.
sourceobjectNoData sent inside the message, with type "base64", a media_type and the data. Used with the "image" part, and with the "file" part in place of file_id, where it also needs a filename.

Limits

A file can be up to 10 MB and an account can store up to 100 MB during early access. A file over either limit gets a 413.

An image over 10 MB gets a 413. More than 20 images in a request, or an image that is not PNG, JPEG or WebP, gets a 400 invalid_request.

Limit Value
File size 10 MB a file
File types txt, md, csv, json, pdf, docx, doc, xlsx
Image types PNG, JPEG and WebP
Image size 10 MB each, up to 20 images in a request
Stored per account 100 MB in total

Next steps