Claude Platform Docs

To enable the Compliance API, see the setup guide.

Set up the Compliance API

下載 Code 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
下載 Code 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"