跳转到内容
Rayrun
登录注册

用量与账单

用量聚合、余额与流水、价目表、计费告警与策略、兑换码。 完整参数、请求 / 响应 schema 见下方(本页只渲染该组):

v0.1.0
OpenAPI 3.0.3

Rayrun API

Rayrun REST API —— 控制台与命令行(rayrun CLI)的统一接口,也是自托管部署的 第三方集成的接入点。共 13 组、93 个端点(分组见左侧栏或「介绍」页的接口一览)。 基地址与部署同源:<实例地址>/v1(如 https://rayrun.example.com/v1)。 认证:Bearer Token(控制台「设置 → 我的 API Token」或 rayrun login 创建) 或浏览器会话 Cookie;GET /health 免认证。详见「介绍」页的认证一节。

Server:https://api.rayrunos.com/v1

Rayrun 托管平台

Client Libraries

用量与账单

​

用量聚合(现场聚合)

​

tokens 为 trust = Guest,仅展示,永不参与计费

Query Parameters

  • 缺省 = 全局(MVP 即全部沙箱);给定 = 该沙箱

Responses

  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/usage
curl https://api.rayrunos.com/v1/usage \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "vm_hours": 1,
  "egress_bytes": 1,
  "tokens": {
    "input_tokens": 1,
    "output_tokens": 1,
    "cost_usd": null
  }
}

当前余额(现场聚合 Σ credit − Σ debit)

​

Responses

  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/billing/balance
curl https://api.rayrunos.com/v1/billing/balance \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "balance_cents": 1,
  "currency": "string"
}

活跃计费告警与组织计费策略

​

现场计算当前组织的活跃告警与策略。欠费状态(arrears_stop)始终返回, 不受平台告警开关影响;balance_low / balance_non_positive / runway_low / usage_daily_high 只在平台开启可选告警时返回。只读端点:不发信、不写 journal、不做去重。

Responses

  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/billing/alerts
curl https://api.rayrunos.com/v1/billing/alerts \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "alerts": [
    {
      "kind": "balance_low",
      "severity": "warning",
      "scope": "string",
      "sandbox_id": null,
      "current": 1,
      "threshold": 1,
      "unit": "cents",
      "message": "string",
      "action_url": "string",
      "grace_deadline": null
    }
  ],
  "policy": {
    "arrears_grace_days": 1
  }
}

账本流水(journal 直查 billing.*,降序分页 / 升序续传两模式)

​
  • 只返回 billing.credit / billing.debit
  • 降序模式(默认,账本页「最新在前」):cursor 返回 seq < cursor 的一页;next_cursor = 本页最后一条 seq,null = 到头
  • 升序模式(增量轮询):from_seq 返回 seq > from_seq 升序,响应无 next_cursor
  • cursor 与 from_seq 互斥,同传 → 400 invalid_request

Query Parameters

  • 降序模式游标(seq,string);与 from_seq 互斥

  • 升序续传起点(seq,string);与 cursor 互斥

  • 默认 50,上限 500

Responses

  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/billing/transactions
curl 'https://api.rayrunos.com/v1/billing/transactions?limit=50' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "entries": [
    {
      "seq": "string",
      "entry_id": "123e4567-e89b-12d3-a456-426614174000",
      "tenant_id": "string",
      "user_id": "string",
      "sandbox_id": null,
      "kind": "string",
      "payload": {},
      "ts": "2026-11-11T06:00:17.727Z",
      "trust": "Host",
      "risk": "Low",
      "outcome": "Success"
    }
  ],
  "next_cursor": null
}

当前价目表(已认证)

​

读启动时解析的全局价目表(RAYRUN_PRICING_JSON);新沙箱创建时按此快照进 sandbox.created.payload

Responses

  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/billing/pricing
curl https://api.rayrunos.com/v1/billing/pricing \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "currency": "string",
  "cpu_cents_per_core_hour": 1,
  "mem_cents_per_gb_hour": 1,
  "egress_cents_per_gb": 1,
  "storage_cents_per_gib_month": 1,
  "storage_free_gib_per_sandbox": 1
}

兑换

