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

# Write Session Relationship Context

PATCH https://api.loreos.app/v1/sessions/{session_id}/relationship-context
Content-Type: application/json

Append or replace developer-owned relationship context for one session.

This is a typed writeback layer for product facts such as "founding friend" or
"inner circle". It is deliberately NOT canon/persona mutation: the data is
stored as a session context event, optionally permanent until soft-delete,
and then consumed through the same speakable/private/forbidden lanes as
``POST /context-events``. Use ``relationship_context_key`` +
``write_mode=replace_key`` for durable lifecycle updates.

Reference: https://docs.loreos.app/api-reference/relationship-evidence/write-session-relationship-context

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

### Body (application/json)

This endpoint expects a V1RelationshipContextWritebackRequest.

- `relationship_label` (string, optional, nullable) — Optional app-side label such as founding_friend or inner_circle.
- `relationship_context_key` (string, optional, nullable) — Stable app-owned key for later replacement/deletion, e.g. tier:founding_friend. Required when write_mode=replace_key.
- `write_mode` (enum, optional, default: append) — append keeps existing active context. replace_key soft-deletes active rows with the same relationship_context_key before storing the new row.
  - Allowed values: `append`, `replace_key`
- `speakable_relationship_facts` (list of string, optional) — Relationship facts the character may say if relevant. These are planning-guarded against generic first-meeting contradictions.
- `private_relationship_context` (list of string, optional) — Planning-only relationship context; never spoken directly.
- `forbidden_to_reveal` (list of string, optional) — Hard constraints the reply must not reveal or imply.
- `memory_candidates` (list of string, optional) — Optional relationship memories to propose to the memory pipeline.
- `ttl_seconds` (integer, optional, nullable) — How long this context should shape replies. Default is about 10 minutes.
- `permanent` (boolean, optional, default: false) — If true, remains active until DELETE instead of expiring by TTL.
- `priority` (double, optional, default: 0.6) — Ranking when multiple context events are active.
- `idempotency_key` (string, optional, nullable)

## Response

### 200

Successful Response

- `map from string to any`

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `input` (any, optional)
- `ctx` (ValidationErrorCtx, optional)

### ValidationErrorLocItems

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "relationship_label": "founding_friend",
  "speakable_relationship_facts": [
    "The user is a founding friend."
  ],
  "private_relationship_context": [
    "Treat this as warm trust, not exclusivity."
  ],
  "forbidden_to_reveal": [
    "Do not say they are the only special user."
  ],
  "ttl_seconds": 3600,
  "idempotency_key": "founding-friend:user_123:v1"
}
```

**Response**

```json
{
  "schema_version": "v0",
  "data": {
    "stored_event_ids": [
      "00000000-0000-0000-0000-000000000001"
    ],
    "count": 1,
    "write_semantics": {
      "scope": "session",
      "ttl_seconds": 3600,
      "overwrites_canon": false,
      "overwrites_persona": false,
      "overwrites_relational_scores": false,
      "planning_guarded": true
    }
  },
  "next_actions": [
    {
      "command": "POST /v1/sessions/00000000-0000-0000-0000-000000000000/messages {\"text\": \"...\"}",
      "description": "Send the next user message; active relationship context can shape it"
    }
  ]
}
```

**SDK Code**

```python
import requests

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

payload = {
    "relationship_label": "founding_friend",
    "speakable_relationship_facts": ["The user is a founding friend."],
    "private_relationship_context": ["Treat this as warm trust, not exclusivity."],
    "forbidden_to_reveal": ["Do not say they are the only special user."],
    "ttl_seconds": 3600,
    "idempotency_key": "founding-friend:user_123:v1"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/relationship-context';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"relationship_label":"founding_friend","speakable_relationship_facts":["The user is a founding friend."],"private_relationship_context":["Treat this as warm trust, not exclusivity."],"forbidden_to_reveal":["Do not say they are the only special user."],"ttl_seconds":3600,"idempotency_key":"founding-friend:user_123:v1"}'
};

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/relationship-context"

	payload := strings.NewReader("{\n  \"relationship_label\": \"founding_friend\",\n  \"speakable_relationship_facts\": [\n    \"The user is a founding friend.\"\n  ],\n  \"private_relationship_context\": [\n    \"Treat this as warm trust, not exclusivity.\"\n  ],\n  \"forbidden_to_reveal\": [\n    \"Do not say they are the only special user.\"\n  ],\n  \"ttl_seconds\": 3600,\n  \"idempotency_key\": \"founding-friend:user_123:v1\"\n}")

	req, _ := http.NewRequest("PATCH", 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/relationship-context")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"relationship_label\": \"founding_friend\",\n  \"speakable_relationship_facts\": [\n    \"The user is a founding friend.\"\n  ],\n  \"private_relationship_context\": [\n    \"Treat this as warm trust, not exclusivity.\"\n  ],\n  \"forbidden_to_reveal\": [\n    \"Do not say they are the only special user.\"\n  ],\n  \"ttl_seconds\": 3600,\n  \"idempotency_key\": \"founding-friend:user_123:v1\"\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.patch("https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/relationship-context")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"relationship_label\": \"founding_friend\",\n  \"speakable_relationship_facts\": [\n    \"The user is a founding friend.\"\n  ],\n  \"private_relationship_context\": [\n    \"Treat this as warm trust, not exclusivity.\"\n  ],\n  \"forbidden_to_reveal\": [\n    \"Do not say they are the only special user.\"\n  ],\n  \"ttl_seconds\": 3600,\n  \"idempotency_key\": \"founding-friend:user_123:v1\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://api.loreos.app/v1/sessions/00000000-0000-0000-0000-000000000000/relationship-context', [
  'body' => '{
  "relationship_label": "founding_friend",
  "speakable_relationship_facts": [
    "The user is a founding friend."
  ],
  "private_relationship_context": [
    "Treat this as warm trust, not exclusivity."
  ],
  "forbidden_to_reveal": [
    "Do not say they are the only special user."
  ],
  "ttl_seconds": 3600,
  "idempotency_key": "founding-friend:user_123:v1"
}',
  '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/relationship-context");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"relationship_label\": \"founding_friend\",\n  \"speakable_relationship_facts\": [\n    \"The user is a founding friend.\"\n  ],\n  \"private_relationship_context\": [\n    \"Treat this as warm trust, not exclusivity.\"\n  ],\n  \"forbidden_to_reveal\": [\n    \"Do not say they are the only special user.\"\n  ],\n  \"ttl_seconds\": 3600,\n  \"idempotency_key\": \"founding-friend:user_123:v1\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "relationship_label": "founding_friend",
  "speakable_relationship_facts": ["The user is a founding friend."],
  "private_relationship_context": ["Treat this as warm trust, not exclusivity."],
  "forbidden_to_reveal": ["Do not say they are the only special user."],
  "ttl_seconds": 3600,
  "idempotency_key": "founding-friend:user_123:v1"
] 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/relationship-context")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```