# Compose a reply

> **POST** `https://api.us.nylas.com/v3/grants/{grant_id}/messages/{message_id}/smart-compose`

Source: https://developer.nylas.com/docs/reference/api/smart-compose/post-smart-compose-reply/

Generates a reply to the specified message based on a prompt.

**Authentication:** NYLAS_API_KEY, ACCESS_TOKEN

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `grant_id` | string | Yes | ID of the grant to access. Use `/me/` to refer to the grant associated with an access token. |
| `message_id` | string | Yes | ID of the message to access. Nylas recommends you URL-encode this field, or you might receive a [`404` error](/docs/api/errors/400-response/) if the ID contains special characters (for example, `#`). |

## Request body

Content-Type: application/json

- `prompt` (string) - The prompt that Smart Compose uses to generate a message suggestion.

## Responses

### 200 - Returns a suggestion for a message

- `request_id` (string) - The request ID.
- `data` (object)
  - `suggestion` (string) **(required)**

- `suggestion` (string)

### 400 - Bad Request

- `request_id` (string) - ID of the request
- `error` (object) - Response error object.
  - `type` (string) - Error Type
  - `message` (string) - Error Message

### 401 - Unauthorized

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 422 - Validation Error

- `request_id` (string) - ID of the request
- `error` (object) - Response error object.
  - `type` (string) - Error Type
  - `message` (string) - Error Message
  - `details` (array)
    - `loc` (array)
    - `msg` (string)
    - `type` (string)

### 500 - Unexpected Error

- `request_id` (string) - ID of the request
- `error` (object) - Response error object.
  - `type` (string) - Error Type
  - `message` (string) - Error Message

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.us.nylas.com/v3/grants/<NYLAS_GRANT_ID>/messages/<MESSAGE_ID>/smart-compose' \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <NYLAS_API_KEY>' \
  --header 'Content-Type: application/json'
```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function composeEmailReply() {
  try {
    const message = await nylas.messages.smartCompose.composeMessageReply({
      identifier: "<NYLAS_GRANT_ID>",
      messageId: "<MESSAGE_ID>",
      requestBody: {
        prompt: "Respond to the email",
      },
    });

    console.log("Message created:", message);
  } catch (error) {
    console.error("Error creating message:", error);
  }
}

composeEmailReply();

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>"
)

grant_id = "<NYLAS_GRANT_ID>"
message_id = "<MESSAGE_ID>"

message = nylas.messages.smart_compose.compose_message_reply(
  grant_id,
  message_id,
  request_body={
    "prompt": "Respond to the email",
  }
)

print(message)

```

### Ruby SDK

```ruby
require 'nylas'

nylas = Nylas::Client.new(
  api_key: "<NYLAS_API_KEY>"
)

request_body = {
  prompt: 'reply'
}

message, _ = nylas.messages.smart_compose.compose_message_reply(
  identifier: "<NYLAS_GRANT_ID>",
  message_id: "<MESSAGE_ID>",
  request_body: request_body
)

puts message[:suggestion]

```

### Java SDK

```java
import com.nylas.NylasClient;
import com.nylas.models.*;

public class SmartCompose {
    public static void main(String[] args) throws
            NylasSdkTimeoutError, NylasApiError {

        NylasClient nylas = new NylasClient.Builder("<NYLAS_API_KEY>").build();

        ComposeMessageRequest requestBody = new ComposeMessageRequest("Reply");

        Response<ComposeMessageResponse> message = 
        nylas.messages().smartCompose().composeMessageReply("<NYLAS_GRANT_ID>", 
        "<MESSAGE_ID>", requestBody);
        System.out.println(message.getData().getSuggestion());
    }
}

```

### Kotlin SDK

```kotlin
import com.nylas.NylasClient
import com.nylas.models.ComposeMessageRequest

fun main(args: Array<String>) {

    val nylas: NylasClient = NylasClient(
        apiKey = "<NYLAS_API_KEY>"
    )

    val requestBody : ComposeMessageRequest = 
    ComposeMessageRequest("Reply")
    val message = nylas.messages().smartCompose().composeMessageReply("<NYLAS_GRANT_ID>", 
    "<MESSAGE_ID>", requestBody)
    print(message.data.suggestion)

}

```