​
  • 一次性语义:GET_LOCK 内「查终态 + 写 [code.redeemed, billing.credit]」原子
  • 同用户重复提交同一码 → 200 原结果(重放该码的兑换记录)
  • 他人已兑换 → 409 code_already_redeemed;过期 → 400 invalid_request + details.reason = "expired";未知码 → 400 invalid_request
  • 落 journal:code.redeemed → billing.credit
  • 限 owner/admin:developer → 403 forbidden。核销是不可逆的账本入账动作,是本版唯一有角色门禁的业务端点(账单/用量维持三角色只读可见)

Body·

required
application/json
  • 大写规范形(比对大小写不敏感,handler 规范化后校验);7 组 × 4 字符、28 字符去歧义字母表(去 0/1/O/I,≈ 134 bit);响应与审计永不含码值

Responses

  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
Request Example for post/redemption-codes/redeem
curl https://api.rayrunos.com/v1/redemption-codes/redeem \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
  --data '{
  "code": ""
}'
{
  "amount_cents": 1,
  "balance_cents": 1,
  "currency": "string"
}

在线充值配置(是否启用 / 预设面额 / 金额上下限)

​
  • 返回服务端配置的在线充值开关、预设面额与金额上下限;不含商户号、密钥与回调地址
  • enabled=false 时前端隐藏入口,POST /orders 返回 503 wechat_pay_not_configured
  • 任意已认证角色可读(下单仍限 owner/admin)

Responses

  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/billing/recharge
curl https://api.rayrunos.com/v1/billing/recharge \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "enabled": true,
  "currency": "string",
  "presets_cents": [
    1
  ],
  "min_cents": 1,
  "max_cents": 1
}

创建充值订单(微信支付 H5 / Native)

​
  • channel=h5:返回微信 H5 支付链接(服务端已拼 redirect_url),前端整页跳转
  • channel=native:返回微信 Native code_url,前端渲染二维码并轮询 GET /orders/{order_id}
  • 金额为整数分,范围见 GET /billing/recharge;仅 owner/admin 可下单
  • Idempotency-Key 可选;同一 key 在 24h 内重放同一 201
  • 未配置微信支付 → 503 wechat_pay_not_configured;微信下单失败 → 502 payment_provider_error

Headers

  • 可选幂等键;同一用户同一 key 在 24h 内重放首次 201

Body·

required
application/json
  • 充值金额(分);范围为 GET /billing/recharge 的 min_cents..max_cents

  • h5 = 手机浏览器跳转微信支付;native = 桌面二维码扫码

Responses

  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
Request Example for post/orders
curl https://api.rayrunos.com/v1/orders \
  --request POST \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN' \
  --data '{
  "amount_cents": 1,
  "channel": "h5"
}'
{
  "order_id": "123e4567-e89b-12d3-a456-426614174000",
  "status": "pending",
  "channel": "h5",
  "amount_cents": 1,
  "currency": "string",
  "pay_url": null,
  "pay_url_expires_at": null,
  "expires_at": "2026-11-11T06:00:17.727Z",
  "created_at": "2026-11-11T06:00:17.727Z",
  "paid_at": null
}

查询充值订单状态

​
  • 租户隔离;非本组织或不存在 → 404 not_found
  • pending 时限频主动查询微信(约 3s 节流),用于支付回跳页快速确认与回调丢失兜底
  • paid 为终态;pay_url 仅在 pending 且未过期时返回
  • 仅 owner/admin 可查

Path Parameters

  • 充值订单 ID(UUIDv7)

Responses

  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
  • application/json
Request Example for get/orders/{order_id}
curl https://api.rayrunos.com/v1/orders/123e4567-e89b-12d3-a456-426614174000 \
  --header 'Authorization: Bearer YOUR_SECRET_TOKEN'
{
  "order_id": "123e4567-e89b-12d3-a456-426614174000",
  "status": "pending",
  "channel": "h5",
  "amount_cents": 1,
  "currency": "string",
  "pay_url": null,
  "pay_url_expires_at": null,
  "expires_at": "2026-11-11T06:00:17.727Z",
  "created_at": "2026-11-11T06:00:17.727Z",
  "paid_at": null
}

Models