# Chat using Functions — 302.AI

> Enable your 302.AI model to invoke user-defined functions. Useful for conditional logic, workflow orchestration, and tool invocation within conversations. See documentation

- Key: `_302_ai-chat-using-functions`
- Type: Action (Write)
- Version: 0.0.1
- App: 302.AI (`_302_ai`) — https://pipedream.com/apps/302-ai.md
- This page (HTML): https://pipedream.com/apps/302-ai/actions/chat-using-functions
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/_302_ai/actions/chat-using-functions/chat-using-functions.mjs

## Description

Enable your 302.AI model to invoke user-defined functions. Useful for conditional logic, workflow orchestration, and tool invocation within conversations. [See documentation](https://doc.302.ai/211560247e0)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `modelId` | `string` | Yes | The ID of the model to use for chat completions Options are loaded from the connected account. |
| `input` | `string` | Yes | Text input to the model used to generate a response |
| `functions` | `string` | Yes | A valid JSON array of tools/functions using the OpenAI function schema definition. Each tool must have a type property set to "function" and a function object with name, description, and parameters. |
| `instructions` | `string` | No | System instructions for the model |
| `toolChoice` | `string` | No | auto: The model decides whether and how many functions to call. required: The model must call one or more functions. function_name: Enter a custom function name to force the model to call this specific function. |
| `parallelToolCalls` | `string` | No | Allow or prevent the model to call multiple functions in a single turn |
| `maxTokens` | `string` | No | The maximum number of tokens to generate in the completion. |
| `temperature` | `string` | No | What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. |
| `responseFormat` | `string` | No | Text: Returns unstructured text output. JSON Schema: Enables you to define a specific structure for the model's output using a JSON schema. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "_302_ai",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "_302_ai-chat-using-functions",
  arguments: {
    modelId: "Model",
    input: "Chat Input",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "_302_ai-chat-using-functions",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    _302_ai: { authProvisionId: "apn_xxxxxxx" },
    modelId: "Model",
    input: "Chat Input",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "_302_ai-chat-using-functions",
    "configured_props": {
      "_302_ai": { "authProvisionId": "apn_xxxxxxx" },
      "modelId": "Model",
      "input": "Chat Input"
    }
  }'
```

---

- App: https://pipedream.com/apps/302-ai.md · All apps: https://pipedream.com/apps
