## POST /v1/sessions/{id}/messages

Send a follow-up to a session. The response carries the message. It is answered once the session is idle or closed, and its message_ended record says how. Reuse an idempotency key when retrying the same message.

Required permissions: write:sessions.
API key: Supported.
CLI user token: Supported.
Session token: Requires the ellipsis:api scope, and the session's permissions.ellipsis rules must allow the operation. Never the token's own session.
Higher permission levels include lower levels: read < write < delete.
Grant match patterns can further restrict access to individual resources.

### Request

```text
{
  "idempotency_key": str,
  "images": [
    {
      "data": str,
      "media_type": str
    }
  ],
  "message": str
}
```

### Response

```text
{
  "message": {
    "author": str,
    "body": str,
    "created_at": str,
    "id": str,
    "images": [
      {
        "id": str,
        "index": int,
        "media_type": str,
        "size_bytes": int
      }
    ],
    "index": int,
    "session_id": str
  }
}
```

### Python

```python
import os

from ellipsis import Ellipsis

client = Ellipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"])

result = client.sessions.send_message(
    "...",
    "Add a regression test.",
    idempotency_key="add-test",
)
print(result)
```

### TypeScript

```typescript
import { Ellipsis } from '@ellipsis-dev/sdk';

const client = new Ellipsis({
  apiKey: process.env.ELLIPSIS_API_TOKEN!,
});

const request: Parameters<typeof client.sessions.sendMessage>[1] = {
  message: 'Add a regression test.',
  idempotency_key: 'add-test',
};

const result = await client.sessions.sendMessage('...', request);
console.log(result);
```

### cURL

```bash
curl -X POST "https://api.ellipsis.dev/v1/sessions/{id}/messages" \
  -H "Authorization: Bearer $ELLIPSIS_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "message": "Add a regression test.",
  "idempotency_key": "add-test"
}'
```

### Request schema

```json
{
  "properties": {
    "idempotency_key": {
      "anyOf": [
        {
          "maxLength": 128,
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "images": {
      "items": {
        "properties": {
          "data": {
            "type": "string"
          },
          "media_type": {
            "enum": [
              "image/png",
              "image/jpeg",
              "image/gif",
              "image/webp"
            ],
            "type": "string"
          }
        },
        "required": [
          "media_type",
          "data"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "message"
  ],
  "type": "object"
}
```

### Response schema

```json
{
  "properties": {
    "message": {
      "properties": {
        "author": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "body": {
          "type": "string"
        },
        "created_at": {
          "format": "date-time",
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "images": {
          "items": {
            "properties": {
              "id": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "index": {
                "type": "integer"
              },
              "media_type": {
                "type": "string"
              },
              "size_bytes": {
                "type": "integer"
              }
            },
            "required": [
              "index",
              "media_type",
              "size_bytes"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "index": {
          "type": "integer"
        },
        "session_id": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "session_id",
        "index",
        "body",
        "created_at"
      ],
      "type": "object"
    }
  },
  "required": [
    "message"
  ],
  "type": "object"
}
```
