创建会话
创建会话。使用当前 API Key 所属工作区的资源。
先调用「创建智能体」,用返回的智能体 ID 替换示例 ID。
/agent/v1/sessions◐ 部分支持请求体
modelstring可选智能体使用的模型:直接写模型名字符串(如 claude-opus-5),或传对象做附加配置(见子字段)。
agentstring | object必填会话要运行的智能体:直接写智能体 ID 字符串(固定用最新版本),或传对象指定 id 与 version(见子字段)。
▸ 展开子字段(8)
idstring必填会话要运行的智能体 ID。
typestring必填引用类型,目前只有 agent。
versionnumber可选固定使用的智能体版本;省略用最新版本。
mcp_serversarray可选替换本会话的 MCP 服务器列表:传入的数组整体生效;传空数组清除,省略沿用智能体的配置。
modelstring | object可选替换本会话的模型:模型名字符串(如 claude-opus-5)或配置对象;省略沿用智能体自身的模型。
skillsarray可选替换本会话的 Skill 列表;传空数组清除,省略沿用智能体的配置。
systemstring可选替换本会话的系统提示词,最长 100,000 字符;传 null 清除,省略沿用智能体的。
toolsarray可选替换本会话的工具配置;传空数组清除,省略沿用智能体的配置。
environment_idstring可选会话运行所在的环境 ID,决定容器的基础环境。
titlestring可选会话标题,便于在控制台辨认。
metadataobject可选会话的自定义元数据键值对。
budgetobject可选会话的预算上限设置。
▸ 展开子字段(2)
max_list_costobject必填预算内列表类调用的花费上限。
typestring必填预算类型,目前只有 max_list_cost。
initial_eventsarray可选创建时按顺序发给会话的初始事件,支持 user.message 与 user.define_outcome,一次最多 50 条。
resourcesarray可选要挂载进会话容器的资源(如代码仓库、文件)。
vault_idsarray可选保险库 ID 列表:会话里智能体可以使用这些已存凭据。
cwdstring可选Session working directory on any machine. Must be an absolute path within /home/user with no . or .. segments. Repeated and trailing slashes are normalized. Invalid values return 400 invalid_request_error with Invalid cwd.
▸ 更多参数(3)
computer_idstring可选Praxis extension: MA only has session-scoped temporary containers and memory_stores, not durable browsable computers. computer_id selects a tenant-owned active computer. Session selection overrides the agent default; a sandbox environment_id and computer_id cannot be combined.
time_zonestring可选Praxis extension: the session's IANA time zone name (e.g. Asia/Shanghai) — the clock the runtime environment block renders for every turn. Absent means UTC. Only IANA names are accepted; fixed offsets ("+08:00") and unknown names return 400. Never stored in `metadata`.
thinkingobject可选Praxis extension: explicit session thinking effort; null inherits the pinned agent default, then the model default. none disables thinking only when model.thinking.can_disable is true. Unsupported efforts return 400 invalid_request_error.
▸ 展开子字段(1)
effortstring必填Thinking level for this session. The model must support the chosen effort; none requires can_disable. Null on thinking restores inheritance from the agent and model.
返回
200
可在创建时传 model(models.allowed 内的 ID 字符串;无 allowed 时只允许默认模型)与 thinking({effort: "low|medium|high|xhigh|none"} 或 null),在首条 initial_events 执行前保存。省略或 null 继承智能体默认,再使用模型默认。档位必须在 model.thinking.efforts 内;none 要求 can_disable 为 true,否则返回 400 invalid_request_error。响应包含 thinking 与 model.thinking: {efforts, can_disable, default_effort};未知能力为 null,默认档位也可为 null。示例:{"agent":"agent_123","model":"deepseek-v4-flash","thinking":{"effort":"xhigh"}}。这些选择字段只在 /agent/v1 提供。先创建智能体,将示例 agent_123 换成返回的 id。省略 environment_id 得到轻量机器(light),有默认或显式 computer_id 时使用该 Computer;指定 node22 或租户自建 cloud 环境则使用沙箱配方。无配方时响应省略 environment_id。不支持内联智能体覆盖、预算与凭据库。支持 file 类型资源的持久化、查询和解除关联,单会话最多 500 条。文件须属于当前租户且有效。默认路径为 /mnt/session/uploads/<file_id>,自定义路径归一到该目录,拒绝父目录遍历。不修改文件内容;本批尚不将资源同步到沙箱。
错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码
响应
HTTP 201
Successful response
application/json
| 名称 | 类型 | 说明 |
|---|---|---|
| id | string | Session id (sesn_...). Pass it as session_id in every session call. |
| agent | object | Resolved `agent` definition for a `session`. Snapshot of the `agent` at `session` creation time. |
| agent.id | string | Agent id (agent_...). Pass it as agent when creating a session and as agent_id in agent calls. |
| agent.description | null | string | Free-text description of what the agent is for; null when none was set. |
| agent.mcp_servers | array<object> | URL MCP servers the agent can call, paired one-to-one with mcp_toolset entries in tools and saved with the agent version. No credentials are stored here. |
| 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 | Display name of the agent, as set on create or update. It is a label, not a unique key. |
| agent.skills | array<object> | Skills attached to the agent. Setting skills is not supported on this platform and returns 400, so do not send this field on create or update. |
| agent.system | null | string | System prompt given to the model at the start of every session of this agent; null when none was set. |
| agent.tools | array<object> | Tools of the agent: one agent_toolset_20260401 entry for the native tools (all resolved settings are returned, ready to send back on update), plus mcp_toolset entries and custom tool definitions. |
| agent.type | string | Always `agent`. An agent definition. |
| agent.version | number | The agent's current version. Starts at 1 and increments each time the agent is modified. |
| 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 | Always `limit`. A spending limit. |
| created_at | string | A timestamp in RFC 3339 format |
| environment_id | string | Id of the environment recipe the session's sandbox was created from. Omitted when no recipe was selected, that is, for a light machine or the Computer chosen by computer_id. |
| metadata | object | Free-form string key/value pairs stored with the session, changed through sessions.update patch semantics. |
| 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 | Always `outcome_evaluation`. Record of one outcome evaluation. |
| resources | array<object> | Resources attached to the session, at most 500; each is a file reference mounted into the session's machine. |
| resources[].id | string | Resource id, the resource_id of sessions.resources calls. |
| resources[].created_at | string | A timestamp in RFC 3339 format |
| resources[].mount_path | string | null | string | Path inside the machine where the file is mounted; defaults to /mnt/session/uploads/<file_id>, and custom paths are rooted there. / 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 | Always `github_repository`. A GitHub repository resource; not supported on this platform. / Always `file`. A file resource: an uploaded file mounted into the session's machine. / Always `memory_store`. A memory store resource; not supported on this platform. |
| resources[].updated_at | string | A timestamp in RFC 3339 format |
| resources[].url | string | Repository URL. |
| resources[].checkout | null | object | Branch or commit to check out. |
| resources[].file_id | string | Id of the uploaded file; it must exist and belong to your tenant. |
| 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 | Title of the session, set on create or through sessions.update; null when none was set. |
| type | string | Always `session`. A session, one conversation of an agent on a machine. |
| 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 | A monetary amount in a specific currency. |
| 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. |
| cwd | string | Normalized session working directory; defaults to /home/user/workspace. Forks inherit this directory. |
| computer_id | string | Praxis extension: MA only has session-scoped temporary containers and memory_stores, not durable browsable computers. computer_id selects a tenant-owned active computer. Session selection overrides the agent default; a sandbox environment_id and computer_id cannot be combined. Omitted when no computer is selected. |
| model | object | 扩展 / Praxis extension: the currently selected session model. |
| model.id | string | Identifier of the object, as returned by the API; pass it in the path of follow-up calls on the same resource. |
| model.thinking | object | null | Supported thinking controls, or null when capability is unknown or unavailable. efforts lists selectable strengths; can_disable permits none; default_effort is nullable. |
| thinking | object | null | Praxis extension: explicit session thinking effort; null inherits the pinned agent default, then the model default. none disables thinking only when model.thinking.can_disable is true. Unsupported efforts return 400 invalid_request_error. |
| thinking.effort | string | Thinking level saved for this session: low, medium, high, xhigh, or none to turn thinking off. Null or absent means the session inherits the agent default and then the model default. |
| forked_from | object | null | Praxis extension: source of a forked session; null for other sessions. Available only on /agent/v1. |
| forked_from.session_id | string | Id of the parent session this session was forked from; it is left unchanged by the fork. |
| forked_from.message_id | string | message_id of the agent message in the parent session up to which the conversation was copied. |