> 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.

# Start a session

POST https://api.loreos.app/v1/sessions
Content-Type: application/json

Start a native interaction between app-owned characters and an end-user.

The end-user is BYO auth (an opaque ref the developer controls), never an
operator identity. Send one stable ``Idempotency-Key`` per intended session
so a timeout or retry returns the original session instead of creating a
duplicate.

Reference: https://docs.loreos.app/api-reference/sessions/create-session

## 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

### Headers

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

### Body (application/json)

This endpoint expects a V1SessionCreateRequest.

- `character` (string, required) — character slug
- `external_user_ref` (string, required)
- `additional_characters` (list of string, optional, default: []) — Additional app-owned character slugs participating in this interaction.
- `external_user_display_name` (string, optional, nullable)
- `locale` (enum, optional) — End-user input locale for this session. LoreOS validates it against the character's supported_input_languages unless the character was authored with input_language_policy=allow_cross_language.
  - Allowed values: `en-US`, `ja-JP`, `ko-KR`, `zh-CN`, `zh-TW`
- `proactive_enabled` (boolean, optional, nullable)

## Response

### 200

Successful Response

- `schema_version` ("v0", required) — LoreOS success-envelope version.
- `data` (SessionCreateData, 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.

### 403 Forbidden Error

The end-user is blocked from at least one requested character.

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

### 404 Not Found Error

A requested character does not exist in the caller's app.

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

### 409 Conflict Error

Character lifecycle, locale/localization, or Idempotency-Key payload conflict prevents session creation.

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

### 422 Unprocessable Entity Error

Session payload, locale, actor set, or header validation failed.

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

## Types

### SessionCreateData

- `session_id` (string, required)
- `character` (string, required)
- `characters` (list of SessionCharacterActor, required)
- `canonical_character` (string, required, nullable)
- `external_user_ref` (string, required)
- `initial_event_cursor` (integer, required)
- `language_guard` (SessionLanguageGuard, required)
- `actor_scope` (SessionActorScope, required)

### 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)

### SessionCharacterActor

- `character` (string, required)
- `actor_id` (string, required)
- `primary` (boolean, required)

### SessionLanguageGuard

- `requested_locale` (string, required)
- `character_primary_reply_language` (string, required)
- `supported_input_languages` (list of string, required)
- `input_language_policy` (enum, required)
  - Allowed values: `enforce_supported_input`, `allow_cross_language`
- `accepted` (true, required)
- `available_locales` (list of string, required)
- `effective_locale` (string, required)
- `effective_reply_language` (string, required)
- `character_localization_id` (string, required, nullable)
- `localization_source` (string, required)
- `requested_character_slug` (string, required)
- `canonical_character_slug` (string, required)

### SessionActorScope

- `interaction_id` (string, required)
- `external_user_actor_id` (string, required)
- `participant_actor_ids` (list of string, required)
- `requires_explicit_message_scope` (boolean, required)

## Examples

**Request**

```json
{
  "character": "mira-demo",
  "external_user_ref": "user_123"
}
```

**Response**

```json
{
  "schema_version": "v0",
  "data": {
    "session_id": "00000000-0000-0000-0000-000000000000",
    "character": "mira-demo",
    "characters": [
      {
        "character": "mira-demo",
        "actor_id": "11111111-1111-1111-1111-111111111111",
        "primary": true
      }
    ],
    "canonical_character": "mira-demo",
    "external_user_ref": "user_123",
    "initial_event_cursor": 1,
    "language_guard": {
      "requested_locale": "en-US",
      "character_primary_reply_language": "en-US",
      "supported_input_languages": [
        "en-US"
      ],
      "input_language_policy": "enforce_supported_input",
      "accepted": true,
      "available_locales": [
        "en-US"
      ],
      "effective_locale": "en-US",
      "effective_reply_language": "en-US",
      "character_localization_id": null,
      "localization_source": "legacy_default",
      "requested_character_slug": "mira-demo",
      "canonical_character_slug": "mira-demo"
    },
    "actor_scope": {
      "interaction_id": "22222222-2222-2222-2222-222222222222",
      "external_user_actor_id": "33333333-3333-3333-3333-333333333333",
      "participant_actor_ids": [
        "11111111-1111-1111-1111-111111111111",
        "33333333-3333-3333-3333-333333333333"
      ],
      "requires_explicit_message_scope": false
    }
  },
  "next_actions": [
    {
      "command": "POST /v1/sessions/00000000-0000-0000-0000-000000000000/messages {\"text\": \"안녕!\"}",
      "description": "Send the end-user's first message"
    },
    {
      "command": "GET /v1/sessions/00000000-0000-0000-0000-000000000000/events?since=0",
      "description": "Poll the event log for the character's replies"
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.loreos.app/v1/sessions"

payload = {
    "character": "mira-demo",
    "external_user_ref": "user_123"
}
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';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"character":"mira-demo","external_user_ref":"user_123"}'
};

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"

	payload := strings.NewReader("{\n  \"character\": \"mira-demo\",\n  \"external_user_ref\": \"user_123\"\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")

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  \"character\": \"mira-demo\",\n  \"external_user_ref\": \"user_123\"\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")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"character\": \"mira-demo\",\n  \"external_user_ref\": \"user_123\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.loreos.app/v1/sessions', [
  'body' => '{
  "character": "mira-demo",
  "external_user_ref": "user_123"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.loreos.app/v1/sessions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"character\": \"mira-demo\",\n  \"external_user_ref\": \"user_123\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "character": "mira-demo",
  "external_user_ref": "user_123"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.loreos.app/v1/sessions")! 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()
```