调用端点
用 provider、endpoint 和结构化输入调用任意端点。Pikeway 负责拼出 URL、查询参数和 body,经网关按正常计费流程执行,并把结果包装成一个 run 对象。默认同步;耗时任务可在后台运行。
鉴权
Authorization: Bearer pk-…。计费与 /gw 完全一致:只有上游成功(2xx)的响应才扣费。
Body
providerstring必填endpointstring必填methodstringinputobjectasyncboolean202。提供方标记为长任务的端点总是异步执行。timeoutSecondsintegerinput 的两种写法
结构化:包含 pathParams、queryParams、body 中的任意几个,与 /v1/inspect 返回的 schema 对应。queryParams 中的数组值会变成重复参数。
{ "pathParams": { "id": "42" }, "queryParams": { "limit": 10 }, "body": { "...": "..." } }扁平:一个普通对象。与路径占位符同名的键填入路径;其余键在 GET/DELETE/HEAD 时作为查询参数,其他方法时作为 JSON body。
{ "address": "So11111111111111111111111111111111111111112" }会先检查必填的路径和查询参数;缺失时直接返回 400,带缺失列表和完整输入 schema,不会调用也不会扣费。
请求示例
curl -X POST https://gw.pikeway.ai/v1/run \
-H "Authorization: Bearer $PIKEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"provider": "birdeye",
"endpoint": "/defi/price",
"input": { "address": "So11111111111111111111111111111111111111112" }
}'响应
同步运行的 HTTP 状态码就是提供方的状态码。响应码低于 400 时 status 为 COMPLETED,否则为 FAILED;output 是提供方的 body(解析后的 JSON,或字符串)。
{
"runId": "0192f6b0-5e2a-7d40-b1c3-8f9e2a4d6c11",
"provider": "birdeye",
"endpoint": "/defi/price",
"method": "GET",
"status": "COMPLETED",
"output": { "success": true, "data": { "value": 172.41, "updateUnixTime": 1761297120 } },
"providerResponse": { "httpStatus": 200, "contentType": "application/json", "cache": "" },
"price": { "type": "PER_CALL", "amount": { "value": 0.001, "currency": "USD" }, "notes": ["charged only when the upstream call succeeds (HTTP 2xx)"] },
"cost": { "value": 0.001, "currency": "USD" },
"durationMs": 214,
"hints": { "get": "curl -s https://gw.pikeway.ai/v1/runs/0192f6b0-5e2a-7d40-b1c3-8f9e2a4d6c11 -H 'Authorization: Bearer $PIKEWAY_API_KEY'" }
}runIdstringstatusCOMPLETED | FAILEDoutputanyproviderResponseobjectprice · costobjectdurationMsinteger响应头 X-Pikeway-Call-Id、X-Pikeway-Cost、X-Pikeway-Cache 和 X-Pikeway-Byok 从底层调用复制过来。
{"error": "insufficient balance", "statusCode": 402}。异步运行
传 "async": true 会立即得到 202 Accepted。调用在后台按同样的网关流程执行;轮询 GET /v1/runs/{runId},直到 status 不再是 QUEUED 或 RUNNING。异步运行需要 key,保留 7 天;超时、被停止或失败都不扣费。
curl -X POST https://gw.pikeway.ai/v1/run \
-H "Authorization: Bearer $PIKEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"provider": "birdeye", "endpoint": "/defi/price", "input": {"address": "So111…"}, "async": true, "timeoutSeconds": 120}'{
"runId": "run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87",
"status": "QUEUED",
"provider": "birdeye",
"endpoint": "/defi/price",
"method": "GET",
"timeoutSeconds": 120,
"price": { "type": "PER_CALL", "amount": { "value": 0.001, "currency": "USD" }, "notes": ["…"] },
"pollUrl": "https://gw.pikeway.ai/v1/runs/run_5f0c2b7e9a4d4e1b8c3a6f2d1e0b9a87",
"hints": {
"get": "curl -s https://gw.pikeway.ai/v1/runs/run_5f0c… -H 'Authorization: Bearer $PIKEWAY_API_KEY'",
"stop": "curl -s -X POST https://gw.pikeway.ai/v1/runs/run_5f0c…/stop -H 'Authorization: Bearer $PIKEWAY_API_KEY'"
}
}异步运行的 id 以 run_ 开头。最终状态:COMPLETED、FAILED、STOPPED、TIMED_OUT。输出最多保存 2 MB。
错误
400missing required input(见下) ·provider and endpoint are required (see POST /v1/discover)·body must be JSON400async runs need an API key (x402 pays per synchronous run)401missing API key (Authorization: Bearer pk-...)·invalid or revoked API key403自带 key 的 API 但你没有配置 key:{"code": 403, "message": "…", "byok": true, "signupUrl": "…"}404unknown provider: …·unknown endpoint … on …(带 available)405use POST- 网关层拒绝(402、429、503……),格式见 网关错误格式。
{
"code": 400,
"message": "missing required input",
"missing": ["queryParams.address"],
"input": { "queryParams": { "type": "object", "properties": { "address": { "type": "string" } }, "required": ["address"] } }
}