Claude Platform Docs

To enable the Compliance API, see the setup guide.

Set up the Compliance API

下载代码 Artifact 版本内容

GET/v1/compliance/apps/code/artifacts/{artifact_id}/versions/{version_id}

以分块方式将 Artifact 某个版本的内容作为响应正文流式传输,不带 Content-Length。使用 multi_file_format=zip 时,包含多个文件的版本(Claude Doc 的版本除外;Claude Doc 是 artifact_type 为 claude_docs 的 Artifact)会以其文件的 ZIP 归档形式返回。

标头:Content-Type(ZIP 归档为 application/zip,否则为存储的 MIME 类型)、Content-Disposition: attachment; filename*=utf-8''<name>(RFC 5987)、Cache-Control: no-store, private,以及在可用时提供的 Content-MD5(base64)。无论内容是什么,ZIP 归档的 <name> 为 {artifact_id}-{version_id}.zip,否则为 {artifact_id}-{version_id}.txt。Content-MD5 仅出现在以未压缩方式存储的单个文件上,因此永远不会出现在 ZIP 归档上。如果存在该标头,请据此校验正文。

此下载特有的错误:

  • 404:Artifact 不存在或 API 密钥无法读取它,或者该版本已不再保留。发布新版本时会丢弃较旧的版本,因此请重新列出该 Artifact 的版本。当组织的客户管理的加密密钥无法使用时,您也会收到此错误。请在密钥恢复可用后重试。
  • 503:当前无法提供内容,例如因为其上传仍在进行中或已被放弃。请使用退避策略重试。
  • 422,且 error.details.error_code 为 multi_file_unavailable:该版本包含多个文件。请添加 multi_file_format=zip。包含多个文件的 Claude Doc 版本无论如何都会收到此错误,因为它只包含用于显示该 Doc 的网页。请使用 GET /v1/compliance/apps/code/artifacts/{artifact_id}/content?multi_file_format=zip 下载该 Doc 的文本。
  • 422,且为 file_set_unavailable:请求设置了 multi_file_format=zip,该版本包含多个文件,且其中一个文件的路径无法通过 API 导出。请勿重试。

下载开始后发生的错误会使正文提前终止,而此时 200 状态已经发送。例如,以压缩方式存储且解压后超过 16 MiB 的内容就会出现这种情况。对于没有 Content-MD5 的单个文件,唯一的迹象是传输在最后一个分块之前中止,因此请将以这种方式中止的下载视为失败。

版本文件的 ZIP 归档包含一个以 Artifact 和版本命名的顶层文件夹。该文件夹包含一个 files/ 文件夹和一个索引 files.json。索引最后写入,因此如果归档无法打开,或其顶层文件夹中没有 files.json,请将其视为不完整。

files.json 包含以下字段:

  • artifact_id:Artifact ID,与请求中的相同。
  • version_id:版本 ID,与请求中的相同。
  • title:归档中版本的标题;如果未保留标题,则为该版本的 ID。
  • created_at:版本的发布时间(RFC 3339,UTC);如果未知,则为 null。
  • files:files/ 下每个文件对应一个条目,包含 original_path(文件在版本中的路径)、exported_as(文件在归档中的路径)、sha256(小写十六进制)、size_bytes(压缩前)和 mime_type。exported_as 由顶层文件夹、files/ 和 original_path 依次组成。无法在所有操作系统上安全保存或打开的名称会被更改。请使用 exported_as(而非 original_path)在归档中查找文件。
  • omitted_files:未包含在归档中的文件,每个文件包含 original_path、sha256、size_bytes 和 mime_type。其中包括该版本从其他 Artifact 使用的文件,还包括当另一个组织拥有该 Artifact 所基于的 Artifact 类型时,从该类型复制的文件(例如用于显示它的应用)。

files 和 omitted_files 合计最多列出 4,096 个文件,其 size_bytes 总和最多为 1 GiB,且单个文件不超过 20 MiB。

Path parameters
artifact_id: string

The Artifact ID (tagged ID, e.g., cart_abc123)

version_id: string

Opaque version identifier from the Artifact's versions list

Query parameters
multi_file_format: optional string

Set to zip, its only value, to receive a version that has more than one file as a ZIP archive of its files with an index, files.json. A version with one file is returned as that file. A Claude Doc's version never comes back as a ZIP.

Headers
"anthropic-version": optional string

The version of the Claude API you want to use.

Read more about versioning and our version history here.

"x-api-key": optional string
下载代码 Artifact 版本内容
cURL
curl https://api.anthropic.com/v1/compliance/apps/code/artifacts/$ARTIFACT_ID/versions/$VERSION_ID \
    -H 'anthropic-version: 2023-06-01' \
    -H "Authorization: Bearer $ANTHROPIC_COMPLIANCE_API_KEY"