Skip to main content
This guide adds Era to a trusted Node.js backend. Your browser or mobile app should never receive the Node SDK API key. You need Node.js 18 or later, an Era API key, a partner ID, and a visitorId from the Web SDK or Flutter SDK.
1

Install

2

Create the client

Create one client and reuse it. Keep all three values on your backend.
3

Get context before the model call

Call turnContext() after adding the latest user message to messages.
Use the same visitorId for the same visitor. Use the same sessionId for every turn in one conversation.
4

Add the context to your system prompt

eraContext is a plain string. If it is empty, continue with the model call as usual.

Complete example

What to expect

The default mode is async:
  • The first turn normally returns "".
  • Later turns return the previous turn’s prepared context.
  • Network and API failures return "" instead of breaking your chat.
Use mode: "sync" if you need context for the current turn and can accept the extra latency.

Add signed-in identity

If your backend knows the signed-in user, include your stable user ID:
You can also send a verified email or phone with partnerEndUserId. Never copy those values directly from untrusted client input.

Next steps

Async and sync modes

Choose when Era prepares context.

Node SDK reference

See every client method and option.