Client Reference
The@erdoai/server package provides the ErdoClient class for invoking Erdo agents from server-side code.
Installation
ErdoClient
Constructor
authToken or token. Use authToken for server-side code with full API access, and token for client-side code with limited scope.
createToken()
Create a scoped token for client-side use. RequiresauthToken (API key) authentication.
How External Users WorkEvery scoped token is linked to an external user - a real user identity in Erdo’s system. This enables proper RBAC and resource ownership.
-
With
externalUserId: If you provide the sameexternalUserIdacross multiple tokens, they all authenticate as the same user. This is useful when your users need persistent access to their threads and resources. -
Without
externalUserId: A new user is created for each token. Use this for one-off or anonymous interactions where user persistence isn’t needed.
externalUserId is your own user identifier (e.g., your database user ID). It’s only used for matching - Erdo maintains its own internal user IDs.invoke()
Invoke an agent and wait for the complete result.
InvokeParams:
invokeStream()
Invoke an agent and stream results as they arrive.Thread Methods
Thread methods work with any scoped token. Each token is linked to an external user, and threads created are owned by that user.createThread()
Create a new thread for the authenticated user.listThreads()
List threads. The behavior depends on your authentication method:- Scoped Token
- API Key
When using a scoped token, returns threads owned by the token’s user.
The
externalUserId parameter is ignored (the token already identifies the user).getThread()
Get a specific thread by ID.getThreadMessages()
Get all messages in a thread. Useful for loading conversation history when a user returns to a previous thread.sendMessage()
Send a message to a thread and stream the bot response.sendMessageAndWait()
Send a message and wait for the complete response (non-streaming).Content Types
Agents can return various content types:
ContentItem:
Error Handling
Node.js Example
B2B Integration Example
For B2B applications where your customers’ users need to interact with Erdo agents, use scoped tokens to provide secure, limited access.Server-side: Create Token for User
Why use
externalUserId?When you pass your user’s ID as externalUserId, Erdo creates a persistent user identity. This means:- The same user can have multiple tokens over time (e.g., after token expiry)
- All tokens with the same
externalUserIdsee the same threads and resources - Perfect for apps where users need to return to their conversation history
externalUserId, each token creates a new isolated user - useful for anonymous or one-time interactions.
