# Generate Text — Mistral AI

> Generate text using Mistral AI models. See the Documentation

- Key: `mistral_ai-generate-text`
- Type: Action (Write)
- Version: 0.0.2
- App: Mistral AI (`mistral_ai`) — https://pipedream.com/apps/mistral-ai.md
- This page (HTML): https://pipedream.com/apps/mistral-ai/actions/generate-text
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/mistral_ai/actions/generate-text/generate-text.mjs

## Description

Generate text using Mistral AI models. [See the Documentation](https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `message` | `string` | Yes | The prompt message to send |
| `modelId` | `string` | Yes | The identifier of the model to use Options are loaded from the connected account. |
| `temperature` | `string` | No | The sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both. The default value varies depending on the model you are targeting. |
| `topP` | `string` | No | Nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both. |
| `maxTokens` | `integer` | No | The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length. |
| `randomSeed` | `integer` | No | The seed to use for random sampling. If set, different calls will generate deterministic results. |
| `n` | `integer` | No | Number of completions to return for each request, input tokens are only billed once. |

## 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": "mistral_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: "mistral_ai-generate-text",
  arguments: {
    message: "Message",
    modelId: "Model ID",
  },
})
```

**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: "mistral_ai-generate-text",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    mistral_ai: { authProvisionId: "apn_xxxxxxx" },
    message: "Message",
    modelId: "Model ID",
  },
})

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": "mistral_ai-generate-text",
    "configured_props": {
      "mistral_ai": { "authProvisionId": "apn_xxxxxxx" },
      "message": "Message",
      "modelId": "Model ID"
    }
  }'
```

---

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