Skip to main content

Create a client

The API key is secret. Create this client only on a trusted backend. See all constructor options.

turnContext(messages, options?)

Returns the context block for a conversation.

Arguments

EraMessage[]
required
Conversation history through the latest user message.
string
Visitor ID from the Web or Flutter SDK. It can also be set on the client.
string
Your stable ID for a signed-in user.
string
A backend-verified email address. Requires partnerEndUserId.
string
A backend-verified phone number. Requires partnerEndUserId.
string
Your stable ID for this conversation.
visitorId must be available on the call or client. partnerEndUserId is optional and does not replace it.

Result

The promise resolves to a plain string. Add it to your system prompt:
It resolves to "" without making a request when:
  • No visitorId is available.
  • The normalized conversation is empty.
  • The last normalized message is not from the user.
Expected network, timeout, and API failures also resolve to "". See Fail-open design.

HTTP request

The SDK normalizes messages into user and assistant turns, adds identity and session values, and sends the request for you.

Repeated calls

The latest result is memoized by identity, session, and turn number. Repeated calls for the same latest turn can share one HTTP request.