> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.loreos.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.loreos.app/_mcp/server.

# Send a message

POST https://api.loreos.app/v1/sessions/{session_id}/messages
Content-Type: application/json

Deliver an end-user message; the character's reply arrives async on the
event log. Returns immediately with the user-message cursor — poll
`GET .../events?since=<cursor>` for the reply (delayed-exposure UX).

Send `Idempotency-Key: <unique-per-message>` to make retries safe (common on
serverless/Vercel): a same-key re-call returns the original cursor + turn index
(`idempotent_replay: true`) instead of creating a duplicate turn/reply.

Reference: https://docs.loreos.app/api-reference/sessions/send-message

## Authentication

- `Authorization` header (bearer token, required) — LoreOS runtime API key (`ck_...`), sent as `Authorization: Bearer <key>`.

## Servers

- `https://api.loreos.app` (Production, default)
- `http://127.0.0.1:8000` (Local development)

## Request

### Path parameters

- `session_id` (string, required)

### Headers

- `Idempotency-Key` (string, optional, nullable)

### Body (application/json)

This endpoint expects a V1SendMessageRequest.

- `text` (string, required)
- `reply_mode` (enum, optional, nullable)
  - Allowed values: `fast`, `deep`
- `context_events` (list of V1ContextEvent, optional, nullable)
- `active_addressee_actor_ids` (list of string, optional, nullable)
- `audience_actor_ids` (list of string, optional, nullable)

## Response

### 200

Successful Response

- `schema_version` ("v0", required) — LoreOS success-envelope version.
- `data` (MessageAcceptedData, required)
- `next_actions` (list of V1NextAction, required) — Concrete follow-up API actions; empty when no action is required.

## Errors

### 401 Unauthorized Error

Runtime API key is missing, invalid, expired, or revoked.

- `detail` (V1ErrorDetail, required) — Stable public error core; domain-specific fields may be added alongside it.

### 402 Payment Required Error

The app's prepaid balance or configured budget cap is exhausted.

- `detail` (V1ErrorDetail, required) — Stable public error core; domain-specific fields may be added alongside it.

### 404 Not Found Error

Session not found in the caller's app.

- `detail` (V1ErrorDetail, required) — Stable public error core; domain-specific fields may be added alongside it.

### 409 Conflict Error

Session lifecycle, actor scope, or Idempotency-Key payload conflicts with this message.

- `detail` (V1ErrorDetail, required) — Stable public error core; domain-specific fields may be added alongside it.

### 422 Unprocessable Entity Error

Message, context-event, actor-scope, or header validation failed.

- `detail` (V1ErrorDetail, required) — Stable public error core; domain-specific fields may be added alongside it.

## Types

### V1ContextEvent

One typed, visibility-scoped context push for a session.

- `source` (string, optional, nullable) — Free provenance label.
- `speakable_facts` (list of string, optional) — Facts the character MAY say.
- `private_facts` (list of string, optional) — Shape the reply; never spoken.
- `forbidden_to_reveal` (list of string, optional) — Must NOT surface, even if asked.
- `memory_candidates` (list of string, optional) — Proposed to the persistent world model (the engine's critics decide).
- `ttl_seconds` (integer, optional, nullable) — Active window; default ~10 min.
- `permanent` (boolean, optional, default: false) — If true, active until explicitly deleted instead of TTL expiry.
- `priority` (double, optional, default: 0.5) — Ranking when context is abundant.
- `idempotency_key` (string, optional, nullable)
- `relationship_context_key` (string, optional, nullable)

### MessageAcceptedData

- `accepted` (true, required)
- `cursor` (integer, required)
- `sent_turn_index` (integer, required)
- `idempotent_replay` (boolean, optional, nullable)
- `run_ref` (string, optional, nullable)
- `reply_mode` (enum, optional, nullable)
  - Allowed values: `fast`, `deep`

### V1NextAction

- `command` (string, required) — The next API command an agent can execute.
- `description` (string, required) — Why or when to execute the command.

### V1ErrorDetail

Stable public error core; domain-specific fields may be added alongside it.

- `code` (string, required)
- `message` (string, required)
- `fix` (string, required)

## Examples

**Request**

```json
{
  "text": "Give me one short line proving this chat works."
}
```

**Response**

```json
{
  "schema_version": "v0",
  "data": {
    "accepted": true,
    "cursor": 2,
    "sent_turn_index": 1,
    "run_ref": "trace_0000000000000000",
    "reply_mode": "fast"
  },
  "next_actions": [
    {
      "command": "GET /v1/sessions/00000000-0000-0000-0000-000000000000/events?since=2",
      "description": "Poll for the character's reply"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages"

payload = { "text": "Give me one short line proving this chat works." }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"text":"Give me one short line proving this chat works."}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages"

	payload := strings.NewReader("{\n  \"text\": \"Give me one short line proving this chat works.\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"text\": \"Give me one short line proving this chat works.\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"text\": \"Give me one short line proving this chat works.\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages', [
  'body' => '{
  "text": "Give me one short line proving this chat works."
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"text\": \"Give me one short line proving this chat works.\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["text": "Give me one short line proving this chat works."] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/messages")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```