Node (@agentimhq/server) API
Generated from the source and its doc comments (sdk/node/index.d.ts).
npm install @agentimhq/serverFunctions
Section titled “Functions”createUserToken
Section titled “createUserToken”function createUserToken(key: { kid: string; secret: string }, userId: string, opts?: { expiresIn?: number }): stringSigns a client token for a user (HS256 JWT, docs/en/design/access.md); no call to AgentIM.
AgentIMError
Section titled “AgentIMError”class AgentIMErrorAn error answered by the server: code is the error code (forbidden, not_found, conflict, bad_request, rate_limited, …), status the HTTP status.
AgentIMError.status
Section titled “AgentIMError.status”status: numberThe HTTP status of the answer.
AgentIMError.code
Section titled “AgentIMError.code”code: stringSame codes as the WebSocket protocol: forbidden, not_found, conflict, blocked, …
AgentIMError.detail
Section titled “AgentIMError.detail”detail: stringThe server’s explanation (the problem document’s detail).
type As = stringA user id, or “system”.
Message
Section titled “Message”interface MessageA message to send through the open API.
Message.as
Section titled “Message.as”as: AsWho sends it: a user id (a member) or system.
Message.text
Section titled “Message.text”text: stringThe text (for a custom kind, its plain-text fallback).
Message.kind
Section titled “Message.kind”kind?: stringA custom kind (default text).
Message.payload
Section titled “Message.payload”payload?: Record<string, unknown>The structured content of a custom kind.
Message.clientMsgId
Section titled “Message.clientMsgId”clientMsgId?: stringYour id for the message: sending again with the same id never doubles it.
Message.replyTo
Section titled “Message.replyTo”replyTo?: stringThe message it replies to.
Message.threadId
Section titled “Message.threadId”threadId?: stringReplies in the thread of this root message (docs/en/design/messaging.md).
Message.alsoInConv
Section titled “Message.alsoInConv”alsoInConv?: booleanA thread reply that also shows in the conversation.
Message.toUser
Section titled “Message.toUser”toUser?: stringShows it only to this member (an ephemeral notice): not stored in the conversation’s history.
Message.to
Section titled “Message.to”to?: string[]Routing envelope (docs/en/design/agents.md–§6.3): members this asks to act, topics, intent, references.
Message.topics
Section titled “Message.topics”topics?: string[]Topics the message is about, for members that follow only some topics.
Message.intent
Section titled “Message.intent”intent?: "request" | "proposal" | "answer" | "status" | "done"What the message is: request, proposal, answer, status or done.
Message.refs
Section titled “Message.refs”refs?: string[]Ids of the messages it refers to.
Message.sources
Section titled “Message.sources”sources?: { title: string; url: string; excerpt?: string }[]Sources the message is based on.
interface AgentAn agent’s record.
Agent.id
Section titled “Agent.id”id: stringThe agent’s user id.
Agent.owner
Section titled “Agent.owner”owner: stringThe person responsible for it.
Agent.team
Section titled “Agent.team”team: booleanA team agent (stays when its owner leaves; can be transferred).
Agent.unit
Section titled “Agent.unit”unit: stringThe data unit (database) its conversations live in.
Agent.deactivated
Section titled “Agent.deactivated”deactivated: booleanWhether it is deactivated (cannot connect).
Agent.stopped
Section titled “Agent.stopped”stopped: booleanWhether it was stopped with the kill switch.
Agent.keys
Section titled “Agent.keys”keys: any[]Its keys (id, name, created, last used), never the secrets.
UserAttrs
Section titled “UserAttrs”interface UserAttrsA user’s attributes, for create and update.
UserAttrs.kind
Section titled “UserAttrs.kind”kind?: "human" | "agent"human (default) or agent.
UserAttrs.owner
Section titled “UserAttrs.owner”owner?: stringFor an agent: the person responsible for it.
UserAttrs.unit
Section titled “UserAttrs.unit”unit?: stringThe data unit (database) the user’s data lives in, for data residency.
UserAttrs.team
Section titled “UserAttrs.team”team?: booleanA team agent (stays when its owner leaves; can be transferred).
UserAttrs.display_name
Section titled “UserAttrs.display_name”display_name?: stringThe name others see.
UserAttrs.avatar
Section titled “UserAttrs.avatar”avatar?: stringThe avatar URL.
UserAttrs.fields
Section titled “UserAttrs.fields”fields?: Record<string, unknown>Your own fields (department, plan…), returned as they are.
AgentIM
Section titled “AgentIM”class AgentIMThe 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.
AgentIM.request
Section titled “AgentIM.request”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.
AgentIM.revokeTokens
Section titled “AgentIM.revokeTokens”revokeTokens(userId: string): Promise<{ revoked: number }>Logs a person out everywhere: client tokens issued until now are refused.
AgentIM.issueAgentKey
Section titled “AgentIM.issueAgentKey”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.
AgentIM.revokeAgentKeys
Section titled “AgentIM.revokeAgentKeys”revokeAgentKeys(agentId: string): Promise<{ revoked: number }>Revokes every key of an agent and disconnects it.
AgentIM.revokeAgentKey
Section titled “AgentIM.revokeAgentKey”revokeAgentKey(agentId: string, deviceId: string): Promise<{ revoked: number }>Revokes one key of an agent (by its device id) and disconnects that connection.
AgentIM.listAgents
Section titled “AgentIM.listAgents”listAgents(userId: string): Promise<{ agents: Agent[] }>The agents a person owns, with their keys (never the secrets).
AgentIM.stopAgent
Section titled “AgentIM.stopAgent”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.
AgentIM.resumeAgent
Section titled “AgentIM.resumeAgent”resumeAgent(agentId: string): Promise<Agent>Resumes a stopped agent.
AgentIM.transferAgent
Section titled “AgentIM.transferAgent”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.
AgentIM.destroyAgent
Section titled “AgentIM.destroyAgent”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.
AgentIM.exportAgent
Section titled “AgentIM.exportAgent”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.
AgentIM.importAgent
Section titled “AgentIM.importAgent”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).
AgentIM.listDevices
Section titled “AgentIM.listDevices”listDevices(userId: string): Promise<{ devices: any[] }>A person’s devices (one per client token), with when each was last seen.
AgentIM.logoutDevice
Section titled “AgentIM.logoutDevice”logoutDevice(userId: string, deviceId: string): Promise<{ revoked: number }>Revokes one device’s token and disconnects it.
AgentIM.deleteUser
Section titled “AgentIM.deleteUser”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.
AgentIM.erasure
Section titled “AgentIM.erasure”erasure(userId: string): Promise<any>Progress of an account deletion: running or done, with what was erased.
AgentIM.exportUser
Section titled “AgentIM.exportUser”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.
AgentIM.reports
Section titled “AgentIM.reports”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.
AgentIM.getReport
Section titled “AgentIM.getReport”getReport(id: string): Promise<any>One report with its target and what was decided.
AgentIM.resolveReport
Section titled “AgentIM.resolveReport”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.
AgentIM.silenceMember
Section titled “AgentIM.silenceMember”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.
AgentIM.unsilenceMember
Section titled “AgentIM.unsilenceMember”unsilenceMember(convId: string, userId: string): Promise<{ user_id: string; silenced_until: null; changed: boolean; seq?: number }>Lifts a silence early.
AgentIM.upsertUser
Section titled “AgentIM.upsertUser”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).
AgentIM.getUser
Section titled “AgentIM.getUser”getUser(id: string): Promise<any>A user by your id.
AgentIM.updateUser
Section titled “AgentIM.updateUser”updateUser(id: string, attrs: Pick<UserAttrs, "display_name" | "avatar" | "fields">): Promise<any>Changes a user’s display name, avatar or custom fields.
AgentIM.deactivateUser
Section titled “AgentIM.deactivateUser”deactivateUser(id: string): Promise<any>Deactivates a user: logged out everywhere and refused until reactivated; their data stays.
AgentIM.reactivateUser
Section titled “AgentIM.reactivateUser”reactivateUser(id: string): Promise<any>Reactivates a deactivated user.
AgentIM.batchUsers
Section titled “AgentIM.batchUsers”batchUsers(users: Array<UserAttrs & { id: string }>): Promise<{ results: any[] }>Creates or updates up to 100 users in one call; one result per user.
AgentIM.userConversations
Section titled “AgentIM.userConversations”userConversations(id: string): Promise<{ convs: any[] }>The conversations a user is in.
AgentIM.createConversation
Section titled “AgentIM.createConversation”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).
AgentIM.getConversation
Section titled “AgentIM.getConversation”getConversation(id: string): Promise<any>A conversation: kind, title, members, custom fields.
AgentIM.updateConversation
Section titled “AgentIM.updateConversation”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.
AgentIM.dissolveConversation
Section titled “AgentIM.dissolveConversation”dissolveConversation(id: string, as: As): Promise<any>Dissolves a conversation: everyone loses access and the content is deleted.
AgentIM.addMembers
Section titled “AgentIM.addMembers”addMembers(id: string, as: As, users: string[]): Promise<{ results: any[] }>Adds users to a conversation; one result per user.
AgentIM.removeMember
Section titled “AgentIM.removeMember”removeMember(id: string, user: string, as: As): Promise<any>Removes a member.
AgentIM.setRole
Section titled “AgentIM.setRole”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).
AgentIM.sendMessage
Section titled “AgentIM.sendMessage”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).
AgentIM.uploadFile
Section titled “AgentIM.uploadFile”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.
AgentIM.sendFile
Section titled “AgentIM.sendFile”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.
AgentIM.fileUrl
Section titled “AgentIM.fileUrl”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.
AgentIM.sendToUser
Section titled “AgentIM.sendToUser”sendToUser(userId: string, m: Message): Promise<any>Sends to a user directly: the direct conversation with them is opened if needed.
AgentIM.batchSend
Section titled “AgentIM.batchSend”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.
AgentIM.editMessage
Section titled “AgentIM.editMessage”editMessage(id: string, m: { as: As; text: string; payload?: Record<string, unknown> }): Promise<{ seq: number }>Edits a message as its sender (or the system).
AgentIM.recallMessage
Section titled “AgentIM.recallMessage”recallMessage(id: string, as: As): Promise<{ seq: number }>Recalls a message for everyone.
AgentIM.history
Section titled “AgentIM.history”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).
AgentIM.markRead
Section titled “AgentIM.markRead”markRead(convId: string, as: As, seq: number): Promise<{}>Marks a conversation read up to seq for a user.
AgentIM.listThreads
Section titled “AgentIM.listThreads”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).
AgentIM.getThread
Section titled “AgentIM.getThread”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.
AgentIM.addReaction
Section titled “AgentIM.addReaction”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.
AgentIM.removeReaction
Section titled “AgentIM.removeReaction”removeReaction(convId: string, msgId: string, key: string, as: string): Promise<{ changed: boolean; seq: number | null }>Removes a member’s reaction.
AgentIM.listReactions
Section titled “AgentIM.listReactions”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.
AgentIM.listPins
Section titled “AgentIM.listPins”listPins(convId: string, opts?: { beforeSeq?: number; limit?: number }): Promise<{ pins: any[]; more: boolean; count: number; pin_policy: string }>Pinned messages, latest pin first.
AgentIM.pinMessage
Section titled “AgentIM.pinMessage”pinMessage(convId: string, msgId: string, as: string): Promise<{ changed: boolean; seq: number | null }>Pins a message as a member; pinning it again changes nothing.
AgentIM.unpinMessage
Section titled “AgentIM.unpinMessage”unpinMessage(convId: string, msgId: string, as: string): Promise<{ changed: boolean; seq: number | null }>Unpins a message as a member.
FileInfo
Section titled “FileInfo”interface FileInfoA stored file (docs/en/design/messaging.md).
FileInfo.file_id
Section titled “FileInfo.file_id”file_id: stringThe file id; send it in a message or ask for its URL.
FileInfo.name
Section titled “FileInfo.name”name: stringThe file name as uploaded.
FileInfo.size
Section titled “FileInfo.size”size: numberThe size in bytes.
FileInfo.mime
Section titled “FileInfo.mime”mime: stringThe content type.
FileInfo.kind
Section titled “FileInfo.kind”kind: "image" | "file"image (shown inline, has a size) or file.
FileInfo.width
Section titled “FileInfo.width”width: number | nullAn image’s width in pixels, upright (null for other files).
FileInfo.height
Section titled “FileInfo.height”height: number | nullAn image’s height in pixels, upright (null for other files).
FileInfo.thumb
Section titled “FileInfo.thumb”thumb: booleanWhether it has a thumbnail.
FileInfo.ai_generated
Section titled “FileInfo.ai_generated”ai_generated: booleanWhether it is marked as made by AI (EU AI Act Art. 50); agents’ uploads always are.