Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build LLM-powered apps with the Anthropic Claude API or SDK across Python, TypeScript, Java, Go, Ruby, C#, and PHP.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
curl/managed-agents.md
1# Managed Agents — cURL / Raw HTTP23Use these examples when the user needs raw HTTP requests or is working without an SDK.45## Setup67```bash8export ANTHROPIC_API_KEY="your-api-key"910# Common headers11HEADERS=(12-H "Content-Type: application/json"13-H "x-api-key: $ANTHROPIC_API_KEY"14-H "anthropic-version: 2023-06-01"15-H "anthropic-beta: managed-agents-2026-04-01"16)17```1819---2021## Create an Environment2223```bash24curl -X POST https://api.anthropic.com/v1/environments \25"${HEADERS[@]}" \26-d '{27"name": "my-dev-env",28"config": {29"type": "cloud",30"networking": { "type": "unrestricted" }31}32}'33```3435### With restricted networking3637```bash38curl -X POST https://api.anthropic.com/v1/environments \39"${HEADERS[@]}" \40-d '{41"name": "restricted-env",42"config": {43"type": "cloud",44"networking": {45"type": "limited",46"allow_package_managers": true,47"allow_mcp_servers": true,48"allowed_hosts": ["api.example.com"]49}50}51}'52```5354---5556## Create an Agent (required first step)5758> ⚠️ **There is no inline agent config.** Under `managed-agents-2026-04-01`, `model`/`system`/`tools` are top-level fields on `POST /v1/agents`, not on the session. Always create the agent first — the session only takes `"agent": {"type": "agent", "id": "..."}`.5960### Minimal6162```bash63# 1. Create the agent64curl -X POST https://api.anthropic.com/v1/agents \65"${HEADERS[@]}" \66-d '{67"name": "Coding Assistant",68"model": "claude-opus-4-8",69"tools": [{ "type": "agent_toolset_20260401" }]70}'71# → { "id": "agent_abc123", ... }7273# 2. Start a session74curl -X POST https://api.anthropic.com/v1/sessions \75"${HEADERS[@]}" \76-d '{77"agent": { "type": "agent", "id": "agent_abc123", "version": "1772585501101368014" },78"environment_id": "env_abc123"79}'80```8182### With system prompt, custom tools, and GitHub repo8384```bash85# 1. Create the agent86curl -X POST https://api.anthropic.com/v1/agents \87"${HEADERS[@]}" \88-d '{89"name": "Code Reviewer",90"model": "claude-opus-4-8",91"system": "You are a senior code reviewer. Be thorough and constructive.",92"tools": [93{ "type": "agent_toolset_20260401" },94{95"type": "custom",96"name": "run_linter",97"description": "Run the project linter on a file",98"input_schema": {99"type": "object",100"properties": {101"file_path": { "type": "string", "description": "Path to lint" }102},103"required": ["file_path"]104}105}106]107}'108109# 2. Start a session with the repo mounted110curl -X POST https://api.anthropic.com/v1/sessions \111"${HEADERS[@]}" \112-d '{113"agent": { "type": "agent", "id": "agent_abc123", "version": "1772585501101368014" },114"environment_id": "env_abc123",115"title": "Code review session",116"resources": [117{118"type": "github_repository",119"url": "https://github.com/owner/repo",120"mount_path": "/workspace/repo",121"authorization_token": "ghp_...",122"branch": "feature-branch"123}124]125}'126```127128---129130## Send a User Message131132```bash133curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \134"${HEADERS[@]}" \135-d '{136"events": [137{138"type": "user.message",139"content": [{ "type": "text", "text": "Review the auth module for security issues" }]140}141]142}'143```144145---146147## Stream Events (SSE)148149```bash150curl -N https://api.anthropic.com/v1/sessions/$SESSION_ID/events/stream \151"${HEADERS[@]}"152```153154Response format:155156```157event: session.status_running158data: {"type":"session.status_running","id":"sevt_...","processed_at":"..."}159160event: agent.message161data: {"type":"agent.message","id":"sevt_...","content":[{"type":"text","text":"I'll review..."}],"processed_at":"..."}162163event: session.status_idle164data: {"type":"session.status_idle","id":"sevt_...","processed_at":"..."}165```166167---168169## Poll Events170171```bash172# Get all events173curl https://api.anthropic.com/v1/sessions/$SESSION_ID/events \174"${HEADERS[@]}"175176# Paginated — get next page of events177curl "https://api.anthropic.com/v1/sessions/$SESSION_ID/events?page=page_abc123" \178"${HEADERS[@]}"179```180181---182183## Provide Custom Tool Result184185When the agent calls a custom tool, send the result back:186187```bash188curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \189"${HEADERS[@]}" \190-d '{191"events": [192{193"type": "user.custom_tool_result",194"custom_tool_use_id": "sevt_abc123",195"content": [{ "type": "text", "text": "No linting errors found." }]196}197]198}'199```200201---202203## Interrupt a Running Session204205```bash206curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \207"${HEADERS[@]}" \208-d '{209"events": [210{211"type": "interrupt"212}213]214}'215```216217---218219## Get Session Details220221```bash222curl https://api.anthropic.com/v1/sessions/$SESSION_ID \223"${HEADERS[@]}"224```225226---227228## List Sessions229230```bash231curl https://api.anthropic.com/v1/sessions \232"${HEADERS[@]}"233```234235---236237## Delete a Session238239```bash240curl -X DELETE https://api.anthropic.com/v1/sessions/$SESSION_ID \241"${HEADERS[@]}"242```243244---245246## Upload a File247248```bash249curl -X POST https://api.anthropic.com/v1/files \250-H "x-api-key: $ANTHROPIC_API_KEY" \251-H "anthropic-version: 2023-06-01" \252-H "anthropic-beta: files-api-2025-04-14" \253-F "file=@path/to/file.txt"254```255256---257258## List and Download Session Files259260List files the agent wrote to `/mnt/session/outputs/` during a session, then download them.261262```bash263# List files associated with a session264curl "https://api.anthropic.com/v1/files?scope_id=$SESSION_ID" \265-H "x-api-key: $ANTHROPIC_API_KEY" \266-H "anthropic-version: 2023-06-01" \267-H "anthropic-beta: files-api-2025-04-14,managed-agents-2026-04-01"268269# Download a specific file270curl "https://api.anthropic.com/v1/files/$FILE_ID/content" \271-H "x-api-key: $ANTHROPIC_API_KEY" \272-H "anthropic-version: 2023-06-01" \273-H "anthropic-beta: files-api-2025-04-14,managed-agents-2026-04-01" \274-o downloaded_file.txt275```276277---278279## List Agents280281```bash282curl https://api.anthropic.com/v1/agents \283"${HEADERS[@]}"284```285286---287288## MCP Server Integration289290```bash291# 1. Agent declares MCP server (no auth here — auth goes in a vault)292curl -X POST https://api.anthropic.com/v1/agents \293"${HEADERS[@]}" \294-d '{295"name": "MCP Agent",296"model": "claude-opus-4-8",297"mcp_servers": [298{ "type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse" }299],300"tools": [301{ "type": "agent_toolset_20260401" },302{ "type": "mcp_toolset", "mcp_server_name": "my-tools" }303]304}'305306# 2. Session attaches vault containing credentials for that MCP server URL307curl -X POST https://api.anthropic.com/v1/sessions \308"${HEADERS[@]}" \309-d '{310"agent": "agent_abc123",311"environment_id": "env_abc123",312"vault_ids": ["vlt_abc123"]313}'314```315316See `shared/managed-agents-tools.md` §Vaults for creating vaults and adding credentials.317318---319320## Tool Configuration321322```bash323curl -X POST https://api.anthropic.com/v1/agents \324"${HEADERS[@]}" \325-d '{326"name": "Restricted Agent",327"model": "claude-opus-4-8",328"tools": [329{330"type": "agent_toolset_20260401",331"default_config": { "enabled": true },332"configs": [333{ "name": "bash", "enabled": false }334]335}336]337}'338```339