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

# Open a user-delegated agent DM channel

POST https://cessy.ai/api/rest/tenant-id/app-id/channels/dm
Content-Type: application/json

Creates a fresh human-to-agent DM conversation and channel-linked session for the authenticated user on every successful call; it does not reuse an earlier DM. The agentId must exist in the published app configuration, even when a Workspace runtime source is selected; promote a Workspace-only agent before using it here. The response field created is always true. If content is supplied and createOnly is not true, posts the first message as that user.

Reference: https://docs.cessy.ai/runtime-api-template/channels/open-agent-dm-channel

## Authentication

- `Authorization` header (bearer token, required) — OAuth/JWT bearer with the 'runtime' scope that resolves to a user principal. API keys and agent service tokens are rejected by user-delegated operations.

## Request

### Query parameters

- `workspaceId` (string, optional) — Optional Workspace runtime selector for preview or validation calls. If supplied with X-CES-Workspace-ID, both values must match.

### Headers

- `X-CES-Workspace-ID` (string, optional) — Optional Workspace runtime selector header. If supplied with workspaceId, both values must match.

### Body (application/json)

This endpoint expects an OpenAgentDmChannelRequest.

- `agentId` (string, required)
- `content` (string, optional) — Optional initial user message.
- `createOnly` (boolean, optional, default: false) — When true, open the DM channel without posting content.
- `messageId` (string, optional) — Optional caller-provided idempotency/message id.
- `attachments` (list of map from string to any, optional)
- `pageContext` (map from string to any, optional)
- `agentTurnContext` (AgentTurnContext, optional) — Private, turn-scoped agent orientation for the associated channel message. It is not returned by channel message APIs.
- `agentSessionContext` (AgentTurnContext, optional) — Compatibility alias for agentTurnContext. Send only one of these fields.

## Response

### 201

DM channel created

- `channelId` (string, required)
- `sessionId` (string, required)
- `created` (boolean, required) — Always true because this operation creates a fresh conversation.
- `messageId` (string, optional)

## Errors

### 400 Bad Request Error

Invalid request body

- `error` (string, required)
- `message` (string, optional) — Operator-safe failure text when the endpoint exposes a typed error.
- `details` (any, optional)
- `code` (string, optional) — Stable machine-readable failure category when available.
- `executionId` (string, optional) — Protected execution-log lookup identifier when execution started.
- `correlationId` (string, optional) — Identifier for related requests and diagnostics when available.
- `effectState` (enum, optional) — Authoritative confirmation that the command effect is absent.
  - Allowed values: `rejected`, `rolled_back`

### 401 Unauthorized Error

Missing or invalid user bearer token

- `error` (string, required)
- `message` (string, optional) — Operator-safe failure text when the endpoint exposes a typed error.
- `details` (any, optional)
- `code` (string, optional) — Stable machine-readable failure category when available.
- `executionId` (string, optional) — Protected execution-log lookup identifier when execution started.
- `correlationId` (string, optional) — Identifier for related requests and diagnostics when available.
- `effectState` (enum, optional) — Authoritative confirmation that the command effect is absent.
  - Allowed values: `rejected`, `rolled_back`

### 403 Forbidden Error

The user is not allowed to access this app or agent

- `error` (string, required)
- `message` (string, optional) — Operator-safe failure text when the endpoint exposes a typed error.
- `details` (any, optional)
- `code` (string, optional) — Stable machine-readable failure category when available.
- `executionId` (string, optional) — Protected execution-log lookup identifier when execution started.
- `correlationId` (string, optional) — Identifier for related requests and diagnostics when available.
- `effectState` (enum, optional) — Authoritative confirmation that the command effect is absent.
  - Allowed values: `rejected`, `rolled_back`

### 404 Not Found Error

Agent not found

- `error` (string, required)
- `message` (string, optional) — Operator-safe failure text when the endpoint exposes a typed error.
- `details` (any, optional)
- `code` (string, optional) — Stable machine-readable failure category when available.
- `executionId` (string, optional) — Protected execution-log lookup identifier when execution started.
- `correlationId` (string, optional) — Identifier for related requests and diagnostics when available.
- `effectState` (enum, optional) — Authoritative confirmation that the command effect is absent.
  - Allowed values: `rejected`, `rolled_back`

