> For the complete documentation index, see [llms.txt](https://docs.tensorx.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorx.ai/automation-platforms/activepieces.md).

# Activepieces

Activepieces is an open-source automation platform similar to Zapier, with a visual workflow builder for connecting apps and services.

## Prerequisites

* An Activepieces instance (self-hosted or cloud)
* Your TensorX API key from [app.tensorx.ai](https://app.tensorx.ai)

## Configuration

Since the built-in OpenAI piece uses a hardcoded endpoint, you'll use the **HTTP Request** piece to connect to TensorX's OpenAI-compatible API.

{% hint style="info" %}
The HTTP Request method gives you full control over the API call and works with any OpenAI-compatible endpoint.
{% endhint %}

## Method: HTTP Request Piece

### Step 1: Add HTTP Request Piece

1. Open your Activepieces flow
2. Click **+** to add a new piece
3. Search for **HTTP** and select **HTTP Request (Advanced)**

### Step 2: Configure the Request

Set up the HTTP request with these parameters:

| Field      | Value                                        |
| ---------- | -------------------------------------------- |
| **Method** | `POST`                                       |
| **URL**    | `https://api.tensorx.ai/v1/chat/completions` |

### Step 3: Add Headers

Click **Add Header** and add the following:

| Header          | Value                         |
| --------------- | ----------------------------- |
| `Authorization` | `Bearer YOUR_TENSORX_API_KEY` |
| `Content-Type`  | `application/json`            |

### Step 4: Configure the Body

Set **Body Type** to `Raw (JSON)` and enter:

```json
{
  "model": "z-ai/glm-5.2",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "{{trigger.message}}"
    }
  ],
  "temperature": 0.7
}
```

{% hint style="info" %}
Replace `{{trigger.message}}` with your actual data source from previous pieces in your flow.
{% endhint %}

### Step 5: Parse the Response

The API returns a JSON response. To extract the assistant's message:

1. Add a **Code** piece after the HTTP Request
2. Use JavaScript to parse the response:

```javascript
const response = inputs.httpResponse.body;
return {
  message: response.choices[0].message.content,
  model: response.model,
  tokens: response.usage.total_tokens
};
```

## Example Flows

### Email Summarizer

1. **Trigger**: New Email (Gmail piece)
2. **HTTP Request**: Send email body to TensorX for summarization
3. **Action**: Save summary to Notion or send to Slack

Request body:

```json
{
  "model": "z-ai/glm-5.2",
  "messages": [
    {
      "role": "system",
      "content": "Summarize the following email in 2-3 sentences."
    },
    {
      "role": "user",
      "content": "{{trigger.emailBody}}"
    }
  ],
  "temperature": 0.3
}
```

### Customer Support Classifier

1. **Trigger**: New Support Ticket (webhook or integration)
2. **HTTP Request**: Classify ticket category
3. **Branch**: Route based on category
4. **Action**: Assign to appropriate team

Request body:

```json
{
  "model": "z-ai/glm-5.3",
  "messages": [
    {
      "role": "system",
      "content": "Classify this support ticket into one of: billing, technical, general, urgent. Return only the category name."
    },
    {
      "role": "user",
      "content": "{{trigger.ticketContent}}"
    }
  ],
  "temperature": 0.1
}
```

### Content Generator

1. **Trigger**: New Row in Google Sheets
2. **HTTP Request**: Generate content based on topic
3. **Action**: Update sheet with generated content

Request body:

```json
{
  "model": "z-ai/glm-5.2",
  "messages": [
    {
      "role": "system",
      "content": "Write a short blog post introduction about the given topic."
    },
    {
      "role": "user",
      "content": "Topic: {{trigger.topic}}"
    }
  ],
  "temperature": 0.8
}
```

## Model selection

Call `GET /v1/models` with your TensorX API key and use one of the returned IDs. If the integration depends on a capability or token limit, query `GET /v1/model/info` before selecting the model. See [Models](/api-reference/models.md) for examples.

***

## Handling Streaming Responses

For long responses, you may want to handle streaming:

1. The TensorX API supports streaming with `"stream": true`
2. However, HTTP Request piece may not handle SSE well
3. For streaming, consider using a webhook-based approach or the Code piece with fetch

## Error Handling

### Add Error Handling

1. Click on your HTTP Request piece
2. Enable **Handle Errors**
3. Add a branch to handle failed requests

### Common Errors

| Error | Cause             | Solution                    |
| ----- | ----------------- | --------------------------- |
| 401   | Invalid API key   | Check your API key          |
| 400   | Malformed request | Verify JSON body format     |
| 404   | Wrong endpoint    | Use `/v1/chat/completions`  |
| 429   | Rate limit        | Add delays between requests |

## Creating a Reusable Template

To reuse your TensorX configuration:

1. Create a flow template with the HTTP Request piece configured
2. Use flow variables for dynamic content
3. Duplicate the template for new automations

## Storing API Key Securely

Instead of hardcoding your API key:

1. Go to **Settings** → **Connections**
2. Create a new **Custom Connection**
3. Store your API key securely
4. Reference it in your flows using `{{connections.tensorx.apiKey}}`

## Troubleshooting

### "Request Failed" Error

* Check the URL is exactly `https://api.tensorx.ai/v1/chat/completions`
* Verify headers are correctly formatted
* Test your API key with a simple curl command

### Empty Response

* Check the response body parsing
* Verify the model ID is correct
* Look at the raw response for error messages

### Timeout Errors

* Increase the timeout setting in HTTP Request piece
* Use a faster model for time-sensitive flows
* Consider breaking long operations into smaller chunks

## Support

Need help? Contact us at <support@tensorx.ai>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorx.ai/automation-platforms/activepieces.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
