Skip to content

Go API

Generated from the source and its doc comments (sdk/go/agentim/agentim.go).

Terminal window
go get github.com/wmkrfjnwvb-svg/agentim/sdk/go/agentim
func New(baseURL, apiKey string) *Client

New returns a client with 3 retries and a 30 second timeout.

func CreateUserToken(kid, secret, userID string, expiresIn time.Duration) (string, error)

CreateUserToken signs a client token for one of your users (docs/en/design/access.md §4.2): an HS256 JWT with the signing key from agentim signing-key create. Do this in your backend after your own login and give the token to your app; no call to AgentIM is made.

type Error struct

Error is an error answered by the server (RFC 9457 problem details). Code is one of the protocol’s codes: forbidden, not_found, conflict, blocked…

func (e *Error) Error() string { return fmt.Sprintf("%d %s: %s", e.Status, e.Code, e.Detail) }

Error formats the HTTP status, the error code and the server’s explanation.

type Client struct

Client calls the open API with one API key.

func (c *Client) Do(ctx context.Context, method, path string, body any, out any) error

Do is the low-level call: POSTs get an Idempotency-Key reused across retries; GET, PUT and POST are retried on network errors, 429 and 503.

func (c *Client) DoRaw(ctx context.Context, method, path string, data []byte, out any) error

DoRaw sends bytes as the body (application/octet-stream), e.g. a file.

func (c *Client) RevokeTokens(ctx context.Context, userID string) (M, error)

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

func (c *Client) IssueAgentKey(ctx context.Context, agentID string, revokeOthers bool) (M, error)

IssueAgentKey returns a new key for an agent; revokeOthers revokes every other key of it in the same write (rotation). The key is shown only here.

func (c *Client) RevokeAgentKeys(ctx context.Context, agentID string) (M, error)

RevokeAgentKeys revokes every key of an agent and disconnects it.

func (c *Client) RevokeAgentKey(ctx context.Context, agentID, deviceID string) (M, error)

RevokeAgentKey revokes one key of an agent (by its device id).

func (c *Client) ListAgents(ctx context.Context, userID string) (M, error)

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

func (c *Client) StopAgent(ctx context.Context, agentID, reason string) (M, error)

StopAgent stops an agent at once (kill switch): it is disconnected and refused until ResumeAgent.

func (c *Client) ResumeAgent(ctx context.Context, agentID string) (M, error)

ResumeAgent resumes a stopped agent.

func (c *Client) TransferAgent(ctx context.Context, agentID, owner string, rotateKeys bool) (M, error)

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

func (c *Client) DestroyAgent(ctx context.Context, agentID string) (M, error)

DestroyAgent destroys an agent for good: keys revoked, memberships ended, checkpoints deleted.

func (c *Client) ExportAgent(ctx context.Context, agentID string, withConversations bool) (M, error)

ExportAgent exports an agent (settings, checkpoints, optionally its conversations) as a package signed by this deployment.

func (c *Client) ImportAgent(ctx context.Context, pkg M, owner, name string, allowUnverified bool) (M, error)

ImportAgent creates an agent from a package. allowUnverified accepts a package this deployment cannot verify (unsigned, or from another deployment).

func (c *Client) ListDevices(ctx context.Context, userID string) (M, error)

ListDevices returns a person’s devices (one per client token).

func (c *Client) LogoutDevice(ctx context.Context, userID, deviceID string) (M, error)

LogoutDevice revokes one device’s token and disconnects it.

func (c *Client) DeleteUser(ctx context.Context, userID string) (M, error)

DeleteUser deletes a person’s account; it returns the erasure’s progress.

func (c *Client) Erasure(ctx context.Context, userID string) (M, error)

Erasure returns the progress of an account deletion: running or done.

func (c *Client) ExportUser(ctx context.Context, userID, after string) ([]M, error)

ExportUser returns the person’s own data, one object per line (NDJSON); after continues from a line’s cursor.

func (c *Client) Reports(ctx context.Context, state string, limit, offset int) (M, error)

Reports returns the moderation queue by state, newest first, in pages.

func (c *Client) GetReport(ctx context.Context, id string) (M, error)

GetReport returns one report with its target and what was decided.

func (c *Client) ResolveReport(ctx context.Context, id string, decision M) (M, error)

ResolveReport takes action (none, remove_content, suspend_user, ban_user), reason and, for suspend_user, days.

func (c *Client) SilenceMember(ctx context.Context, convID, userID string, seconds int, reason string) (M, error)

SilenceMember stops a member from sending, editing or streaming in the conversation for seconds.

func (c *Client) UnsilenceMember(ctx context.Context, convID, userID string) (M, error)

