# HTTP API

> Use the Inner Threads JSON API to integrate direct and group conversations, messages, attachments, reactions, and receipts.

[Web documentation](https://threads.teamkrope.com/docs/api/) · Inner Threads v1.3.0

The default base path is `/inner-threads/api/v1`. Send `Accept: application/json`, use the host session cookie, and include `X-CSRF-TOKEN` when writing through Laravel’s web middleware.

## Endpoints

### Directory and inbox

| Method and path | Request and response |
| --- | --- |
| `GET /bootstrap` | Current user, profile settings, feature flags, limits, reactions, and realtime settings. |
| `PATCH /profile` | Set `theme` to `light` or `dark`, and/or set the boolean `notifications_muted`. Returns `user` and `profile`. |
| `POST /profile/photo` | Upload a JPEG, PNG, or WebP as multipart `photo`, up to 40 KiB and 512 × 512 pixels. Returns `user` and `profile`. |
| `DELETE /profile/photo` | Restore the host directory avatar. Returns `user` and `profile`. |
| `GET /profile/photo/{key}` | Fetch an eligible account photo. With role filtering on, other users need a contact grant or a shared group or direct chat with messages. |
| `GET /people?q=` | Contactable users matching a name. An empty query returns an initial list. Add `include_groups=1` to include accessible groups. With `inbox_page=1`, the endpoint returns contactable people with no direct chat or an active empty direct chat, plus `next_inbox_page`. An existing empty chat includes its `conversation_id`. |
| `GET /search?q=` | People search. Enables matching groups and recent accessible messages when `features.message_search` is on. Requires at least two characters. |
| `GET /conversations?cursor=` | One inbox page, active unread total, and opaque `next_cursor`. Set `unread=1` for active unread chats or `archived=1` for archived chats. |
| `GET /conversations/direct?user_id=42` | Looks up the existing direct chat for a contactable user, including an archived chat. Returns `{"conversation":null}` when none exists. |
| `POST /conversations/direct` | Send `{"user_id":"42"}` to create or return a direct conversation. Use your own actor ID for your private self-chat. |
| `GET /conversations/{id}` | Conversation summary and current members. |
| `PUT /conversations/{id}/preferences` | Set `{"muted":true}` or `false` for the caller. Returns 204. |
| `PUT /conversations/{id}/archive` | Set `{"archived":true}` to archive for the caller or `false` to restore. Returns 204. |
| `GET /starred-messages?before=` | Up to 30 visible starred entries, each with a full `message` and conversation details in the `conversations` map. Use the exclusive `next_before` cursor. |

On the first active, unfiltered inbox page, add `include_self=1` to get a separate `self_conversation` object, including when the private self-chat is empty.

Set `sync_unread=1` on the first inbox page for a sparse map of unread counts in that scope. On the first active page, `notifications=1` establishes a `notification_cursor`. Supply it as `notifications_after` in later requests to retrieve eligible unread message IDs per conversation.

### Groups and membership

| Method and path | Request and response |
| --- | --- |
| `POST /conversations/group` | Pass `title` and `user_ids`. The creator becomes the owner. Group names have a 70-character limit. |
| `PATCH /conversations/{id}` | Owner or admin can set the group `title`. |
| `DELETE /conversations/{id}` | Owner closes the group for all members. Returns 204. |
| `POST /conversations/{id}/members` | Owner or admin adds contactable users via `user_ids`. |
| `PATCH /conversations/{id}/members` | Owner sets `user_id` and `role` to `member`, `admin`, or `owner`. Transferring ownership makes the previous owner an admin. |
| `DELETE /conversations/{id}/members` | Remove `user_id` within role permissions, or omit it to leave. Owners transfer ownership before leaving. |

### Messages and receipts

| Method and path | Request and response |
| --- | --- |
| `GET /conversations/{id}/messages` | Visible messages in chronological order. Accepts exclusive `before` or `after` IDs and optional `limit` from 1 to 100. |
| `GET /conversations/{id}/messages/{messageId}` | A single visible message. |
| `POST /conversations/{id}/messages` | Send a message. Returns 201, or 200 with the original message on a client-ID retry. |
| `PATCH /conversations/{id}/messages/{messageId}` | Edit owned text within the edit window. Pass `mentions` to replace group mentions. |
| `DELETE /conversations/{id}/messages/{messageId}` | Pass `scope` as `me` or `everyone`. Deleting for everyone requires ownership within the configured window. |
| `DELETE /conversations/{id}/messages` | Include the same `scope` plus up to 100 unique visible IDs in `message_ids`. The server checks the full batch before changes. Returns 204. |
| `PUT /conversations/{id}/messages/{messageId}/reaction` | Set `emoji` to a configured value or `null` to remove your reaction. |
| `GET /conversations/{id}/messages/{messageId}/reactions` | List reactions on a visible message, including `emoji`, `name`, `avatar_url`, and `is_me` for each person. |
| `PUT /conversations/{id}/messages/{messageId}/star` | Set `starred` to `true` or `false` for the caller. Safe to retry. |
| `PUT /conversations/{id}/receipt` | Advance `read_through`, `delivered_through`, or both. Cursors advance monotonically, and read implies delivered. A read update returns the remaining unread count. |
| `GET /conversations/{id}/messages/{messageId}/receipts` | Message author can read the `read` and `delivered` lists. Each entry includes a profile and `recorded_at`, which can be null for older activity. |

### Files and link previews

| Method and path | Request and response |
| --- | --- |
| `GET /attachments/{attachmentId}` | Authorized download. |
| `GET /attachments/{attachmentId}/preview` | Authorized preview or playback. Video and voice playback support byte ranges. |
| `POST /conversations/{id}/link-preview` | Pass an eligible public HTTP or HTTPS `url`. Returns draft `preview` metadata or `null`. |
| `GET /conversations/{id}/link-preview/{key}/image` | Thumbnail from the caller’s cached draft preview. Use the URL from the lookup response. |
| `GET /conversations/{id}/messages/{messageId}/link-preview/image` | Thumbnail from a sent message visible to the caller. Use the URL from the message response. |

## Send a message

```json
{
  "text": "The review is ready.",
  "client_id": "becaf354-c98c-4f67-9f29-8f904e2edcca",
  "reply_to_id": 123
}
```

Reuse the UUID when retrying the same intended send after a timeout. Use `mentions` for group user IDs or set `mention_all`. For a selected preview, include a matching URL in `link_preview_url`. Set it to null when editing to remove the preview.

Use multipart form data for `attachments[]` or a standalone `voice_message`. Include `attachment_count` before the file parts to detect truncated uploads. Set `split_attachments=1` to create separate media and document messages in one request. The response includes the primary `message` and all resulting `messages` in order. A recording can include `voice_duration_ms` and up to 32 `voice_waveform[]` peaks from 0 to 100.

## Read a response

Actor IDs are strings. Conversation and message IDs are integers. Inbox rows include `id`, `type`, `title`, `is_self`, `member_count`, `unread_count`, `muted`, `archived`, `read_through`, and `latest` when a message exists. The detail response adds `members`. Use `latest.is_voice` and `latest.voice_duration_ms` to display a voice-specific preview.

Message objects contain sender details, timestamps, text, replies, mentions, reactions, attachments, `starred`, and optional `receipts` and `link_preview`. Check `can_edit`, `can_delete_for_all`, and `delete_for_all_until` before offering actions. A deleted message has a null body.

Attachment objects expose `download_url`, optional `preview_url` and `preview_type`, and for voice, `audio_url`, `audio_duration_ms`, and `audio_waveform`.

## Pagination

Keep the inbox scope when using `next_cursor` on the next page. History endpoints return `next_before` or `next_after` if another page is available in that direction. Follow the returned field and stop when it is null.

For inbox contacts, call `GET /people?inbox_page=1` and follow `next_inbox_page`. A page may contain zero contacts and still have a next page when its candidates already have chats or are outside the viewer's visibility rules.

Send `snapshot=` with an initial latest-page request to get a snapshot token. Repeat the request with that token to receive `{ "unchanged": true, "snapshot": "…" }` when the authorized page is unchanged. This applies to latest-page refreshes.

## Contact permissions

With [contact visibility](https://threads.teamkrope.com/docs/contact-visibility/) enabled, group detail responses include `members[].can_contact`. Use it to decide whether to offer a new direct chat from a group member's profile. Direct lookup, direct chat creation, group creation, and member invitations return `422` with `user_id` or `user_ids` field errors when a target cannot be contacted.

Conversation access by ID still follows the current workspace and membership. A caller can open and reply in an existing conversation even if that peer is absent from their contact directory. Existing group owner and admin permissions come from the group membership.

## Status codes

| Status | Meaning |
| --- | --- |
| `401` | Authentication required |
| `403` | Action denied |
| `404` | Record unavailable to the current workspace or member |
| `419` | Laravel CSRF or session failure |
| `422` | Field validation failed |
| `429` | Rate limit exceeded |

## CSRF example

```js
const csrf = document.querySelector('meta[name="csrf-token"]').content

const response = await fetch('/inner-threads/api/v1/conversations/42/messages', {
    method: 'POST',
    credentials: 'same-origin',
    headers: {
        Accept: 'application/json',
        'Content-Type': 'application/json',
        'X-CSRF-TOKEN': csrf
    },
    body: JSON.stringify({
        text: 'The checklist is ready.',
        client_id: crypto.randomUUID()
    })
})

if (!response.ok) throw new Error('Send failed')
const { message } = await response.json()
```
