Was this page helpful?
Files API를 통해 파일을 업로드하고 세션의 컨테이너에 마운트하여 에이전트에 파일을 제공할 수 있습니다.
모든 Managed Agents API 요청에는 managed-agents-2026-04-01 베타 헤더가 필요합니다. SDK는 베타 헤더를 자동으로 설정합니다.
먼저 Files API를 사용하여 파일을 업로드합니다:
file=$(curl --fail-with-body -sS "${auth[@]}" \
"${base_url}/files" \
-F [email protected])
file_id=$(jq -er '.id' <<<"${file}")
printf 'File ID: %s\n' "${file_id}"세션을 생성할 때 resources 배열에 파일을 추가하여 업로드된 파일을 컨테이너에 마운트합니다:
mount_path는 선택 사항이지만, 에이전트가 무엇을 찾고 있는지 알 수 있도록 업로드된 파일에 설명적인 이름을 지정하세요.
세션 내 파일 인스턴스를 참조하는 새로운 file_id가 생성됩니다. 이 복사본은 스토리지 한도에 포함되지 않습니다.
resources 배열에 항목을 추가하여 여러 파일을 마운트합니다:
세션당 최대 100개의 파일이 지원됩니다.
세션 리소스 API를 사용하여 세션 생성 후 파일을 추가하거나 제거할 수 있습니다. 각 리소스는 추가(또는 목록 조회) 시 반환되는 id를 가지며, 이를 삭제 시 사용합니다.
resources.list로 세션의 모든 리소스를 나열합니다. 파일을 제거하려면 리소스 ID와 함께 resources.delete를 호출합니다:
Files API를 사용하여 세션에 범위가 지정된 파일을 나열하고 다운로드합니다.
에이전트는 다음을 포함한 모든 파일 형식을 처리할 수 있습니다:
.py, .js, .ts, .go, .rs 등).csv, .json, .xml, .yaml).txt, .md).zip, .tar.gz) - 에이전트가 bash를 사용하여 압축을 해제할 수 있습니다컨테이너에 마운트된 파일은 읽기 전용 복사본입니다. 에이전트는 파일을 읽을 수 있지만 원본 업로드 파일을 수정할 수 없습니다. 수정된 버전으로 작업하려면 에이전트가 컨테이너 내의 새 경로에 씁니다.
/로 시작)session=$(
jq -n \
--arg agent_id "${agent_id}" \
--arg environment_id "${environment_id}" \
--arg file_id "${file_id}" \
'{
agent: $agent_id,
environment_id: $environment_id,
resources: [
{
type: "file",
file_id: $file_id,
mount_path: "/workspace/data.csv"
}
]
}' | curl --fail-with-body -sS "${auth[@]}" "${base_url}/sessions" --json @-
)
session_id=$(jq -er '.id' <<<"${session}")"resources": [
{ "type": "file", "file_id": "file_abc123", "mount_path": "/workspace/data.csv" },
{ "type": "file", "file_id": "file_def456", "mount_path": "/workspace/config.json" },
{ "type": "file", "file_id": "file_ghi789", "mount_path": "/workspace/src/main.py" }
]resource=$(
jq -n --arg file_id "${file_id}" '{type: "file", file_id: $file_id}' \
| curl --fail-with-body -sS "${auth[@]}" \
"${base_url}/sessions/${session_id}/resources" --json @-
)
resource_id=$(jq -er '.id' <<<"${resource}")
printf '%s\n' "${resource_id}" # "sesrsc_01ABC..."curl --fail-with-body -sS "${auth[@]}" \
"${base_url}/sessions/${session_id}/resources" \
| jq -r '.data[] | "\(.id) \(.type)"'
curl --fail-with-body -sS "${auth[@]}" -X DELETE \
"${base_url}/sessions/${session_id}/resources/${resource_id}" >/dev/null# 세션과 연관된 파일 목록 조회
curl -fsSL "https://api.anthropic.com/v1/files?scope_id=sess_abc123" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: files-api-2025-04-14"
# 파일 다운로드
curl -fsSL "https://api.anthropic.com/v1/files/$FILE_ID/content" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "anthropic-beta: files-api-2025-04-14" \
-o output.txt