UnsilenceMember lifts a silence early.

func (c *Client) UpsertUser(ctx context.Context, id string, attrs M) (M, error)

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

func (c *Client) GetUser(ctx context.Context, id string) (M, error)

GetUser returns a user by your id.

func (c *Client) UpdateUser(ctx context.Context, id string, attrs M) (M, error)

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

func (c *Client) DeactivateUser(ctx context.Context, id string) (M, error)

DeactivateUser logs a user out everywhere and refuses them until reactivated; their data stays.

func (c *Client) ReactivateUser(ctx context.Context, id string) (M, error)

ReactivateUser reactivates a deactivated user.

func (c *Client) BatchUsers(ctx context.Context, users []M) (M, error)

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

func (c *Client) UserConversations(ctx context.Context, id string) (M, error)

UserConversations returns the conversations a user is in.

func (c *Client) CreateConversation(ctx context.Context, conv M) (M, error)

CreateConversation creates a conversation as a user or as the system (“as”: “system”, then name an “owner”).

func (c *Client) GetConversation(ctx context.Context, id string) (M, error)

GetConversation returns a conversation: kind, title, members, custom fields.

func (c *Client) UpdateConversation(ctx context.Context, id string, change M) (M, error)

UpdateConversation renames a conversation or replaces its custom fields.

func (c *Client) DissolveConversation(ctx context.Context, id, as string) (M, error)

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

func (c *Client) AddMembers(ctx context.Context, id, as string, users []string) (M, error)

AddMembers adds users to a conversation; one result per user.

func (c *Client) RemoveMember(ctx context.Context, id, user, as string) (M, error)

RemoveMember removes a member.

func (c *Client) SetRole(ctx context.Context, id, user, role, as string) (M, error)

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

func (c *Client) UploadFile(ctx context.Context, convID, as, name string, data []byte, mime string) (M, error)

UploadFile uploads a whole file (at most 64 MiB) as user as: the server removes EXIF and GPS and makes a thumbnail. mime may be empty.

func (c *Client) SendFile(ctx context.Context, convID, as, name string, data []byte, mime, caption string) (M, error)

SendFile uploads a file and sends it as an image or file message.

func (c *Client) FileURL(ctx context.Context, convID, fileID, as, variant string) (M, error)

FileURL is a link (valid 5 minutes) to read a file; variant is “original”, “thumb” or empty, as may be empty (the system).

func (c *Client) SendMessage(ctx context.Context, convID string, m M) (M, error)

SendMessage sends a message as a member or as the system; with client_msg_id a retry returns the first result.

func (c *Client) SendToUser(ctx context.Context, userID string, m M) (M, error)

SendToUser sends to a user in their direct conversation, opened if needed.

func (c *Client) BatchSend(ctx context.Context, m M) (M, error)

BatchSend sends the same message to up to 100 users; one result per user.

func (c *Client) EditMessage(ctx context.Context, id string, m M) (M, error)

EditMessage edits a message as its sender (or the system).

func (c *Client) RecallMessage(ctx context.Context, id, as string) (M, error)

RecallMessage recalls a message for everyone.

func (c *Client) History(ctx context.Context, convID string, afterSeq, limit int) (M, error)

History returns a conversation’s events after a seq, in pages.

func (c *Client) MarkRead(ctx context.Context, convID, as string, seq int) (M, error)

MarkRead marks a conversation read up to seq for a user.

func (c *Client) ListThreads(ctx context.Context, convID, as string) (M, error)

ListThreads lists a conversation’s threads, latest reply first; with as, the ones that user follows.

func (c *Client) GetThread(ctx context.Context, convID, threadID string, afterSeq int) (M, error)

GetThread returns a thread’s root, summary and replies after a seq.

func (c *Client) AddReaction(ctx context.Context, convID, msgID, key, as string) (M, error)

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

func (c *Client) RemoveReaction(ctx context.Context, convID, msgID, key, as string) (M, error)

RemoveReaction removes a member’s reaction.

func (c *Client) ListReactions(ctx context.Context, convID, msgID, key string) (M, error)

ListReactions lists who reacted with a key, oldest first.

func (c *Client) ListPins(ctx context.Context, convID string) (M, error)

ListPins lists the pinned messages, latest pin first.

func (c *Client) PinMessage(ctx context.Context, convID, msgID, as string) (M, error)

PinMessage pins a message as a member; pinning it again changes nothing.

func (c *Client) UnpinMessage(ctx context.Context, convID, msgID, as string) (M, error)

UnpinMessage unpins a message as a member.

type M = map[string]any

M is a JSON object.