# profiles.create_from_context

`POST /api/public/v1/profiles/from-context`

Tạo hồ sơ theo ngữ cảnh danh tính mới đã đo.

- Quyền: `profile.create`
- Lệnh (chống trùng): Có — gửi command_id; gửi lại cùng ID và nội dung để nhận biên nhận đã lưu
- Tool MCP: `profiles_create_from_context`

## Tham số

| Tên | Vị trí | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|---|
| `command_id` | body | string (uuid) | Có | UUID do chương trình khách tạo cho lệnh; gửi lại cùng id và nội dung để nhận biên nhận đã lưu; cùng id nhưng khác nội dung trả CONFLICT |
| `persona_context_id` | body | string (uuid) | Có |  |
| `profile` | body | object | Có |  |

## Phản hồi

201 với { data, replayed: false, correlation_id } lần đầu; 200 với replayed: true khi cùng command_id và nội dung được gửi lại.

| Trường | Kiểu | Luôn có | Mô tả |
|---|---|---|---|
| `data` | object | Có |  |
| `data.profile_id` | string (uuid) | Có |  |
| `data.number` | integer | Có | (tối thiểu -9007199254740991, tối đa 9007199254740991) |
| `data.revision` | integer | Có | (tối thiểu -9007199254740991, tối đa 9007199254740991) |
| `data.changed` | array<string> | Có | Các trường đã thay đổi; rỗng nếu không có thay đổi và giữ nguyên bản sửa đổi |
| `correlation_id` | string (uuid) | Có |  |
| `ok` | true | Không |  |
| `operation_id` | string \| null | Không |  |
| `state_version` | integer | Không | (tối thiểu 0) |
| `retryable` | false | Không |  |
| `next` | null | Không |  |
| `replayed` | boolean | Không | true khi command_id này đã được áp dụng và trả lại biên nhận đã lưu |

Trường mới có thể xuất hiện bất cứ lúc nào; hãy bỏ qua trường bạn không biết.

## Lỗi

| Mã | HTTP | Thử lại |
|---|---|---|
| `UNAUTHENTICATED` | 401 | Không |
| `FORBIDDEN` | 403 | Không |
| `RATE_LIMITED` | 429 | Có |
| `VALIDATION_FAILED` | 422 | Không |
| `CONFLICT` | 409 | Không |
| `OUTCOME_UNKNOWN` | 202 | Có |
| `DEPENDENCY_UNAVAILABLE` | 503 | Có |
| `UNKNOWN` | 500 | Không |

## Ví dụ (curl)

```bash
curl -X POST "https://browlix.com/api/public/v1/profiles/from-context" \
  -H "Authorization: Bearer $BROWLIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command_id":"<uuid>","persona_context_id":"<persona_context_id>","profile":{"name":"Shop 01","config":{"os":"windows"}}}'
```

## Ví dụ (TypeScript SDK)

```ts
import { Browlix } from "@browlix/sdk";

const bx = new Browlix({ apiKey: process.env.BROWLIX_API_KEY! });
const reply = await bx.call("profiles.create_from_context", { body: {"persona_context_id":"<persona_context_id>","profile":{"name":"Shop 01","config":{"os":"windows"}}} });
console.log(reply.data);
```

## Ví dụ (Python)

```python
import os, uuid
import requests

r = requests.post(
    "https://browlix.com/api/public/v1/profiles/from-context",
    headers={"Authorization": f"Bearer {os.environ['BROWLIX_API_KEY']}"},
    json={"command_id":str(uuid.uuid4()),"persona_context_id":"<persona_context_id>","profile":{"name":"Shop 01","config":{"os":"windows"}}},
    timeout=60,
)
print(r.status_code, r.json())
```

## Ví dụ (MCP)

```json
{
  "method": "tools/call",
  "params": {
    "name": "profiles_create_from_context",
    "arguments": {
      "persona_context_id": "<persona_context_id>",
      "profile": {
        "name": "Shop 01",
        "config": {
          "os": "windows"
        }
      }
    }
  }
}
```
