> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sambanova.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Voiceflow integration guide

[Voiceflow](https://www.voiceflow.com/) is a no-code builder for chat and voice agents. Its model picker offers only Voiceflow-hosted models and has no custom model option, so SambaCloud is not selectable there. A workflow can still call any HTTP API from a **Function** step, which lets a SambaCloud model produce the replies in your conversation. This guide builds a small chat workflow that does this, with conversation memory.

> [!NOTE]
>
> This guide was tested on the Voiceflow Free plan in November 2026. Menu names and limits can change, so check the [Voiceflow documentation](https://www.voiceflow.com/docs/documentation/build/tools/function-tool) if a screen looks different.

## Prerequisites

* A [SambaCloud](https://cloud.sambanova.ai/?utm_source=voiceflow\&utm_medium=external\&utm_campaign=cloud_signup) account and [API key](https://cloud.sambanova.ai/apis?utm_source=voiceflow\&utm_medium=external\&utm_campaign=cloud_signup)
* A [Voiceflow](https://creator.voiceflow.com/) account and an agent. A new agent starts with an **Untitled workflow**, which is all you need.

## Find your way around Voiceflow

The build steps below happen in two different places, so it helps to know both before you start.

* **The workflow canvas** is the dotted grid you build on. Open it from the left sidebar: under **Build**, click **Workflows**, then click **Untitled workflow**. The canvas holds a green **Start** pill and the steps you drag onto it, joined by arrows.
* **The step palette** floats on the left edge of the canvas. A dropdown at the top of it switches between **Agentic** steps (Playbook, Crew) and **Scripted** steps (Message, Cards, Carousel, Buttons, Listen). Below the dropdown, **Tools** (API, Function, Integration, MCP) and **Logic** stay visible in both modes.
* **Secrets** is a separate full-screen page, not part of the canvas. Reach it from **Settings**, or press `Cmd + K` and type `secrets`.

> [!WARNING]
>
> Build this on a **workflow**, not on the **Agent** page. If the left sidebar shows **Agent** selected and the browser address ends in `/agent`, you are in the wrong place. An agent decides for itself when to call a tool and answers from its own Voiceflow model the rest of the time, and it generates the tool's input values instead of reading your secret. See [What this integration does not cover](#what-this-integration-does-not-cover).

## Store your API key as a secret

**1. Create the secret**

Open **Secrets** from **Settings**, or press `Cmd + K` and type `secrets`. Click **New secret**. Set **Name** to `sambanova_api_key`, paste your SambaCloud API key into **Default value**, leave **Visibility** as **Masked**, and click **Create secret**. Paste only the key, without a `Bearer ` prefix.

![Voiceflow Secrets page listing the sambanova\_api\_key secret with a masked default value](https://mintcdn.com/sambanova-systems/dcD1i9TfmqLehxz2/images/docs/integrations/voiceflow/secret.png?fit=max\&auto=format\&n=dcD1i9TfmqLehxz2\&q=85\&s=1e276ed76bce166578ac0eedadfe801b)

## Create the Function tool

The function sends the conversation to SambaCloud and returns the reply. Voiceflow runs it in a sandbox, so nothing persists between runs. The function receives the conversation history as an input and returns the updated history as an output.

**1. Add a Function step**

Open the workflow on the canvas. In the step palette, under **Tools**, drag **Function** onto the canvas. In the panel that opens on the right, click **Create function tool**.

> [!TIP]
>
> If you already built this function somewhere else in the agent, pick it from the dropdown at the top of that panel instead of creating it again. One function tool can be used by any number of steps.

**2. Name the tool and add variables**

Set **Name** to `ask_sambanova_fn`. Under **Input variables**, add `question`, `api_key`, and `chat_history`. Under **Output variables**, add `answer` and `chat_history`.

**3. Paste the code**

The editor already contains the first line, `export default async function main(args) {`, and the last line, `}`. Select all, delete, and paste only the lines between them:

```javascript theme={}
  const { question, api_key, chat_history } = args.inputVars;

  // A new variable starts as "0", so only accept a stored array.
  let messages = [];
  try {
    const stored = JSON.parse(chat_history);
    if (Array.isArray(stored)) messages = stored;
  } catch (e) {}
  messages.push({ role: 'user', content: question });

  const response = await fetch('https://api.sambanova.ai/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${api_key}`,
    },
    body: JSON.stringify({
      model: 'MiniMax-M3.1-Flash',
      max_tokens: 1024,
      messages,
    }),
  });

  if (!response.ok) {
    throw new Error(`SambaCloud returned ${response.status}: ${JSON.stringify(response.json)}`);
  }

  const answer = response.json.choices[0].message.content;
  if (!answer) {
    // The model used all of max_tokens on reasoning and wrote no text.
    // Return a short message and keep the unanswered question out of the history.
    return {
      outputVars: {
        answer: 'The model ran out of room before it finished. Try a shorter or simpler question.',
        chat_history: JSON.stringify(messages.slice(0, -1)),
      },
    };
  }
  messages.push({ role: 'assistant', content: answer });

  return {
    outputVars: { answer, chat_history: JSON.stringify(messages) },
  };
```

The Voiceflow `fetch` returns the parsed body as the `json` property, so there is no `.json()` call. `JSON.stringify` escapes quotes in the user's message, which a fixed request body cannot do. The `if (!answer)` check covers a reply with no text: SambaCloud answers HTTP 200 with an empty `content` when reasoning uses up `max_tokens`, so `response.ok` does not catch it.

![Voiceflow function editor for ask\_sambanova\_fn with three input variables, two output variables, and JavaScript that calls the SambaCloud chat completions endpoint](https://mintcdn.com/sambanova-systems/dcD1i9TfmqLehxz2/images/docs/integrations/voiceflow/function-editor.png?fit=max\&auto=format\&n=dcD1i9TfmqLehxz2\&q=85\&s=19bfa2bd9bdc2e7c30b7303c881b9801)

## Build the workflow

**1. Add the other steps**

**Listen** and **Message** are **Scripted** steps, so switch the dropdown at the top of the step palette from **Agentic** to **Scripted** to see them. Drag one of each onto the canvas. Connect **Start** to **Listen**, **Listen** to the Function step, the Function step to **Message**, and **Message** back to **Listen** so the chat continues after each reply. **Listen** saves what the user types to the `last_utterance` variable.

**2. Map the Function inputs**

Click the Function step. The right panel lists the three inputs, each marked **Not added**. Click a row, then type `{` in the field to open the picker. If the picker closes before you choose, type `{` again to reopen it.

* `question`: on the **Variables** tab, select `last_utterance`
* `api_key`: switch to the **Secrets** tab and select `sambanova_api_key`
* `chat_history`: this variable does not exist yet, so the list does not contain it. Keep typing `chat_history` after the `{` until the list is empty, then click **Create variable** at the bottom of the picker and turn **Persist across sessions** off, so one chat does not carry into the next.

Each row changes to **Added** once it is mapped.

**3. Save the Function outputs**

Both outputs start as **Not saved**. Click each row and choose where to save it: `answer` goes to a new variable named `sambanova_answer`, and `chat_history` goes to the `chat_history` variable you just created. Both rows must read **Saved** before the workflow will work, because an unsaved output never reaches the **Message** step.

**4. Show the answer**

The **Message** step still reads **Add message**, which sends an empty reply. Click it, type `{`, and select `sambanova_answer`.

![Voiceflow canvas with Start, Listen, ask\_sambanova\_fn, and a Message step, and the Function tool panel showing question, api\_key, and chat\_history as added and answer and chat\_history as saved](https://mintcdn.com/sambanova-systems/dcD1i9TfmqLehxz2/images/docs/integrations/voiceflow/function-step.png?fit=max\&auto=format\&n=dcD1i9TfmqLehxz2\&q=85\&s=d288976220fd5419904a36a1f348f8f5)

## Test the workflow

Click **Run** in the top right of the canvas and wait for **Compiling agent** to finish. Send a few messages:

1. `What can you do?`
2. `My name is Gil.`
3. `What is my name?`
4. `Say "hello" in French.`

![Voiceflow Run panel where the workflow answers What is my name with Your name is Gil and Say hello in French with Bonjour, each reply following a Called ask\_sambanova\_fn line](https://mintcdn.com/sambanova-systems/dcD1i9TfmqLehxz2/images/docs/integrations/voiceflow/chat-test.png?fit=max\&auto=format\&n=dcD1i9TfmqLehxz2\&q=85\&s=7953d070e22e95b76f6b25c107405a97)

Each reply comes from `MiniMax-M3.1-Flash` on SambaCloud. The third message shows that the history works, and the fourth shows that quotes in a message do not break the request.

> [!NOTE]
>
> `MiniMax-M3.1-Flash` is a reasoning model. In this test the Function step took 4.6 seconds on the first message and 1 to 2 seconds on later ones. A Function step stops at its timeout, which has a maximum of 20 seconds.

## What this integration does not cover

* **The agent and Playbooks keep using Voiceflow's model.** The **Agent** model picker lists only Voiceflow-hosted models. In a test where an agent held a SambaCloud API tool, it called the tool for one message and answered from its own model for the next. For replies that always come from SambaCloud, use a workflow like the one in this guide.
* **Playbooks and the API key.** Voiceflow documents that an agent generates a function's input values when it runs in a Playbook, so `api_key` cannot come from a secret there. This guide did not test the Function tool inside a Playbook.

## Troubleshooting

> [accordion] The Function step fails and the chat repeats the previous answer
>
> When the function throws, the **Message** step prints the last value of `sambanova_answer`. In the **Run** panel, click the line that says the tool failed to read the error, then use the items below.

> [accordion] The reply says the model ran out of room, or ends in the middle of a sentence
>
> `MiniMax-M3.1-Flash` reasons before it answers, and the reasoning counts toward `max_tokens: 1024`. On a long or hard question the reasoning can use the whole budget. The function then returns the "ran out of room" message when no text is left, and a reply cut off mid-sentence when only some text is left. Ask a shorter or simpler question, or add `reasoning_effort: 'low',` on the line after `max_tokens` in the request body to shorten the reasoning. This lowers the chance but does not remove it. Raising `max_tokens` does not help for long, hard questions, because a larger budget can push the step past its 20 second limit.

> [accordion] TypeError: messages.push is not a function
>
> A new variable starts with the value `"0"`, and `JSON.parse("0")` returns the number 0. Keep the `Array.isArray` check from the code above so the function ignores a stored value that is not an array.

> [accordion] Incorrect API key provided
>
> SambaCloud returned a 401. Check that the `sambanova_api_key` secret holds your SambaCloud key without a `Bearer ` prefix, and that you selected it from the **Secrets** tab in the Function step panel. A reference typed by hand, or one placed in an API tool header, is sent as literal text, so the error shows a value like `{samba*****key}`.

> [accordion] The pasted code has a duplicated first line or an extra brace
>
> The editor keeps its own `export default async function main(args) {` line and closing `}`. Select all, delete, and paste only the lines between them.

> [accordion] We could not parse the JSON body of your request
>
> This appears when you call SambaCloud from an API tool with a raw JSON body, because a quote in the user's message breaks the JSON. Use the Function step in this guide, which builds the body with `JSON.stringify`.

> [accordion] Typing on the canvas opens panels or changes tools
>
> Voiceflow's canvas has single-key shortcuts. If you type while no field is focused, for example after a click that did not open an input, letters can open the **Run** panel or select a toolbar tool. Click the field first, and press `Escape` to leave a tool.

## Additional resources

* [Voiceflow Function tool](https://www.voiceflow.com/docs/documentation/build/tools/function-tool)
* [Voiceflow secrets](https://www.voiceflow.com/docs/documentation/build/data/secrets)
* [Supported SambaCloud models](https://docs.sambanova.ai/docs/en/models/sambacloud-models.md)