### 409 Conflict Error

Channel command conflict

- `error` (string, required)
- `message` (string, optional) — Operator-safe failure text when the endpoint exposes a typed error.
- `details` (any, optional)
- `code` (string, optional) — Stable machine-readable failure category when available.
- `executionId` (string, optional) — Protected execution-log lookup identifier when execution started.
- `correlationId` (string, optional) — Identifier for related requests and diagnostics when available.
- `effectState` (enum, optional) — Authoritative confirmation that the command effect is absent.
  - Allowed values: `rejected`, `rolled_back`

## Types

### AgentTurnContext

Private, turn-scoped agent orientation for the associated channel message. It is not returned by channel message APIs.

- `schemaVersion` (string, required) — Versioned context contract understood by the sending BFF and agent.
- `scope` (enum, optional, default: next_message_only) — Turn scope. The context applies only to the associated channel message.
  - Allowed values: `next_message_only`
- `surface` (string, optional) — Product surface that produced the turn, e.g. buddy_rail or main_chat.
- `generatedAt` (datetime, optional) — When the BFF generated this context.
- `focus` (AgentTurnContextFocus, optional) — Focused domain/UI object. Use kind plus ids/status; avoid large bodies.
- `domainPointers` (list of AgentTurnContextDomainPointersItems, optional) — Projection/document ids the agent may read through Runtime MCP if authorized.
- `snapshot` (map from string to any, optional) — Small UI/domain snapshot for orientation only.
- `permissions` (AgentTurnContextPermissions, optional) — Orientation flags only. Runtime authorization and explicit user actions still control writes.
- `extensions` (map from string to any, optional) — Builder-specific compact JSON orientation. Keep keys namespaced and avoid large bodies.

### AgentTurnContextFocus

Focused domain/UI object. Use kind plus ids/status; avoid large bodies.

- `kind` (string, optional)
- `id` (string, optional)
- `title` (string, optional)
- `truthStatus` (enum, optional)
  - Allowed values: `published`, `draft`, `ui_snapshot`, `unknown`
- `mayReferenceAsPublishedTruth` (boolean, optional)

### AgentTurnContextDomainPointersItems

- `projection` (string, required)
- `id` (string, required)
- `purpose` (string, optional)

### AgentTurnContextPermissions

Orientation flags only. Runtime authorization and explicit user actions still control writes.

- `mayWriteDocument` (boolean, optional)
- `mayCreateProposal` (boolean, optional)
- `writeRequiresExplicitUserAction` (boolean, optional)

## Examples

**Request**

```json
{
  "agentId": "agent_support_assistant_01"
}
```

**Response**

```json
{
  "channelId": "ch_7f3a2b1e9d4c8f6a0e5b3d2c1a9f8e7d",
  "sessionId": "sess_4c8f6a0e5b3d2c1a9f8e7d7f3a2b1e9d",
  "created": true,
  "messageId": "msg_1a9f8e7d7f3a2b1e9d4c8f6a0e5b3d2c"
}
```

**SDK Code**

```python
import requests

url = "https://cessy.ai/api/rest/tenant-id/app-id/channels/dm"

payload = { "agentId": "agent_support_assistant_01" }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://cessy.ai/api/rest/tenant-id/app-id/channels/dm';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"agentId":"agent_support_assistant_01"}'
};

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://cessy.ai/api/rest/tenant-id/app-id/channels/dm"

	payload := strings.NewReader("{\n  \"agentId\": \"agent_support_assistant_01\"\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://cessy.ai/api/rest/tenant-id/app-id/channels/dm")

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  \"agentId\": \"agent_support_assistant_01\"\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://cessy.ai/api/rest/tenant-id/app-id/channels/dm")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"agentId\": \"agent_support_assistant_01\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://cessy.ai/api/rest/tenant-id/app-id/channels/dm', [
  'body' => '{
  "agentId": "agent_support_assistant_01"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://cessy.ai/api/rest/tenant-id/app-id/channels/dm");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"agentId\": \"agent_support_assistant_01\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["agentId": "agent_support_assistant_01"] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://cessy.ai/api/rest/tenant-id/app-id/channels/dm")! 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()
```