Raintree Workspace Data API

The Raintree workspace data API is a read-only HTTP API. It lets an authorized agent or script read chat messages, list workspace files, and download files from one Raintree workspace.

Every workspace serves its own copy of the API under /api/v1/. The API accepts GET and HEAD only. HEAD is supported on /api/v1/, /api/v1/openapi.json, and file downloads.

Where the spec lives

  • Canonical machine spec: GET <origin>/api/v1/openapi.json. OpenAPI 3.1, no token needed.
  • In-workspace guide: GET <origin>/api/v1/. Markdown, with the same endpoints and examples.
  • This page: the public overview for agents and developers. The markdown alternate has the same content.

Connect

Use the workspace origin, for example https://<name>.workspace.raintree.tech. Send a Bearer token that starts with rtw_.

export ORIGIN=https://<name>.workspace.raintree.tech
curl -H "Authorization: Bearer rtw_..." "$ORIGIN/api/v1/chat_log"

Keep tokens out of logs and shared notes.

Endpoints

MethodPathPurpose
GET, HEAD/api/v1/Markdown guide
GET, HEAD/api/v1/openapi.jsonOpenAPI 3.1 spec. No token needed.
GET/api/v1/chat_logList chats or read messages
GET/api/v1/filesList one folder, or a whole tree with recursive=1
GET, HEAD/api/v1/files/<path>Download one file

Unknown or repeated query parameters return 400. Use only the parameters listed in the sections below.

Chat log

GET /api/v1/chat_log takes chat, text, sender, since, until, n, and cursor. The chat parameter takes a chat id, a unique case-insensitive name substring of at least 3 characters, or all. The n parameter is an integer from 1 to 200, and defaults to 50.

text is a case-insensitive substring of the message text. sender is a substring of the sender's name or id.

since and until are inclusive. A bare date (YYYY-MM-DD) covers its whole UTC day: since starts at 00:00:00Z and until ends at 23:59:59.999Z. A date-time needs Z or a UTC offset. Bare numbers and date-times without a zone return 400. Every time in a response is UTC ISO-8601 with Z.

With no chat (or chat=all) and none of text, sender, since, until, n, or cursor, the endpoint lists chats:

{
  "chats": [
    {
      "id": "C9773370",
      "name": "Team",
      "type": "group",
      "provider": "line",
      "messages": 412,
      "last_activity": "2026-11-01T08:30:00Z",
      "participants": ["Alice", "Bob"],
      "files_dir": "inbox/line/C9773370"
    }
  ]
}

messages counts messages in both directions. participants lists the known participant names. files_dir is the workspace path of the chat's attachment folder, or null.

A message query returns messages oldest first. When truncated is true, the response includes next_cursor. It is opaque: send it back unchanged as cursor and repeat every other parameter to read older messages. Pages never skip or repeat a message, even when messages share a timestamp.

{
  "messages": [
    {
      "id": "412",
      "time": "2026-11-01T08:30:00Z",
      "chat": "C9773370",
      "sender": "Alice",
      "sender_id": "U100",
      "direction": "inbound",
      "text": "Shipment confirmed.",
      "attachments": [
        {"path": "inbox/line/C9773370/photo-1.jpg", "name": "photo-1.jpg", "mime": "image/jpeg", "size": 204800}
      ]
    }
  ],
  "truncated": true,
  "next_cursor": "v1.eyJ0IjoxNzkzNTIxODAwMDAwLCJpZCI6NDEyfQ"
}
  • id is a stable string that identifies one message. Use it to tell messages apart; do not parse it.
  • sender_id is a stable id. It is null for outbound and unknown senders.
  • direction is inbound or outbound. Outbound messages show sender as Raintree.
  • Each attachment path works with /api/v1/files/<path>. It is null when the file is not stored. The API has no newest-20 cap on attachments.
  • truncated is true when older matching messages exist. The API fetches one message more than n to set this value.

Files

GET /api/v1/files?path=<dir> lists one folder level. Omit path for the workspace root. Add recursive=1 or recursive=true to list the whole tree. recursive=0, recursive=false, or no recursive lists one level. Any other value returns 400.

A recursive listing is flat, sorted by path, and holds at most 5000 entries. It is gathered breadth-first, with names sorted within each level. truncated is true when more than 5000 entries exist, or when a directory path is longer than 1024 characters; that directory's children are skipped. When truncated is true, the list is not the full tree. To see the rest, list a subdirectory with path=. A one-level listing always sets truncated to false.

GET /api/v1/files/<path> returns the file body. HEAD returns the same headers with no body. Downloads are limited to files of at most 50 MiB.

  • Responses up to 1 MiB include Content-Length. Larger responses stream with chunked transfer encoding and no Content-Length. HEAD always includes the full Content-Length. Range (206), ETag, Last-Modified, 304 and 416 apply to all sizes.
  • ETag is W/"<size>-<mtimeMs>". Send If-None-Match to get 304 when it matches.
  • One Range: bytes=a-b, bytes=a-, or bytes=-n header returns 206. An unsatisfiable range returns 416 with Content-Range: bytes */<size>.
  • Multiple ranges are not supported. The API ignores the header and returns 200 with the full file.
  • Last-Modified and Accept-Ranges: bytes are set.
  • Responses use Cache-Control: private, no-store and X-Content-Type-Options: nosniff.

Errors

Errors return JSON with an error object that has a code and a message.

{"error": {"code": "invalid_request", "message": "unknown parameter 'x'; allowed: chat, text, sender, since, until, n, cursor"}}
StatusCodeWhen
400invalid_requestUnknown or repeated parameter, bad n, bad since or until, malformed cursor, bad recursive
400ambiguous_chatThe chat name matches more than one chat. The body lists candidates with id and name.
401unauthorizedThe token is missing, invalid, expired, or revoked.
404chat_not_foundNo chat matches chat. The body lists chats.
404not_foundNo such directory or file.
405method_not_allowedA method other than GET or HEAD. The response sends Allow: GET, HEAD.
416range_not_satisfiableThe Range header cannot be satisfied.
429rate_limitedOver a limit. The response sends Retry-After. See Limits.
500chat_log_failedThe server could not read chat history. Retry later.

Limits

  • Per token: 5 requests per second, with a burst of 20.
  • 2 requests in flight at once.
  • 1 MiB/s per file download.

When you hit a limit, the response is 429 with Retry-After: 2 (seconds) from the edge. Wait that long and retry. Do not send requests in a tight loop.

Recipes

Read the newest 50 messages from one chat:

curl -H "Authorization: Bearer rtw_..." "$ORIGIN/api/v1/chat_log?chat=Team&n=50"

Read the next older page, repeating the same filters:

curl -H "Authorization: Bearer rtw_..." "$ORIGIN/api/v1/chat_log?chat=Team&n=50&cursor=<next_cursor>"

List a folder tree:

curl -H "Authorization: Bearer rtw_..." "$ORIGIN/api/v1/files?path=inbox&recursive=1"

Download the first MiB of a file:

curl -H "Authorization: Bearer rtw_..." -H "Range: bytes=0-1048575" "$ORIGIN/api/v1/files/inbox/example.pdf" -o part.bin

Related pages