|
| 1 | +--- |
| 2 | +title: Integrate Generative APIs into n8n workflows |
| 3 | +description: Learn how to integrate Scaleway Generative APIs with open-source workflow automation tool n8n |
| 4 | +tags: generative-apis ai machine-learning n8n workflow automation |
| 5 | +dates: |
| 6 | + validation: 2025-08-06 |
| 7 | + posted: 2025-08-06 |
| 8 | +--- |
| 9 | +import Requirements from '@macros/iam/requirements.mdx' |
| 10 | + |
| 11 | +import scwN8nInterface from './assets/scw-n8n-interface.webp' |
| 12 | +import scwN8nChatmodel from './assets/scw-n8n-chatmodel.webp' |
| 13 | +import scwN8nEmbeddings from './assets/scw-n8n-embeddings.webp' |
| 14 | + |
| 15 | +n8n is an open-source workflow automation tool that allows users to build automated workflows by connecting various AI agents, apps, and services. It provides a visual interface to facilitate the creation of workflows - this document will show you how to use this interface to integrate Scaleway Generative APIs, by: |
| 16 | +- Adding a chat model to a workflow |
| 17 | +- Adding an embedding model to a workflow |
| 18 | + |
| 19 | +<Requirements /> |
| 20 | + |
| 21 | +- A Scaleway account logged into the [console](https://console.scaleway.com) |
| 22 | +- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization |
| 23 | +- A valid [API key](/iam/how-to/create-api-keys/) for API authentication |
| 24 | +- [Installed n8n](https://docs.n8n.io/hosting/installation/docker/) on your local machine |
| 25 | + |
| 26 | +## Adding a chat model |
| 27 | + |
| 28 | +You can add a chat model to a workflow by adding an **AI Agent** node, and configuring it to use Scaleway Generative APIs. Follow the steps below. |
| 29 | + |
| 30 | +1. Open the n8n visual interface on your local machine. |
| 31 | + |
| 32 | + <Lightbox image={scwN8nInterface} alt="The visual interface of n8n displayed in a browser" /> |
| 33 | + |
| 34 | +2. Click `+` > **Workflow** in the top left corner to create a new workflow. |
| 35 | +3. Click **Add first step** to define what will trigger this workflow. |
| 36 | +4. Type **AI agent** in the search bar, and select that option from the search results. |
| 37 | + A form displays prompting you to define parameters and settings for the AI agent. You can come back to this later, if necessary. |
| 38 | +5. Click **Back to canvas** in the top left corner. |
| 39 | + A canvas displays, visually showing the trigger **When chat message received**, connected to the node **AI agent**. |
| 40 | +6. Click **Chat Model +** underneath the AI agent node to define a chat model for the agent. |
| 41 | + A list of language models displays. |
| 42 | +7. Select **OpenAI Chat Model**. |
| 43 | + A form displays prompting you to define parameters and settings for the model. |
| 44 | +8. Under **Credential to connect with**, click **Select Credential** > **Create new credential**. |
| 45 | + A form displays prompting you to enter the credentials. |
| 46 | +9. Fill in the form, to add where prompted: |
| 47 | + - The secret part of your [Scaleway API key](https://console.scaleway.com/iam/api-keys) |
| 48 | + - The URL `https://api.scaleway.ai/v1` as your base URL |
| 49 | + <Message type="tip"> |
| 50 | + If you are using a Project other than your [default Project](/organizations-and-projects/concepts/#default-project), modify the base URL accordingly: `https://api.scaleway.ai/{project_id}/v1` |
| 51 | + </Message> |
| 52 | +10. Click **Save**. |
| 53 | + The credentials are saved, and an automatic connection test is carried out, displaying the message **Connected tested successfully**. This confirms that n8n can access the `/v1/models` and `/v1/chat/completions` endpoints. |
| 54 | +11. Close the credentials screen to go back to the model parameters. |
| 55 | +12. Under **Model**, click your chosen model, e.g. `llama-3.3-70b-instruct`. |
| 56 | +13. Click **Back to canvas** in the top left corner. |
| 57 | + |
| 58 | +<Lightbox image={scwN8nChatmodel} alt="The visual interface of n8n shows the chat model workflow" /> |
| 59 | + |
| 60 | + |
| 61 | +Your AI agent node is now configured to use the model you configured via Scaleway Generative APIs. |
| 62 | + |
| 63 | +### Testing the model |
| 64 | + |
| 65 | +You can test the model by opening a chat from the interface, asking it questions and checking the answers. |
| 66 | + |
| 67 | +1. Click the **Open chat** button at the bottom of the screen. |
| 68 | + The chat interface displays. |
| 69 | +2. Enter your question in the **Chat** box on the left, e.g. `How much is 1 + 1 ?`, and send it. |
| 70 | +3. Check the result that displays in the **Output** box on the right, e.g. `I can calculate that for you. The answer is 2.`. |
| 71 | + |
| 72 | +### Adding tools |
| 73 | + |
| 74 | +You can add **tools** to the AI Agent node you created, to define new capabilities and actions for the agent. A "tool" lets the agent, for example, call another n8n workflow, make an HTTP request, or run pre-defined code. |
| 75 | + |
| 76 | +In the example below, we create and add a code tool to provide weather information. |
| 77 | + |
| 78 | +1. Click **Tool +** underneath the AI agent node to define a new tool for the agent. |
| 79 | + A list of tools displays. |
| 80 | +2. Click **Code Tool**. |
| 81 | + A form displays prompting you to define parameters and settings for the tool. |
| 82 | +3. In the **Description** box, enter `This tool provides the weather in Paris.` |
| 83 | +4. Under **Language**, select **Javascript**. |
| 84 | +5. In the **Javascript** code box, edit the return statement in the sample code as follows: |
| 85 | + ```javascript |
| 86 | + return "Paris is sunny with clear skies, and the temperature is 30 degrees" |
| 87 | + ``` |
| 88 | +6. Click **Back to canvas** in the top left corner. |
| 89 | + |
| 90 | +Now when you [test the model](#testing-the-model) by asking a question such as `What's the weather in Paris?`, you should see via the workflow that the agent calls the code tool, and ultimately returns the answer `Paris is sunny with clear skies, and the temperature is 30 degrees`. |
| 91 | + |
| 92 | +<Message type="tip"> |
| 93 | + |
| 94 | +You can also specify a schema to define the input the tool receives, and modify the code accordingly. For example, edit the tool description with `This tool provides the weather in a city`, and edit the Javascript as follows: |
| 95 | + |
| 96 | + ``` |
| 97 | + let weather = "unknown"; |
| 98 | + if (query.city === "Paris") { |
| 99 | + weather = "sunny"; |
| 100 | + } else if (query.city === "London") { |
| 101 | + weather = "rainy"; |
| 102 | + } |
| 103 | + return weather; |
| 104 | + ``` |
| 105 | + |
| 106 | +Toggle the **Specify Input Schema** setting on, and under **Schema Type** select **Define using JSON Schema**. Add the following input schema: |
| 107 | + |
| 108 | + ```json |
| 109 | + { |
| 110 | + "type": "object", |
| 111 | + "properties": { |
| 112 | + "city": { |
| 113 | + "type": "string", |
| 114 | + "description": "City name" |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + ``` |
| 119 | + |
| 120 | +Now when you ask `What's the weather in London?` you should get the output `rainy.`, and `What's the weather in Tokyo` should generate the response `unknown`. |
| 121 | +</Message> |
| 122 | + |
| 123 | +## Adding an embedding model |
| 124 | + |
| 125 | +You can add an embedding model to a workflow by adding a **Simple Vector Store** node, and configuring it to use Scaleway Generative APIs. Follow the steps below to see how to create a workflow that takes a chat message as an input, and outputs an embedding of the message (list of vectors). |
| 126 | + |
| 127 | +1. Open the n8n visual interface on your local machine. |
| 128 | + |
| 129 | + <Lightbox image={scwN8nInterface} alt="The visual interface of n8n displayed in a browser" /> |
| 130 | + |
| 131 | +2. Click `+` > **Workflow** in the top left corner to create a new workflow. |
| 132 | +3. Click **Add first step** to define what will trigger this workflow. |
| 133 | +3. Select **On chat message** as the trigger, then click **Back to canvas**. |
| 134 | +4. Test the chat by sending a message in the bottom left. The output is a JSON object containing session ID, action and chatInput fields. |
| 135 | +5. Click `+` to the right of your **When chat message received** node to define what happens next. |
| 136 | +6. Type **Simple Vector Store** in the search bar, and select that option from the search results. |
| 137 | +7. From the **Actions** sub-menu that displays, click **Add documents to vector store**. |
| 138 | + A form displays prompting you to define parameters and settings. |
| 139 | +8. Click **+** under **Embeddings** at the bottom of the form to add an embedding. |
| 140 | + A list of embeddings nodes displays. |
| 141 | +9. Click **Embeddings OpenAPI**. |
| 142 | + A form displays prompting you to define parameters and settings. |
| 143 | +10. Under **Credential to connect with**, select existing credentials and skip to step 15, or click **Select Credential** > **Create new credential**. |
| 144 | + A form displays prompting you to enter the credentials. |
| 145 | +11. Fill in the form, to add where prompted: |
| 146 | + - The secret part of your [Scaleway API key](https://console.scaleway.com/iam/api-keys) |
| 147 | + - The URL `https://api.scaleway.ai/v1` as your base URL |
| 148 | + <Message type="tip"> |
| 149 | + If you are using a Project other than your [default Project](/organizations-and-projects/concepts/#default-project), modify the base URL accordingly: `https://api.scaleway.ai/{project_id}/v1` |
| 150 | + </Message> |
| 151 | +12. Click **Save**. |
| 152 | + The credentials are saved, and an automatic connection test is carried out, displaying the message **Connected tested successfully**. This confirms that n8n can access the `/v1/models` and `/v1/chat/completions` endpoints. |
| 153 | +13. Close the credentials screen to go back to the **Parameters** tab. |
| 154 | +14. Under **Model**, click your chosen model, e.g. `bge-multilingual-gemma2` (other listed models are not supported by Scaleway Generative APIs at the time of writing). |
| 155 | + <Message type="note"> |
| 156 | + For n8n versions earlier than `1.104.1`, a [known issue](https://github.com/n8n-io/n8n/issues/16716) prevents the model list from displaying. If you cannot upgrade your n8n version, you can still Select **Expression** instead of **Fixed** and type the model name. |
| 157 | + </Message> |
| 158 | +15. Click **Back to canvas** in the top left corner. |
| 159 | +16. Click **Document +** underneath the Simple Vector Store node. |
| 160 | + A list of document loaders displays. |
| 161 | +17. Click **Default Data Loader**. |
| 162 | + A form displays prompting you to define parameters and settings for the data loader. |
| 163 | +18. Under **Mode**, select ** Load Specific Data**. |
| 164 | +17. Drag and drop the **chatInput** field from the **Input** panel on the left into the **Data** field of the main form. Alternatively type `{{ $('When chat message received').item.json.chatInput }}` into the **Data** field. |
| 165 | +18. Click **Back to canvas** |
| 166 | + |
| 167 | +<Lightbox image={scwN8nEmbeddings} alt="The visual interface of n8n shows the embeddings workflow" /> |
| 168 | + |
| 169 | + |
| 170 | +### Testing the workflow |
| 171 | + |
| 172 | +You can test the workflow by opening a chat from the interface, sending it a message, and checking that the output is an embedding (list of vectors). |
| 173 | + |
| 174 | +1. Click the **Open chat** button at the bottom of the screen. |
| 175 | + The chat interface displays. |
| 176 | +2. Enter your chat input in the **Chat** box on the left, e.g. `This is a message to embed`, and send it. |
| 177 | +3. In the middle **Logs** panel, click **Simple Vector Store** > **Embeddings OpenAI**. |
| 178 | +5. Check that the input shows your chat message, and the output is an embedding (list of vectors). |
| 179 | + |
| 180 | +### Going further |
| 181 | + |
| 182 | +You now know how to add a simple embedding model to your n8n workflows. To go further, you can: |
| 183 | + |
| 184 | +- Replace the **Simple Vector Store** node with a persistent storage node, such as **Postgres PGVector Store** or **Qdrant Vector Store**. |
| 185 | +- Implement a RAG pipeline using Vector retrieval components, such as **AI Agent** and **Query Data Tool** (using for instance [RAG Starter Template](https://n8n.io/workflows/5010-rag-starter-template-using-simple-vector-stores-form-trigger-and-openai/)). |
0 commit comments