# 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 Tensorix API key from [app.tensorix.ai](https://app.tensorix.ai)

## Configuration

Pipedream offers two methods to connect to Tensorix:

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: {
    tensorixApiKey: {
      type: "string",
      label: "Tensorix API Key",
      secret: true,
    },
  },
  async run({ steps, $ }) {
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorix.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorixApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "deepseek/deepseek-chat-v3.1",
        messages: [
          {
            role: "system",
            content: "You are a helpful assistant."
          },
          {
            role: "user",
            content: steps.trigger.event.message // Adjust based on your trigger
          }
        ],
        temperature: 0.7,
        max_tokens: 1000,
      },
    });
    
    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 Tensorix 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["tensorix_api_key"]
    user_message = pd.steps["trigger"]["event"]["message"]
    
    response = requests.post(
        "https://api.tensorix.ai/v1/chat/completions",
        headers={
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        },
        json={
            "model": "deepseek/deepseek-chat-v3.1",
            "messages": [
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": user_message}
            ],
            "temperature": 0.7,
            "max_tokens": 1000,
        }
    )
    
    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.tensorix.ai/v1/chat/completions` |

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

```json
{
  "model": "deepseek/deepseek-chat-v3.1",
  "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: {
    tensorixApiKey: {
      type: "string",
      label: "Tensorix 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 Tensorix API
    const response = await axios($, {
      method: "POST",
      url: "https://api.tensorix.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorixApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "deepseek/deepseek-chat-v3.1",
        messages: [
          {
            role: "system",
            content: "You are a helpful Slack assistant. Keep responses concise."
          },
          { role: "user", content: userMessage }
        ],
        temperature: 0.7,
        max_tokens: 500,
      },
    });
    
    return { reply: response.choices[0].message.content };
  },
});
```

### Email Classifier

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

export default defineComponent({
  props: {
    tensorixApiKey: {
      type: "string",
      label: "Tensorix 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.tensorix.ai/v1/chat/completions",
      headers: {
        "Authorization": `Bearer ${this.tensorixApiKey}`,
        "Content-Type": "application/json",
      },
      data: {
        model: "z-ai/glm-5.1",
        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,
        max_tokens: 200,
      },
    });
    
    return JSON.parse(response.choices[0].message.content);
  },
});
```

### Content Generator with Streaming

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

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

## Recommended Models

{% hint style="info" %}
**For Coding Tasks:**

* `z-ai/glm-5.1` - Best for tool calling and structured outputs
* `minimax/minimax-m2.5` - Best for complex reasoning tasks
  {% endhint %}

| Model ID                      | Best For                               |
| ----------------------------- | -------------------------------------- |
| `deepseek/deepseek-chat-v3.1` | General chat, content generation       |
| `z-ai/glm-5.1`                | Classification, structured JSON output |
| `minimax/minimax-m2.5`        | Complex reasoning, analysis            |
| `moonshotai/kimi-k2.5`        | Vision, long context                   |

## Using Environment Variables

Store your API key securely:

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

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

## Error Handling

```javascript
try {
  const response = await axios($, {
    method: "POST",
    url: "https://api.tensorix.ai/v1/chat/completions",
    headers: {
      "Authorization": `Bearer ${this.tensorixApiKey}`,
      "Content-Type": "application/json",
    },
    data: {
      model: "deepseek/deepseek-chat-v3.1",
      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: `deepseek/deepseek-chat-v3.1`
* Check available models at [app.tensorix.ai/models](https://app.tensorix.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@tensorix.ai>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorix.ai/automation-platforms/pipedream.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
