Skip to content

Node (@agentimhq/server) API

Generated from the source and its doc comments (sdk/node/index.d.ts).

Terminal window
npm install @agentimhq/server
function createUserToken(key: { kid: string; secret: string }, userId: string, opts?: { expiresIn?: number }): string

Signs a client token for a user (HS256 JWT, docs/en/design/access.md); no call to AgentIM.

class AgentIMError

An error answered by the server: code is the error code (forbidden, not_found, conflict, bad_request, rate_limited, …), status the HTTP status.

status: number

The HTTP status of the answer.

code: string

Same codes as the WebSocket protocol: forbidden, not_found, conflict, blocked, …

detail: string

The server’s explanation (the problem document’s detail).

type As = string

A user id, or “system”.

interface Message

A message to send through the open API.

as: As

Who sends it: a user id (a member) or system.

text: string

The text (for a custom kind, its plain-text fallback).

kind?: string

A custom kind (default text).

payload?: Record<string, unknown>

The structured content of a custom kind.

clientMsgId?: string

Your id for the message: sending again with the same id never doubles it.

replyTo?: string

The message it replies to.

threadId?: string

Replies in the thread of this root message (docs/en/design/messaging.md).

alsoInConv?: boolean

A thread reply that also shows in the conversation.

toUser?: string

Shows it only to this member (an ephemeral notice): not stored in the conversation’s history.

to?: string[]

Routing envelope (docs/en/design/agents.md–§6.3): members this asks to act, topics, intent, references.

topics?: string[]

Topics the message is about, for members that follow only some topics.

intent?: "request" | "proposal" | "answer" | "status" | "done"

What the message is: request, proposal, answer, status or done.

refs?: string[]

Ids of the messages it refers to.

sources?: { title: string; url: string; excerpt?: string }[]

Sources the message is based on.

interface Agent

An agent’s record.

id: string

The agent’s user id.

owner: string

The person responsible for it.

team: boolean

A team agent (stays when its owner leaves; can be transferred).

unit: string

The data unit (database) its conversations live in.

deactivated: boolean

Whether it is deactivated (cannot connect).

stopped: boolean

Whether it was stopped with the kill switch.

keys: any[]

Its keys (id, name, created, last used), never the secrets.

interface UserAttrs

A user’s attributes, for create and update.

kind?: "human" | "agent"

human (default) or agent.

owner?: string

For an agent: the person responsible for it.

unit?: string

The data unit (database) the user’s data lives in, for data residency.

team?: boolean

A team agent (stays when its owner leaves; can be transferred).

display_name?: string

The name others see.

avatar?: string

The avatar URL.

fields?: Record<string, unknown>

Your own fields (department, plan…), returned as they are.

class AgentIM

The open API client for your backend: an API key with the scopes the calls need. Retries network errors and 429/5xx with backoff; POSTs reuse one Idempotency-Key across retries.

request(method: string, path: string, body?: unknown, opts?: { idempotencyKey?: string }): Promise<any>

Any open API call: method, a path under /v1, an optional JSON body. Use the typed methods when there is one.

revokeTokens(userId: string): Promise<{ revoked: number }>

Logs a person out everywhere: client tokens issued until now are refused.

issueAgentKey(agentId: string, opts?: { revokeOthers?: boolean }): Promise<{ key: string; device_id: string; revoked: string[]; connect: any }>

A new key for an agent (agents:write). revokeOthers revokes every other key of the agent in the same write (rotation). The key is shown only here.

revokeAgentKeys(agentId: string): Promise<{ revoked: number }>

Revokes every key of an agent and disconnects it.

revokeAgentKey(agentId: string, deviceId: string): Promise<{ revoked: number }>

Revokes one key of an agent (by its device id) and disconnects that connection.

listAgents(userId: string): Promise<{ agents: Agent[] }>

The agents a person owns, with their keys (never the secrets).

stopAgent(agentId: string, opts?: { reason?: string }): Promise<Agent>

Stops an agent at once (kill switch): it is disconnected and every request is refused until resumeAgent.

resumeAgent(agentId: string): Promise<Agent>

Resumes a stopped agent.

transferAgent(agentId: string, opts: { owner: string; rotateKeys?: boolean }): Promise<Agent>

