Update session

Updated at:

Update session metadata, model, reasoning effort, and service tier; changes apply to later turns only.

Endpoint

Returns 200 and the complete updated Session. Only metadata, agent.model, and agent.reasoning.effort can be updated.

Updates affect later turns only. They do not change a running turn or write back to the saved agent. Concurrent update conflicts return 409 conflict_error; retrieve the latest state and retry.

POST/agents/sessions/{session_id}

Path parameters

session_idstringRequired

Session ID, format sesn_<ULID>

Request body

metadataobject / nullOptional

Metadata, replaced as a whole, omitted keeps the current value, null or {} clears. Up to 16 items, key non-empty and up to 64 characters, value a string up to 512 characters

agentobjectOptional

Session-level settings, omitted keeps the current value, null is rejected, {} is valid but changes nothing. Unknown fields are rejected

Properties

modelstringOptional

Model for later turns, omitted keeps the current value, null or all whitespace is rejected. The update endpoint allows up to 1,048,576 characters, and a model change must use a model available in the current workspace

reasoningobjectOptional

Can contain only effort, not summary, omitted keeps the current value, null is rejected

Properties

effortstring / nullOptional

Reasoning effort, none, minimal, low, medium, high, xhigh, max, or ultra; null resets to the model default

At least one of metadata and agent must be present. An empty request body, JSON null, or a request body of {} returns 400.

agent: {} is valid by itself but does not change any setting. Update validates the settings before reading and merging the resource; if the settings are invalid and the resource does not exist at the same time, the API can return 400 first.

Request example

curl -sS -X POST "$BASE_URL/agents/sessions/sess_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "OpenAI-Beta: agents=v1" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {"source": "updated"},
    "agent": {
      "model": "qwen3.8-max",
      "reasoning": {"effort": "medium"}
    }
  }'
session = client.beta.agents.sessions.update(
    "sess_xxx",
    metadata={"source": "updated"},
    agent={
        "model": "qwen3.8-max",
        "reasoning": {"effort": "medium"},
    },
)
print(session.status)

Response fields

Returns the complete updated session object. null when the fields are incomplete.

idstring

Session ID; reuse it for follow-up turns

objectstring

Session object type, fixed as agent.session

created_atinteger

Creation time in Unix seconds

last_active_atinteger

Last activity time in Unix seconds; not a version number or lock

statusstring

Session status: idle, in_progress, requires_action, or failed

agentobject

Effective agent snapshot.

Properties

idstring

Agent ID; inline configurations return a session snapshot ID, not a reusable saved agent, and it cannot be retrieved through Agent GET

modelstring

Model ID

instructionsstring / null

Custom instructions

namestring / null

Display name

reasoningobject / null

Reasoning configuration, contains effort and summary

textobject / null

Text output configuration; contains format and verbosity

toolsarray

Tool configuration

multi_agentobject / null

Subagent configuration; contains enabled and max_concurrent_subagents

environmentobject

Safe environment summary; only type for none.

Properties

typestring

Environment type; none or openai_hosted

idstring

Environment ID, omitted when there is no authoritative value

statusstring

Environment status: omitted when there is no authoritative value

environment_template_idstring

Environment template ID, omitted when there is no authoritative value

workspace_directorystring

Workspace directory, omitted when there is no authoritative value

errorstring / null

Environment error description, omitted when there is no authoritative value

desktopobject / null

Desktop settings; contains enabled

capability_directoriesarray<string> / null

Capability discovery directories

networkobject / null

Network policy; contains access and allowed_domains

packagesobject / null

Package lists; contains npm, python, and system

filesarray

Safe environment file metadata

skillsarray

Safe skill metadata

pluginsarray

Plugin information; [] for managed environments

metadataobject

Session metadata; an empty value is {}

vault_idsarray<string>

Vault IDs recorded at creation; this does not mean mounting is complete

required_actionsarray

Function calls that need client handling; [] when empty.

Properties

typestring

Item type, fixed as function_call

turn_idstring

Public turn ID

call_idstring

Function call ID

namestring

Function name

argumentsobject

Parsed call arguments

errorstring / null

Session-level error message, different from a turn's structured error

usageobject / null

Token usage.

Properties

input_tokensinteger

Number of input tokens

input_tokens_detailsobject

Input token details.

Properties

cached_tokensinteger

Number of input tokens that hit the cache

output_tokensinteger

Number of output tokens

output_tokens_detailsobject

Output token details.

Properties

reasoning_tokensinteger

Number of reasoning tokens

total_tokensinteger

Total number of tokens

spend_controlobject

Spend control; returned only when a historical record has a value; creation and update do not accept writes.

Properties

limitinteger

Spending limit in cents

consumedinteger / null

Consumed amount in cents

Response example

{
  "id": "sess_xxx",
  "object": "agent.session",
  "created_at": 1794118835,
  "last_active_at": 1794119300,
  "status": "idle",
  "agent": {
    "id": "agent_xxx",
    "model": "qwen3.8-max",
    "instructions": "Answer briefly.",
    "reasoning": {"effort": "medium", "summary": "auto"},
    "text": {"format": {"type": "text"}, "verbosity": "medium"},
    "tools": [],
    "multi_agent": {"enabled": false, "max_concurrent_subagents": null},
    "name": null
  },
  "environment": {"type": "none"},
  "metadata": {"source": "updated"},
  "required_actions": [],
  "vault_ids": [],
  "error": null,
  "usage": {
    "input_tokens": 12,
    "input_tokens_details": {"cached_tokens": 0},
    "output_tokens": 8,
    "output_tokens_details": {"reasoning_tokens": 0},
    "total_tokens": 20
  }
}

Error codes

Business errors return an error object with type, code, message, and param. Common errors:

HTTP statusError type / codeSolution
400invalid_request_error / invalid_request_errorSend at least one of metadata or agent in a valid JSON object
400invalid_request_error / unknown_parameter, invalid_type, invalid_valueRemove unknown fields and fix field types and enum values as described
400invalid_request_error / object_above_max_properties, empty_property_name, property_name_above_max_length, string_above_max_lengthShorten metadata or the string field as described
401authentication_error / invalid_api_keySend a valid Authorization: Bearer $DASHSCOPE_API_KEY header
404not_found_error / not_found_errorUse a well-formed, non-archived session ID from the current workspace
409conflict_error / conflict_errorRetrieve the session again and retry
502server_error / agents_api_upstream_unavailableRetry later. If it keeps failing, submit a ticket with the x-request-id from the response headers