Get 灵蛇AI Platform API Call Volume Export

Asynchronously generate a CSV file containing all business interface call records within the selected time period and return the download URL. Suitable for monthly reconciliation, providing BI reports to finance, delivering details to third-party auditors, and other scenarios.

📌 It is strongly recommended to use this interface instead of paginated retrieval of the call record list when the number of call records exceeds 10,000 — the server generates CSV faster.

ℹ️ This interface belongs to the 灵蛇AI Platform Management API, with a unified prefix of https://platform.opensnake.cloud/api/v1/.

Interface Overview

Item Content
Method POST
URL https://platform.opensnake.cloud/api/v1/usages/export/
Authentication ✅ Requires account token
Content-Type application/json

Authentication Instructions (How to Obtain Account Token)

Request Header:

Authorization: Bearer platform-v1-92eb****629c

For obtaining the token, see Manage 灵蛇AI Platform Account Token.

Request Body

Field Type Required Description
user_id UUID ✅ Current account user ID (also in Body, not in query)
start_at datetime ✅ Start time (ISO8601)
end_at datetime ✅ End time (ISO8601). Single export window suggested ≤ 90 days
application_id UUID No Filter by Application
service_id UUID No Filter by service
credential_id UUID No Filter by credential
status_code integer No Filter by HTTP status code

Request Example

cURL

curl -X POST 'https://platform.opensnake.cloud/api/v1/usages/export/' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer platform-v1-92eb****629c' \
  -H 'content-type: application/json' \
  -d '{
    "user_id": "89518d07-5560-4b05-92c1-667f3ddf6a4b",
    "start_at": "2026-04-01T00:00:00Z",
    "end_at": "2026-04-30T23:59:59Z"
  }'

Python

import requests
import time

PLATFORM_TOKEN = "platform-v1-92eb****629c"
USER_ID = "89518d07-5560-4b05-92c1-667f3ddf6a4b"

# 1. Initiate export task
resp = requests.post(
    "https://platform.opensnake.cloud/api/v1/usages/export/",
    headers={
        "authorization": f"Bearer {PLATFORM_TOKEN}",
        "content-type": "application/json",
    },
    json={
        "user_id": USER_ID,
        "start_at": "2026-04-01T00:00:00Z",
        "end_at": "2026-04-30T23:59:59Z",
    },
    timeout=30,
)
task = resp.json()
print(f"Export task created: {task['id']}, status: {task['state']}")

# 2. Poll status until generation is complete
while task["state"] in ("Pending", "Processing"):
    time.sleep(2)
    task = requests.get(
        f"https://platform.opensnake.cloud/api/v1/usages/export/{task['id']}",
        headers={"authorization": f"Bearer {PLATFORM_TOKEN}"},
    ).json()

if task["state"] == "Completed":
    print(f"✅ Export completed, download URL: {task['file_url']}")
else:
    print(f"❌ Export failed: {task.get('error')}")

Node.js

const r = await fetch('https://platform.opensnake.cloud/api/v1/usages/export/', {
  method: 'POST',
  headers: {
    authorization: 'Bearer platform-v1-92eb****629c',
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    user_id: '89518d07-5560-4b05-92c1-667f3ddf6a4b',
    start_at: '2026-04-01T00:00:00Z',
    end_at: '2026-04-30T23:59:59Z',
  }),
})
const task = await r.json()
console.log('Task ID:', task.id)

Response Example (HTTP 202)

{
  "id": "exp-9c8b7a6d5e4f3a2b1c0d",
  "user_id": "89518d07-5560-4b05-92c1-667f3ddf6a4b",
  "state": "Pending",
  "start_at": "2026-04-01T00:00:00Z",
  "end_at": "2026-04-30T23:59:59Z",
  "file_url": null,
  "expires_at": null,
  "created_at": "2026-04-26T08:30:00Z"
}

After completion, state changes to Completed and file_url contains the CSV download link (generally valid for 24 hours).

Response Field Descriptions

Field Type Description
id string Export task ID
state string Pending / Processing / Completed / Failed
file_url string null
expires_at string null
start_at string Start of the export window
end_at string End of the export window
error string null

CSV Column Definitions

The downloaded CSV file from file_url contains the following columns (the first row is the header):

created_at, application_id, service_id, credential_id, api_id, method, path, status_code, consumption, duration_ms, client_ip, request_id

The meanings of the fields are the same as in the call record list.

Error Handling

HTTP Code Meaning
400 invalid Missing or format error in user_id / start_at / end_at
400 window_too_large Time window exceeds limit (default 90 days)
401 not_authenticated Missing account token
403 permission_denied user_id is not yours

Practical Tips

  • Exporting large windows in segments: For cross-year exports, it is recommended to split into multiple monthly tasks.
  • Download URL has a validity period: Generally 24 hours; if expired, a new export task needs to be initiated.
  • Do not write file_url in front-end code: The URL contains a signature and should be stored in the backend before being distributed to users.
  • CSV encoding UTF-8 BOM: Excel opens Chinese characters directly without garbled text.