Gives a team agent to another person of its unit; rotateKeys revokes its keys in the same write.

destroyAgent(agentId: string): Promise<{ id: string; destroyed: boolean; conversations: number }>

Destroys an agent for good: keys revoked, memberships ended, checkpoints deleted. Its messages stay in the conversations; its name cannot be used again.

exportAgent(agentId: string, opts?: { withConversations?: boolean }): Promise<any>

Exports an agent (settings, checkpoints, optionally its conversations) as a package signed by this deployment, to import elsewhere.

importAgent(opts: { package: any; owner: string; name?: string; allowUnverified?: boolean }): Promise<{ agent: Agent; key: string; device_id: string; connect: any; verified: boolean }>

allowUnverified: accept a package this deployment cannot verify (unsigned, or from another deployment).

listDevices(userId: string): Promise<{ devices: any[] }>

A person’s devices (one per client token), with when each was last seen.

logoutDevice(userId: string, deviceId: string): Promise<{ revoked: number }>

Revokes one device’s token and disconnects it.

deleteUser(userId: string): Promise<any>

Deletes a person’s account (GDPR art. 17): logged out everywhere, then their content is erased in the background. Check progress with erasure.

erasure(userId: string): Promise<any>

Progress of an account deletion: running or done, with what was erased.

exportUser(userId: string, opts?: { after?: string }): Promise<any[]>

Everything about a person (GDPR art. 15 and 20) as JSON lines: profile, devices, conversations, their messages, reports. Pages with after; collects all pages.

reports(opts?: { state?: "open" | "resolved"; limit?: number; offset?: number }): Promise<{ reports: any[]; has_more: boolean }>

The moderation queue: reports by state, newest first, in pages.

getReport(id: string): Promise<any>

One report with its target and what was decided.

resolveReport(id: string, d: { action: "none" | "remove_content" | "suspend_user" | "ban_user"; reason: string; ground?: string; automated?: boolean; days?: number }): Promise<any>

Decides a report (DSA art. 16, 17): no action, remove the content, suspend or ban the user; the reason is shown to the people affected.

silenceMember(convId: string, userId: string, opts: { seconds: number; reason?: string }): Promise<{ user_id: string; silenced_until: number; changed: boolean; seq?: number }>

Silences a member of a conversation for seconds: they read but cannot send.

unsilenceMember(convId: string, userId: string): Promise<{ user_id: string; silenced_until: null; changed: boolean; seq?: number }>

Lifts a silence early.

upsertUser(id: string, attrs?: UserAttrs): Promise<any>

Creates or updates a user with your own id: a person, or an agent with an owner (then the answer carries its first key).

getUser(id: string): Promise<any>

A user by your id.

updateUser(id: string, attrs: Pick<UserAttrs, "display_name" | "avatar" | "fields">): Promise<any>

Changes a user’s display name, avatar or custom fields.

deactivateUser(id: string): Promise<any>

Deactivates a user: logged out everywhere and refused until reactivated; their data stays.

reactivateUser(id: string): Promise<any>

Reactivates a deactivated user.

batchUsers(users: Array<UserAttrs & { id: string }>): Promise<{ results: any[] }>

Creates or updates up to 100 users in one call; one result per user.

userConversations(id: string): Promise<{ convs: any[] }>

The conversations a user is in.

createConversation(c: { as: As; kind: "dm" | "group"; title: string; members?: string[]; owner?: string; fields?: Record<string, unknown> }): Promise<any>

Creates a conversation as a user or as the system (as: "system", then name an owner).

getConversation(id: string): Promise<any>

A conversation: kind, title, members, custom fields.

updateConversation(id: string, c: { as: As; title?: string; fields?: Record<string, unknown>; pinPolicy?: 'members' | 'admins' }): Promise<any>

Renames a conversation or replaces its custom fields.

dissolveConversation(id: string, as: As): Promise<any>

Dissolves a conversation: everyone loses access and the content is deleted.

addMembers(id: string, as: As, users: string[]): Promise<{ results: any[] }>

Adds users to a conversation; one result per user.

removeMember(id: string, user: string, as: As): Promise<any>

Removes a member.

