> 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/pipedream.md).

# Pipedream

Pipedream is a developer-focused automation platform that combines no-code workflows with the ability to write custom code in Node.js or Python.

## Prerequisites

* A Pipedream account ([pipedream.com](https://pipedream.com))
* Your TensorX API key from [app.tensorx.ai](https://app.tensorx.ai)

## Configuration

Pipedream offers two methods to connect to TensorX:

1. **Code Step** - Write Node.js or Python code (recommended for flexibility)
2. **HTTP Request Action** - No-code approach

## Method 1: Node.js Code Step (Recommended)

### Step 1: Add a Code Step

1. Create a new workflow or open an existing one
2. Click **+** to add a step
3. Select **Node** → **Run Node.js code**

### Step 2: Write the API Call

```javascript
import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    tensorxApiKey: {
      type: "string",
      label: "TensorX API Key",
      secret: true,
    },
  },
  async run({ steps, $ }) {
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorx.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorxApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "z-ai/glm-5.2",
        messages: [
          {
            role: "system",
            content: "You are a helpful assistant."
          },
          {
            role: "user",
            content: steps.trigger.event.message // Adjust based on your trigger
          }
        ],
        temperature: 0.7,
      },
    });
    
    return {
      content: response.choices[0].message.content,
      model: response.model,
      usage: response.usage,
    };
  },
});
```

### Step 3: Configure the API Key

1. When you run the workflow, Pipedream will prompt for the API key
2. Enter your TensorX API key
3. The key is stored securely and can be reused

## Method 2: Python Code Step

```python
import requests

def handler(pd: "pipedream"):
    api_key = pd.inputs["tensorx_api_key"]
    user_message = pd.steps["trigger"]["event"]["message"]
    
    response = requests.post(
        "https://api.tensorx.ai/v1/chat/completions",
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        },
        json={
            "model": "z-ai/glm-5.2",
            "messages": [
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": user_message}
            ],
            "temperature": 0.7,
        }
    )
    
    data = response.json()
    return {
        "content": data["choices"][0]["message"]["content"],
        "model": data["model"],
        "usage": data["usage"],
    }
```

## Method 3: HTTP Request Action

For a no-code approach:

1. Click **+** → **HTTP / Webhook** → **Send any HTTP Request**
2. Configure:

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

3. Add Headers:
   * `Authorization`: `Bearer YOUR_API_KEY`
   * `Content-Type`: `application/json`
4. Set Body to:

```json
{
  "model": "z-ai/glm-5.2",
  "messages": [
    {"role": "user", "content": "{{steps.trigger.event.message}}"}
  ]
}
```

## Example Workflows

### Slack AI Assistant

Trigger: New Slack message in channel Action: Reply with AI-generated response

```javascript
import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    tensorxApiKey: {
      type: "string",
      label: "TensorX API Key",
      secret: true,
    },
  },
  async run({ steps, $ }) {
    // Get the Slack message
    const userMessage = steps.trigger.event.text;
    
    // Skip if it's a bot message
    if (steps.trigger.event.bot_id) {
      return { skipped: true };
    }
    
    // Call TensorX API
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorx.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorxApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "z-ai/glm-5.2",
        messages: [
          {
            role: "system",
            content: "You are a helpful Slack assistant. Keep responses concise."
          },
          { role: "user", content: userMessage }
        ],
        temperature: 0.7,
      },
    });
    
    return { reply: response.choices[0].message.content };
  },
});
```

### Email Classifier

```javascript
import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    tensorxApiKey: {
      type: "string",
      label: "TensorX API Key",
      secret: true,
    },
  },
  async run({ steps, $ }) {
    const emailSubject = steps.trigger.event.subject;
    const emailBody = steps.trigger.event.body;
    
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorx.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorxApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "z-ai/glm-5.3",
        messages: [
          {
            role: "system",
            content: `Classify this email into one category: sales, support, spam, newsletter, personal. 
                      Return JSON: {"category": "...", "priority": "high|medium|low", "summary": "..."}`
          },
          {
            role: "user",
            content: `Subject: ${emailSubject}\n\nBody: ${emailBody}`
          }
        ],
        temperature: 0.1,
      },
    });
    
    return JSON.parse(response.choices[0].message.content);
  },
});
```

### Content Generator with Streaming

```javascript
import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    tensorxApiKey: {
      type: "string",
      label: "TensorX API Key",
      secret: true,
    },
  },
  async run({ steps, $ }) {
    const topic = steps.trigger.event.topic;
    
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorx.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorxApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "z-ai/glm-5.2",
        messages: [
          {
            role: "system",
            content: "You are a professional content writer."
          },
          {
            role: "user",
            content: `Write a blog post about: ${topic}`
          }
        ],
        temperature: 0.8,
      },
    });
    
    return {
      content: response.choices[0].message.content,
      wordCount: response.choices[0].message.content.split(' ').length,
      tokensUsed: response.usage.total_tokens,
    };
  },
});
```

## 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.

***

## Using Environment Variables

Store your API key securely:

1. Go to **Settings** → **Environment Variables**
2. Add `TENSORX_API_KEY` with your key
3. Access in code: `process.env.TENSORX_API_KEY`

```javascript
const response = await axios($, {
  url: "https://api.tensorx.ai/v1/chat/completions",
  headers: {
    "Authorization": `Bearer ${process.env.TENSORX_API_KEY}`,
  },
  // ...
});
```

## Error Handling

```javascript
try {
  const response = await axios($, {
    method: "POST",
    url: "https://api.tensorx.ai/v1/chat/completions",
    headers: {
      "Authorization": `Bearer ${this.tensorxApiKey}`,
      "Content-Type": "application/json",
    },
    data: {
      model: "z-ai/glm-5.2",
      messages: [{ role: "user", content: "Hello" }],
    },
  });
  return response;
} catch (error) {
  if (error.response?.status === 401) {
    throw new Error("Invalid API key");
  } else if (error.response?.status === 429) {
    throw new Error("Rate limit exceeded");
  }
  throw error;
}
```

## Troubleshooting

### "Unauthorized" Error

* Check that your API key is correct
* Ensure the Authorization header format is `Bearer YOUR_KEY`

### "Model Not Found" Error

* Use the full model ID: `z-ai/glm-5.2`
* Check available models at [tensorx.ai/models](https://tensorx.ai/models)

### Timeout Errors

* Increase the timeout in axios config: `timeout: 60000`
* Use a faster model for time-sensitive workflows

## 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/pipedream.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.
