Skip to main content

Client Reference

The @erdoai/server package provides the ErdoClient class for invoking Erdo agents from server-side code.

Installation

ErdoClient

Constructor

You must provide either 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. Requires authToken (API key) authentication.
CreateTokenParams:
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 same externalUserId across 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.
The 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.
TokenResponse:
Example:

invoke()

Invoke an agent and wait for the complete result.
Server-only: This method uses /bots/{key}/invoke which returns raw SSE events without message wrapping. For React UI rendering with the Content component, use thread-based messaging (sendMessage() or the useThread hook).
Parameters: InvokeParams:
InvokeResult:
Example:

invokeStream()

Invoke an agent and stream results as they arrive.
Server-only: This method uses /bots/{key}/invoke which returns raw SSE events without message wrapping. For React UI rendering with the Content component, use thread-based messaging (sendMessage() or the useThread hook).
SSEEvent:
Example:

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.
For persistent user threads (where users can return to their conversations), use externalUserId when creating tokens. This ensures the same user identity across sessions.

createThread()

Create a new thread for the authenticated user.
CreateThreadParams:
Thread:
Example:

listThreads()

List threads. The behavior depends on your authentication method:
ListThreadsParams:
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.
Example:

getThreadMessages()

Get all messages in a thread. Useful for loading conversation history when a user returns to a previous thread.
ListThreadMessagesResponse:
Example:
Use getThreadMessages() to build a threads sidebar where users can click on previous conversations and see the full message history with all visualizations.

sendMessage()

Send a message to a thread and stream the bot response.
SendMessageParams:
Example:

sendMessageAndWait()

Send a message and wait for the complete response (non-streaming).
Example:

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 externalUserId see the same threads and resources
  • Perfect for apps where users need to return to their conversation history
If you omit externalUserId, each token creates a new isolated user - useful for anonymous or one-time interactions.

Client-side: Use Token for Threads