API 文档

使用 DataTrust API 以编程方式访问数据市场资源

Base URL: http://localhost:3001/api/v1

认证方式

所有API请求需要在HTTP Header中携带API密钥进行认证:

HTTP Header
Authorization: Bearer dt_your_api_key_here

您可以在 控制台 → API密钥 页面创建和管理API密钥。

安全提示:API密钥仅在创建时显示一次,请妥善保管。不要在客户端代码中暴露密钥。

数据模型 API

GET /api/v1/models 免费

搜索和浏览数据模型列表

参数类型说明
keywordstring搜索关键词
industrystring行业筛选
gradestring等级筛选 (S/A/B+/B/C/D)
pageint页码,默认1
per_pageint每页数量,默认20
GET /api/v1/models/:id 付费

获取数据模型的完整数据(字段定义、样例数据等)

Response 200
{
  "success": true,
  "data": {
    "id": 1,
    "name": "用户行为数据模型",
    "industry": "互联网",
    "fields": [...],
    "sample_data": [...],
    "grade_v4": "A",
    "score_total_v4": 82.5
  },
  "credits_charged": 3.00,
  "balance_remaining": 47.00
}
GET /api/v1/models/:id/fields 付费

仅获取模型的字段定义

GET /api/v1/models/:id/sample 付费

仅获取模型的样例数据

数据集 API

GET /api/v1/datasets 免费

搜索认证数据集(企业数据知识产权)

GET /api/v1/datasets/:id 付费

获取数据集完整信息,包含V6六维评分、字段定义、存证信息

数据产品 & 资源 API

GET /api/v1/products | /api/v1/resources 免费

浏览数据产品和数据资源列表

GET /api/v1/products/:id | /api/v1/resources/:id 付费

获取产品或资源详情

账户 API

GET /api/v1/account/balance

查询账户余额和免费额度

Response 200
{
  "success": true,
  "data": {
    "balance": 50.00,
    "free_calls_remaining": 85,
    "tier": "free"
  }
}
GET /api/v1/account/usage

查询使用量统计

错误码

状态码错误代码说明
401AUTH_REQUIRED未提供API密钥
401INVALID_API_KEYAPI密钥无效或已撤销
402INSUFFICIENT_BALANCE余额不足,请充值
404NOT_FOUND请求的资源不存在
429RATE_LIMITED请求频率超限,请稍后重试
500INTERNAL_ERROR服务器内部错误

所有错误响应格式:

Error Response
{
  "success": false,
  "error": "错误信息描述",
  "code": "ERROR_CODE"
}

代码示例

cURL
Shell
# 查询模型列表(免费)
curl -H "Authorization: Bearer dt_your_key" \
  "http://localhost:3001/api/v1/models?keyword=金融&page=1"

# 获取模型详情(付费)
curl -H "Authorization: Bearer dt_your_key" \
  "http://localhost:3001/api/v1/models/123"

# 查询余额
curl -H "Authorization: Bearer dt_your_key" \
  "http://localhost:3001/api/v1/account/balance"
Python
Python
import requests

API_KEY = "dt_your_api_key_here"
BASE_URL = "http://localhost:3001/api/v1"
headers = {"Authorization": f"Bearer {API_KEY}"}

# 搜索数据模型
resp = requests.get(f"{BASE_URL}/models", headers=headers,
                    params={"keyword": "金融", "page": 1})
data = resp.json()
print(f"共 {data['data']['total']} 个模型")

# 获取模型详情(会扣费)
resp = requests.get(f"{BASE_URL}/models/123", headers=headers)
result = resp.json()
print(f"扣费: ¥{result['credits_charged']}")
print(f"剩余: ¥{result['balance_remaining']}")
Node.js
JavaScript
const API_KEY = 'dt_your_api_key_here';
const BASE_URL = 'http://localhost:3001/api/v1';

// 搜索数据模型
const res = await fetch(`${BASE_URL}/models?keyword=金融`, {
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const data = await res.json();
console.log(`共 ${data.data.total} 个模型`);

// 获取模型详情(会扣费)
const detail = await fetch(`${BASE_URL}/models/123`, {
  headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const result = await detail.json();
console.log(`扣费: ¥${result.credits_charged}`);