# Send Chat Completion Request — OpenRouter

> Send a chat completion request to a selected model. See the documentation

- Key: `openrouter-send-chat-completion-request`
- Type: Action (Write)
- Version: 0.0.3
- App: OpenRouter (`openrouter`) — https://pipedream.com/apps/openrouter.md
- This page (HTML): https://pipedream.com/apps/openrouter/actions/send-chat-completion-request
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs

## Description

Send a chat completion request to a selected model. [See the documentation](https://openrouter.ai/docs/api-reference/chat-completion)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `model` | `string` | Yes | The model ID to use. Options are loaded from the connected account. |
| `messages` | `string[]` | Yes | A list of objects containing role and content. E.g. {"role":"user", "content":"text"}. See the documentation for further details. |
| `maxTokens` | `integer` | No | Maximum number of tokens. (range: [1, context_length)). |
| `temperature` | `string` | No | Sampling temperature. (range: [0, 2]). |
| `seed` | `integer` | No | Seed for deterministic outputs. |
| `topP` | `string` | No | Top-p sampling value. (range: (0, 1]). |
| `topK` | `integer` | No | Top-k sampling value. (range: [1, Infinity)). |
| `frequencyPenalty` | `string` | No | Frequency penalty. (range: [-2, 2]). |
| `presencePenalty` | `string` | No | Presence penalty. (range: [-2, 2]). |
| `repetitionPenalty` | `string` | No | Repetition penalty. (range: (0, 2]). |
| `logitBias` | `string[]` | No | A list of token IDs to bias values. |
| `togLogprobs` | `integer` | No | Number of top log probabilities to return. |
| `minP` | `string` | No | Minimum probability threshold. (range: [0, 1]). |
| `topA` | `integer` | No | Alternate top sampling parameter. (range: [0, 1]). |
| `transforms` | `string[]` | No | List of prompt transforms (OpenRouter-only). |
| `models` | `string[]` | No | Alternate list of models for routing overrides Options are loaded from the connected account. |
| `sort` | `string` | No | Sort preference (e.g., price, throughput). |
| `effort` | `string` | No | OpenAI-style reasoning effort setting. |
| `reasoningMaxTokens` | `string` | No | Non-OpenAI-style reasoning effort setting. Cannot be used simultaneously with effort. |
| `exclude` | `boolean` | No | Whether to exclude reasoning from the response |

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

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: "openrouter-send-chat-completion-request",
  arguments: {
    model: "Model",
    messages: ["Messages"],
  },
})
```

**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: "openrouter-send-chat-completion-request",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    openrouter: { authProvisionId: "apn_xxxxxxx" },
    model: "Model",
    messages: ["Messages"],
  },
})

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": "openrouter-send-chat-completion-request",
    "configured_props": {
      "openrouter": { "authProvisionId": "apn_xxxxxxx" },
      "model": "Model",
      "messages": ["Messages"]
    }
  }'
```

---

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