Skip to main content

Send and receive files

Files belong to a conversation. You need an activity_id first: create the conversation as in Ask a persona a question, then upload the file before you open the stream and send the question.

Send a file for the persona to read​

Two steps: upload, then mention the file in the next message.

# 1. upload (multipart form, field name "file")
curl -X POST "$PERSONAAS_BASE_URL/api/v1/activity/$ACTIVITY_ID/upload-file" \
-H "x-personaas-key: $PERSONAAS_API_KEY" \
-F "file=@policy.pdf"
# → { "status": "success", "artifact_id": "…", "upload_id": "…", "filename": "policy.pdf", "message": "…" }

# 2. send the question, naming the file
curl -X POST "$PERSONAAS_BASE_URL/api/$PERSONAAS_ENGINE/activity/$ACTIVITY_ID/message" \
-H "x-personaas-key: $PERSONAAS_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "input": "Summarise this policy", "files": [ { "filename": "policy.pdf" } ] }'

Open the stream before step 2 and read the answer from it, as in Ask a persona a question.

File upload can be switched off for an organisation; in that case the upload returns an error with a detail message. Hide the upload button when that happens.

List the files of a conversation​

curl "$PERSONAAS_BASE_URL/api/v1/artifacts/$ACTIVITY_ID/files" \
-H "x-personaas-key: $PERSONAAS_API_KEY"
# → { "activity_id": "…", "files": [ { "id": "…", "filename": "summary.pdf", "mime_type": "application/pdf", "file_size": 48213, "file_type": "artifact" } ] }

This includes files the user uploaded and files the persona produced. The messages endpoint (Continue a conversation) returns the same list under artifacts.all.

Download a file​

With the usual header:

curl -L "$PERSONAAS_BASE_URL/api/v1/artifacts/$ACTIVITY_ID/file/summary.pdf/download" \
-H "x-personaas-key: $PERSONAAS_API_KEY" -o summary.pdf

Or get a short-lived direct link that opens without a header:

curl "$PERSONAAS_BASE_URL/api/v1/artifacts/$ACTIVITY_ID/file/summary.pdf/signed-url" \
-H "x-personaas-key: $PERSONAAS_API_KEY"

URL-encode the filename when it contains spaces or special characters.

Mistakes to avoid​

  • Uploading and then not listing the file in files on the next message.
  • Storing a signed link. It expires; ask for a new one when the user clicks.
  • Uploading any file the user picks. Set a size limit and an allowed-types list.