# Chat — Anthropic (Claude)

> The Chat API. See the documentation

- Key: `anthropic-chat`
- Type: Action (Write)
- Version: 0.2.2
- App: Anthropic (Claude) (`anthropic`) — https://pipedream.com/apps/anthropic.md
- This page (HTML): https://pipedream.com/apps/anthropic/actions/chat
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/anthropic/actions/chat/chat.mjs

## Description

The Chat API. [See the documentation](https://docs.anthropic.com/claude/reference/messages_post)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `model` | `string` | Yes | Select the model to use. See the documentation for more information Options are loaded from the connected account. |
| `userMessage` | `string` | Yes | The user messages provide instructions to the assistant |
| `messages` | `string[]` | No | All relevant information must be supplied via the conversation. You can provide an array of messages from prior conversations here always beginning with the human message. |
| `temperature` | `string` | No | Optional. Amount of randomness injected into the response. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and temp closer to 1 for creative and generative tasks. |
| `topK` | `integer` | No | Only sample from the top K options for each subsequent token. Used to remove long tail low probability responses. |
| `topP` | `string` | No | Does nucleus sampling, in which we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified. |
| `maxTokensToSample` | `integer` | Yes | A maximum number of tokens to generate before stopping. |

## 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": "anthropic",
      },
    },
  },
)

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: "anthropic-chat",
  arguments: {
    model: "Model",
    userMessage: "User Message",
  },
})
```

**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: "anthropic-chat",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    anthropic: { authProvisionId: "apn_xxxxxxx" },
    model: "Model",
    userMessage: "User Message",
  },
})

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": "anthropic-chat",
    "configured_props": {
      "anthropic": { "authProvisionId": "apn_xxxxxxx" },
      "model": "Model",
      "userMessage": "User Message"
    }
  }'
```

---

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