Use Node.js’s built-in fetch to call the Chat HTTP API from your server. Session creation uses your API credential; the returned session key authenticates subsequent turns.
Before you begin
- A supported Node.js release with built-in
fetch. - A published Chat agent. Build and publish one from code if you are starting from an empty workspace.
- A personal or service key authorized for the project’s
project:READandproject.versions:READactions.
Set VF_TOKEN from your server’s secret store, VF_PROJECT_ID to the agent’s project ID and VF_ENVIRONMENT to the published Environment’s alias. This example uses Voiceflow’s default public runtime. Keep the API credential and session keys out of browser bundles and logs.
Run a conversation
Save the server script
Save the following as chat.mjs:
JSON.stringify encodes customer text safely, including quotes and line breaks. Send the returned session key directly in Authorization, without adding Bearer.
Run the script
The script creates a new conversation, launches the agent, sends one message and prints its text reply. It does not create or publish agent resources.
Verify the reply
Check that the reply follows your published agent’s instructions. HTTP success and a parsed response do not establish that the agent completed the intended customer task.
In your application, retain each customer conversation’s session key and reuse it for later turns. Calling the session-creation endpoint again starts a new session rather than resuming the previous one. Use HTTP Streaming when your interface needs incremental responses.