创建会话
先调用「创建智能体」,用返回的智能体 ID 替换示例 ID。
/anthropic/v1/sessions◐ 部分支持请求体
agentstring | object必填会话要运行的智能体:智能体 ID 字符串,或对象 {type:"agent", id, version?}。只写 ID、或对象不带 version,都固定为创建会话时的 active_version(agents.versions.apply 选定的版本,不一定是最新保存的);带 version 则固定该版本。与 Managed Agents 不同,内联覆盖只支持系统提示词(type 为 agent_with_overrides);要改模型、工具、MCP 服务器或技能,请先保存新版本。
展开子字段 (8)
idstring必填会话要运行的智能体 ID。
typestring必填引用类型:agent,或携带内联覆盖的 agent_with_overrides。
versionnumber可选固定使用的智能体版本;省略取创建会话时的 active_version(不一定是最新保存版本)。
mcp_serversarray可选○ 未支持不支持内联 mcp_servers 覆盖,传入返回 400;请先更新智能体版本。
modelstring | object可选○ 未支持不支持内联 model 覆盖,传入返回 400;请先更新智能体版本。
skillsarray可选○ 未支持不支持内联 skills 覆盖,传入返回 400;请先更新智能体版本。
systemstring可选替换本会话的系统提示词,最长 100,000 字符;传 null 清除,省略沿用智能体的。
toolsarray可选○ 未支持不支持内联 tools 覆盖,传入返回 400;请先更新智能体版本。
environment_idstring必填会话运行所在的环境 ID,决定容器的基础环境。
budgetobject可选○ 未支持会话的预算上限设置。
展开子字段 (2)
max_list_costobject必填会话可达到的列表价费用上限:{amount, currency:"USD"},amount 以美元为单位,传整数或最多 2 位小数(如 "0.50"),响应固定 2 位小数(如 "20.00")。
typestring必填预算类型,恒为 limit;传 max_list_cost 等其他值返回 400。
initial_eventsarray可选创建时按顺序发给会话的初始事件,支持 user.message 与 user.define_outcome,一次最多 50 条。
metadataobject可选会话的自定义元数据键值对。
resourcesarray可选◐ 部分支持要挂载进会话容器的资源(如代码仓库、文件)。
titlestring可选会话标题,便于在控制台辨认。
vault_idsarray可选◐ 部分支持保险库 ID 列表:会话里智能体可以使用这些已存凭据。
返回
200
先创建智能体,将示例 agent_123 换成返回的 id。Anthropic 兼容 API 的 environment_id 必填,可用 node22 或租户自建 cloud 环境;/agent/v1 可省略 environment_id 得到轻量机器。内联智能体覆盖只支持 system;预算不支持。 支持 file 类型资源的持久化、查询和解除关联,单会话最多 500 条。文件须属于当前租户且有效。默认路径为 /mnt/session/uploads/<file_id>,自定义路径归一到该目录,拒绝父目录遍历。不修改文件内容;本批尚不将资源同步到沙箱。 支持 vault_ids,最多 50 个,必须属于本组织且未归档;Secret 以环境变量交给会话的电脑,并按 MCP 服务器地址匹配凭据。
错误按 Claude Managed Agents 格式返回,参见 错误码
请求示例
curl
# 先调用「创建智能体」,用返回的智能体 ID 替换示例 ID。
curl https://api.deepraxis.com/anthropic/v1/sessions \
-H "x-api-key: $PRAXIS_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: managed-agents-2026-04-01" \
-H "Content-Type: application/json" \
-d '{"agent":"agent_123","environment_id":"node22","title":"文档测试"}'Python
# 先调用「创建智能体」,用返回的智能体 ID 替换示例 ID。
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.deepraxis.com/anthropic",
api_key="$PRAXIS_API_KEY",
)
result = client.beta.sessions.create(agent="agent_123", environment_id="node22", title="文档测试")
print(result)TypeScript
// 先调用「创建智能体」,用返回的智能体 ID 替换示例 ID。
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://api.deepraxis.com/anthropic",
apiKey: "$PRAXIS_API_KEY",
});
const result = await client.beta.sessions.create({
"agent": "agent_123",
"environment_id": "node22",
"title": "文档测试"
});
console.log(result);响应示例 200
{
"id": "sesn_d72b90b27a414fe5885adff0ac6b9b96",
"type": "session",
"agent": {
"id": "agent_57d15145-7ef6-4bd3-8b33-2b8ddca88ac0",
"type": "agent",
"name": "文档助手(已更新)",
"description": null,
"system": "用一句话简短回答。",
"model": {
"id": "deepseek-flash"
},
"version": 2,
"tools": [],
"skills": [],
"mcp_servers": [],
"multiagent": null
},
"environment_id": "env_deepraxis_text_v1",
"title": "文档测试",
"metadata": {},
"created_at": "2026-09-26T07:16:14.796Z",
"updated_at": "2026-09-26T07:16:17.024Z",
"archived_at": null,
"status": "idle",
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"cache_read_input_tokens": 0,
"list_cost": null
},
"stats": {},
"budget": null,
"resources": [],
"vault_ids": [],
"outcome_evaluations": [],
"deployment_id": null
}响应
HTTP 200
Successful response
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| id | string | |
| agent | object | Resolved agent definition for a session. Snapshot of the agent at session creation time. |
| agent.id | string | |
| agent.description | null | string | |
| agent.mcp_servers | array<object> | |
| agent.model | object | Model identifier and configuration. |
| agent.multiagent | null | object | Resolved coordinator topology with full agent definitions for each roster member. |
| agent.name | string | |
| agent.skills | array<object> | |
| agent.system | null | string | |
| agent.tools | array<object> | |
| agent.type | string | |
| agent.version | number | |
| archived_at | null | string | A timestamp in RFC 3339 format |
| budget | null | object | A hard spend ceiling. The session stops issuing new model requests once the tracked list cost reaches max_list_cost. |
| budget.max_list_cost | object | A monetary amount in a specific currency. |
| budget.type | string | |
| created_at | string | A timestamp in RFC 3339 format |
| environment_id | string | |
| metadata | object | |
| outcome_evaluations | array<object> | Per-outcome evaluation state. One entry per define_outcome event sent to the session. |
| outcome_evaluations[].completed_at | null | string | A timestamp in RFC 3339 format |
| outcome_evaluations[].description | string | What the agent should produce. |
| outcome_evaluations[].explanation | null | string | Grader's verdict text from the most recent evaluation. For satisfied, explains why criteria are met; for needs_revision (intermediate), what's missing; for failed, why unrecoverable. |
| outcome_evaluations[].iteration | number | 0-indexed revision cycle the outcome is currently on. |
| outcome_evaluations[].outcome_id | string | Server-generated outc_ ID for this outcome. |
| outcome_evaluations[].result | string | Current evaluation state. pending before the agent begins work; running while producing or revising; evaluating while the grader scores; satisfied/max_iterations_reached/failed/interrupted are terminal. |
| outcome_evaluations[].type | string | |
| resources | array<object> | |
| resources[].id | string | |
| resources[].created_at | string | A timestamp in RFC 3339 format |
| resources[].mount_path | string | null | string | Filesystem path where the store is mounted in the session container, e.g. /mnt/memory/user-preferences. Derived from the store's name. Output-only. |
| resources[].type | string | |
| resources[].updated_at | string | A timestamp in RFC 3339 format |
| resources[].url | string | |
| resources[].checkout | null | object | |
| resources[].file_id | string | |
| resources[].memory_store_id | string | The memory store ID (memstore_...). Must belong to the caller's organization and workspace. |
| resources[].access | null | string | Access mode for an attached memory store. |
| resources[].description | string | Description of the memory store, snapshotted at attach time. Rendered into the agent's system prompt. Empty string when the store has no description. |
| resources[].instructions | null | string | Per-attachment guidance for the agent on how to use this store. Rendered into the memory section of the system prompt. Max 4096 chars. |
| resources[].name | null | string | Display name of the memory store, snapshotted at attach time. Later edits to the store's name do not propagate to this resource. |
| stats | object | Timing statistics for a session. |
| stats.active_seconds | number | Cumulative time in seconds the session spent in running status. Excludes idle time. |
| stats.duration_seconds | number | Elapsed time since session creation in seconds. For terminated sessions, frozen at the final update. |
| status | string | SessionStatus enum - rescheduling - Transient error occurred, retrying automatically. - running - Agent is actively executing. - idle - Agent is waiting for input, including user messages or tool confirmations. Sessions start in idle. - terminated - Session has ended, either due to an error or completion. |
| title | null | string | |
| type | string | |
| updated_at | string | A timestamp in RFC 3339 format |
| usage | object | Cumulative token usage for a session across all turns. |
| usage.active_seconds | number | Cumulative time in seconds during which the session had at least one thread in running status. Overlapping activity from concurrent threads is counted once, unlike stats.active_seconds, which sums each thread's own active time. This is the duration the session's runtime cost is priced on. |
| usage.cache_creation | object | Prompt-cache creation token usage broken down by cache lifetime. |
| usage.cache_read_input_tokens | number | Total tokens read from prompt cache. |
| usage.input_tokens | number | Total input tokens consumed across all turns. |
| usage.list_cost | null | object | Session total list-price cost as an integer string in US cents. Includes model cost and all charged products attributed to this session. The budget reads the same total; in-flight work may finish after the limit is reached. |
| usage.output_tokens | number | Total output tokens generated across all turns. |
| usage.server_tool_use | null | object | Cumulative count of server-executed tool invocations, broken down by tool. |
| vault_ids | array<string> | Vault IDs attached to the session at creation. Empty when no vaults were supplied. |
| deployment_id | null | string | Deployment ID when the session was created from a deployment reference. Null otherwise. |