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

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

1

Save the server script

Save the following as chat.mjs:

chat.mjs

JSON.stringify encodes customer text safely, including quotes and line breaks. Send the returned session key directly in Authorization, without adding Bearer.

2

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.

Troubleshooting

Use the up and down arrow keys to select a result, Enter to open it, and Escape to close the search.