Agent API

运行记录

查询你的账户发起过的调用和异步运行,并停止仍在进行的异步运行。

这些接口涵盖两类运行:

  • 调用:用你的 key 通过 /gw、/cap、/ai/v1 或同步 /v1/run 发起的每次调用。run id 就是该调用的 X-Pikeway-Call-Id。
  • 异步运行:用 /v1/run 加 "async": true 发起,id 以 run_ 开头,连同输出保留 7 天。

鉴权

三个接口都需要 Authorization: Bearer pk-…,只返回该 key 所属账户的运行(同一账户的任意 key 都可以)。

列出运行

GET/v1/runs
查询参数
limitinteger
每页条数。默认 20,最大 100。
cursorstring
上一页返回的 cursor。
providerstring
只返回调用该 API slug 的记录(仅调用列表)。
async1 | true
改为列出异步运行(含排队中和运行中的)。
statusstring
与 async=1 一起使用:只返回该状态,如 RUNNING。
bash
curl "https://gw.pikeway.ai/v1/runs?limit=20" -H "Authorization: Bearer $PIKEWAY_API_KEY"
curl "https://gw.pikeway.ai/v1/runs?async=1&status=RUNNING" -H "Authorization: Bearer $PIKEWAY_API_KEY"
200 OK · calls
{
  "items": [
    {
      "runId": "0192f6b0-5e2a-7d40-b1c3-8f9e2a4d6c11",
      "provider": "birdeye",
      "method": "GET",
      "path": "/defi/price",
      "status": "COMPLETED",
      "providerResponse": { "httpStatus": 200 },
      "cost": { "value": 0.001, "currency": "USD" },
      "durationMs": 214,
      "createdAt": "2026-10-24T09:12:03Z"
    },
    {
      "runId": "0192f6af-11c4-7a0e-9b52-3d7e8f1a2c64",
      "provider": "coingecko",
      "method": "GET",
      "path": "/simple/price",
      "status": "FAILED",
      "providerResponse": { "httpStatus": 502 },
      "cost": { "value": 0, "currency": "USD" },
      "durationMs": 10012,
      "createdAt": "2026-10-24T09:10:47Z",
      "errorOrigin": "UPSTREAM"
    }
  ],
  "cursor": "MjAyNi0xMC0yNFQwOToxMDo0Ny4…"
}
调用字段
statusCOMPLETED | FAILED
记录的 HTTP 状态码大于等于 400 时为 FAILED。
pathstring
实际调用的路径(具体路径,不是模板)。
errorOriginUPSTREAM | USER | GATEWAY
失败调用:失败原因来自哪一方。

使用 async=1 时,每项包含 runId、async: true、provider、method、endpoint(模板)、status、cost、createdAt,结束后还有 finishedAt。

获取运行

GET/v1/runs/{runId}
路径参数
runIdstring必填
调用 id(来自 X-Pikeway-Call-Id 或同步运行)或异步运行 id(run_…)。
bash
curl https://gw.pikeway.ai/v1/runs/run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87 \
  -H "Authorization: Bearer $PIKEWAY_API_KEY"

异步运行

200 OK
{
  "runId": "run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87",
  "async": true,
  "provider": "birdeye",
  "method": "GET",
  "endpoint": "/defi/price",
  "status": "COMPLETED",
  "input": { "address": "So11111111111111111111111111111111111111112" },
  "providerResponse": { "httpStatus": 200 },
  "output": { "success": true, "data": { "value": 172.41 } },
  "callId": "0192f6b3-7a10-7e22-a4c5-1b2d3e4f5a6b",
  "cost": { "value": 0.001, "currency": "USD" },
  "timeoutSeconds": 120,
  "createdAt": "2026-10-24T09:20:00Z",
  "startedAt": "2026-10-24T09:20:00Z",
  "finishedAt": "2026-10-24T09:20:01Z",
  "durationMs": 640,
  "pollUrl": "https://gw.pikeway.ai/v1/runs/run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87"
}
statusstring
QUEUED → RUNNING → COMPLETED | FAILED | STOPPED | TIMED_OUT。
outputany
提供方 body:JSON,非 JSON 时为字符串。超过 2 MB 会被截断(error 中会注明)。
errorstring
未完成的原因,如 stopped by user、run exceeded its timeout,或网关的拒绝消息(如 insufficient balance)。
callIdstring
实际发起调用后,对应的底层调用 id。

调用

对于调用 id,返回与列表相同的字段。只有提供方开启了详细日志时才会保留响应 body,此时 output 为前 4 KB;否则 outputRetained 为 false。如果之后还需要输出,请在调用时自行保存。

200 OK
{
  "runId": "0192f6b0-5e2a-7d40-b1c3-8f9e2a4d6c11",
  "provider": "birdeye",
  "method": "GET",
  "path": "/defi/price",
  "status": "COMPLETED",
  "providerResponse": { "httpStatus": 200 },
  "cost": { "value": 0.001, "currency": "USD" },
  "durationMs": 214,
  "createdAt": "2026-10-24T09:12:03Z",
  "outputRetained": false
}

停止运行

POST/v1/runs/{runId}/stop

停止排队中或运行中的异步运行。上游请求会被取消,不扣费。返回 202 和运行的最终状态(通常为 STOPPED)。

bash
curl -X POST https://gw.pikeway.ai/v1/runs/run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87/stop \
  -H "Authorization: Bearer $PIKEWAY_API_KEY"
202 Accepted
{ "runId": "run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87", "status": "STOPPED" }

错误

  • 401 missing API key (Authorization: Bearer pk-...) · invalid or revoked API key · 403 key 限制
  • 404 run not found · run not found (only async runs can be stopped)
  • 405 use GET (or POST /v1/runs/<id>/stop)
  • 409 {"code": 409, "message": "run already finished", "status": "COMPLETED"} 停止已结束的运行时
分页方式与 /v1/wallet/activities 相同:沿着 cursor 翻页,直到它为 null。