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": "package_managers_and_custom",46"allowed_hosts": ["api.example.com"]47}48}49}'50```5152---5354## Create an Agent (required first step)5556> ⚠️ **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": "..."}`.5758### Minimal5960```bash61# 1. Create the agent62curl -X POST https://api.anthropic.com/v1/agents \63"${HEADERS[@]}" \64-d '{65"name": "Coding Assistant",66"model": "claude-opus-4-7",67"tools": [{ "type": "agent_toolset_20260401" }]68}'69# → { "id": "agent_abc123", ... }7071# 2. Start a session72curl -X POST https://api.anthropic.com/v1/sessions \73"${HEADERS[@]}" \74-d '{75"agent": { "type": "agent", "id": "agent_abc123", "version": "1772585501101368014" },76"environment_id": "env_abc123"77}'78```7980### With system prompt, custom tools, and GitHub repo8182```bash83# 1. Create the agent84curl -X POST https://api.anthropic.com/v1/agents \85"${HEADERS[@]}" \86-d '{87"name": "Code Reviewer",88"model": "claude-opus-4-7",89"system": "You are a senior code reviewer. Be thorough and constructive.",90"tools": [91{ "type": "agent_toolset_20260401" },92{93"type": "custom",94"name": "run_linter",95"description": "Run the project linter on a file",96"input_schema": {97"type": "object",98"properties": {99"file_path": { "type": "string", "description": "Path to lint" }100},101"required": ["file_path"]102}103}104]105}'106107# 2. Start a session with the repo mounted108curl -X POST https://api.anthropic.com/v1/sessions \109"${HEADERS[@]}" \110-d '{111"agent": { "type": "agent", "id": "agent_abc123", "version": "1772585501101368014" },112"environment_id": "env_abc123",113"title": "Code review session",114"resources": [115{116"type": "github_repository",117"url": "https://github.com/owner/repo",118"mount_path": "/workspace/repo",119"authorization_token": "ghp_...",120"branch": "feature-branch"121}122]123}'124```125126---127128## Send a User Message129130```bash131curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \132"${HEADERS[@]}" \133-d '{134"events": [135{136"type": "user.message",137"content": [{ "type": "text", "text": "Review the auth module for security issues" }]138}139]140}'141```142143---144145## Stream Events (SSE)146147```bash148curl -N https://api.anthropic.com/v1/sessions/$SESSION_ID/events/stream \149"${HEADERS[@]}"150```151152Response format:153154```155event: session.status_running156data: {"type":"session.status_running","id":"sevt_...","processed_at":"..."}157158event: agent.message159data: {"type":"agent.message","id":"sevt_...","content":[{"type":"text","text":"I'll review..."}],"processed_at":"..."}160161event: session.status_idle162data: {"type":"session.status_idle","id":"sevt_...","processed_at":"..."}163```164165---166167## Poll Events168169```bash170# Get all events171curl https://api.anthropic.com/v1/sessions/$SESSION_ID/events \172"${HEADERS[@]}"173174# Paginated — get next page of events175curl "https://api.anthropic.com/v1/sessions/$SESSION_ID/events?page=page_abc123" \176"${HEADERS[@]}"177```178179---180181## Provide Custom Tool Result182183When the agent calls a custom tool, send the result back:184185```bash186curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \187"${HEADERS[@]}" \188-d '{189"events": [190{191"type": "user.custom_tool_result",192"custom_tool_use_id": "sevt_abc123",193"content": [{ "type": "text", "text": "No linting errors found." }]194}195]196}'197```198199---200201## Interrupt a Running Session202203```bash204curl -X POST https://api.anthropic.com/v1/sessions/$SESSION_ID/events \205"${HEADERS[@]}" \206-d '{207"events": [208{209"type": "interrupt"210}211]212}'213```214215---216217## Get Session Details218219```bash220curl https://api.anthropic.com/v1/sessions/$SESSION_ID \221"${HEADERS[@]}"222```223224---225226## List Sessions227228```bash229curl https://api.anthropic.com/v1/sessions \230"${HEADERS[@]}"231```232233---234235## Delete a Session236237```bash238curl -X DELETE https://api.anthropic.com/v1/sessions/$SESSION_ID \239"${HEADERS[@]}"240```241242---243244## Upload a File245246```bash247curl -X POST https://api.anthropic.com/v1/files \248-H "x-api-key: $ANTHROPIC_API_KEY" \249-H "anthropic-version: 2023-06-01" \250-H "anthropic-beta: files-api-2025-04-14" \251-F "file=@path/to/file.txt"252```253254---255256## List and Download Session Files257258List files the agent wrote to `/mnt/session/outputs/` during a session, then download them.259260```bash261# List files associated with a session262curl "https://api.anthropic.com/v1/files?scope_id=$SESSION_ID" \263-H "x-api-key: $ANTHROPIC_API_KEY" \264-H "anthropic-version: 2023-06-01" \265-H "anthropic-beta: files-api-2025-04-14,managed-agents-2026-04-01"266267# Download a specific file268curl "https://api.anthropic.com/v1/files/$FILE_ID/content" \269-H "x-api-key: $ANTHROPIC_API_KEY" \270-H "anthropic-version: 2023-06-01" \271-H "anthropic-beta: files-api-2025-04-14,managed-agents-2026-04-01" \272-o downloaded_file.txt273```274275---276277## List Agents278279```bash280curl https://api.anthropic.com/v1/agents \281"${HEADERS[@]}"282```283284---285286## MCP Server Integration287288```bash289# 1. Agent declares MCP server (no auth here — auth goes in a vault)290curl -X POST https://api.anthropic.com/v1/agents \291"${HEADERS[@]}" \292-d '{293"name": "MCP Agent",294"model": "claude-opus-4-7",295"mcp_servers": [296{ "type": "url", "name": "my-tools", "url": "https://my-mcp-server.example.com/sse" }297],298"tools": [299{ "type": "agent_toolset_20260401" },300{ "type": "mcp_toolset", "mcp_server_name": "my-tools" }301]302}'303304# 2. Session attaches vault containing credentials for that MCP server URL305curl -X POST https://api.anthropic.com/v1/sessions \306"${HEADERS[@]}" \307-d '{308"agent": "agent_abc123",309"environment_id": "env_abc123",310"vault_ids": ["vlt_abc123"]311}'312```313314See `shared/managed-agents-tools.md` §Vaults for creating vaults and adding credentials.315316---317318## Tool Configuration319320```bash321curl -X POST https://api.anthropic.com/v1/agents \322"${HEADERS[@]}" \323-d '{324"name": "Restricted Agent",325"model": "claude-opus-4-7",326"tools": [327{328"type": "agent_toolset_20260401",329"default_config": { "enabled": true },330"configs": [331{ "name": "bash", "enabled": false }332]333}334]335}'336```337