setRole(id: string, user: string, role: "owner" | "admin" | "member", as: As): Promise<any>

Makes a member an admin or a member, or the owner (transfers ownership).

sendMessage(convId: string, m: Message): Promise<{ conv_id: string; seq?: number; msg_id?: string; duplicate?: boolean }>

Sends a message as a member or as the system. With clientMsgId a retry returns the first result (duplicate: true).

uploadFile(convId: string, opts: { as: string; name: string; data: Uint8Array | ArrayBuffer | Blob; mime?: string }): Promise<FileInfo>

Uploads a whole file (at most 64 MiB); the server removes EXIF and GPS and makes a thumbnail.

sendFile(convId: string, opts: { as: string; name: string; data: Uint8Array | ArrayBuffer | Blob; mime?: string; caption?: string; replyTo?: string }): Promise<{ conv_id: string; seq?: number; msg_id?: string; file: FileInfo }>

Uploads a file and sends it as an image or file message.

fileUrl(convId: string, fileId: string, opts?: { as?: string; variant?: "original" | "thumb" }): Promise<{ url: string; variant: string; expires_at: number; file: FileInfo }>

A link (valid 5 minutes) to read a file.

sendToUser(userId: string, m: Message): Promise<any>

Sends to a user directly: the direct conversation with them is opened if needed.

batchSend(m: { as: As; to: string[]; text: string; kind?: string; payload?: Record<string, unknown>; clientMsgId?: string }): Promise<{ results: any[] }>

Sends the same message to up to 100 users (each in their direct conversation); one result per user.

editMessage(id: string, m: { as: As; text: string; payload?: Record<string, unknown> }): Promise<{ seq: number }>

Edits a message as its sender (or the system).

recallMessage(id: string, as: As): Promise<{ seq: number }>

Recalls a message for everyone.

history(convId: string, opts?: { afterSeq?: number; limit?: number }): Promise<{ events: any[]; next_after_seq: number; has_more: boolean }>

A conversation’s events after a seq, in pages (your backend’s own records, search, analytics).

markRead(convId: string, as: As, seq: number): Promise<{}>

Marks a conversation read up to seq for a user.

listThreads(convId: string, opts?: { as?: string; before?: number; limit?: number }): Promise<{ threads: any[]; more: boolean; unread_threads: number }>

Threads of a conversation, latest reply first (with as: the ones that user follows, with unread counts).

getThread(convId: string, threadId: string, opts?: { afterSeq?: number; limit?: number }): Promise<{ root: any; thread: any; replies: any[]; more: boolean }>

A thread’s root, summary and replies.

addReaction(convId: string, msgId: string, key: string, as: string): Promise<{ changed: boolean; seq: number | null }>

Adds a member’s reaction; adding it again changes nothing.

removeReaction(convId: string, msgId: string, key: string, as: string): Promise<{ changed: boolean; seq: number | null }>

Removes a member’s reaction.

listReactions(convId: string, msgId: string, key: string, opts?: { afterSeq?: number; limit?: number }): Promise<{ users: { user_id: string; name?: string; seq: number; at: number }[]; more: boolean }>

Who reacted with a key, oldest first.

listPins(convId: string, opts?: { beforeSeq?: number; limit?: number }): Promise<{ pins: any[]; more: boolean; count: number; pin_policy: string }>

Pinned messages, latest pin first.

pinMessage(convId: string, msgId: string, as: string): Promise<{ changed: boolean; seq: number | null }>

Pins a message as a member; pinning it again changes nothing.

unpinMessage(convId: string, msgId: string, as: string): Promise<{ changed: boolean; seq: number | null }>

Unpins a message as a member.

interface FileInfo

A stored file (docs/en/design/messaging.md).

file_id: string

The file id; send it in a message or ask for its URL.

name: string

The file name as uploaded.

size: number

The size in bytes.

mime: string

The content type.

kind: "image" | "file"

image (shown inline, has a size) or file.

width: number | null

An image’s width in pixels, upright (null for other files).

height: number | null

An image’s height in pixels, upright (null for other files).

thumb: boolean

Whether it has a thumbnail.

ai_generated: boolean

Whether it is marked as made by AI (EU AI Act Art. 50); agents’ uploads always are.