HTTP APIの使い方
アプリケーションをRelvoに接続し、リクエストのライフサイクル全体を扱います。
ベースURLと規約
https://api.relvo.si- JSONは
Content-Type: application/jsonで送ります。本文は64 KiBまで、見積もり・実行・検索・カスタムツールは1 MiBまで、アップロードとチームスキルは16 MiBまでです。 - 成功のレスポンスは
{ "data": … }、エラーは{ "error": … }です。トラブルシューティングを参照してください。 - 日時はISO 8601の文字列、金額は米ドルのmicrosの整数です。ただし
GET /tools/usageのamountCentsは米セントです。 - 8 KiB以上のレスポンスは、
Accept-Encodingを送るとBrotliかgzipで圧縮されます。
リクエストを認証する
APIキー ↗でproject:read・tools:read・tools:execute・executions:readのスコープを持つプロジェクトのキーを作成し、HTTPSでベアラー認証情報として送ります。キーはサーバー側に保管してください。
export RELVO_API_URL="https://api.relvo.si"
export RELVO_API_KEY="rlv_..."GET /tools/projectはキーが属するチームとプロジェクトを返します。基本料金はかかりません。
curl "$RELVO_API_URL/tools/project" \
-H "Authorization: Bearer $RELVO_API_KEY"const api = process.env.RELVO_API_URL;
const headers = { Authorization: `Bearer ${process.env.RELVO_API_KEY}` };
const response = await fetch(`${api}/tools/project`, { headers });
console.log(await response.json());import os
import requests
api = os.environ["RELVO_API_URL"]
headers = {"Authorization": f"Bearer {os.environ['RELVO_API_KEY']}"}
response = requests.get(f"{api}/tools/project", headers=headers)
print(response.json())探す・見積もる・実行する・読む
1つの機能を英語の短い言葉で表してツールを探します。検索は料金付きで候補を返し、summaryをfalseにすると入力スキーマも返します。
curl "$RELVO_API_URL/tools/discover" \
-H "Authorization: Bearer $RELVO_API_KEY" \
-H "Content-Type: application/json" \
--data '{"query":"web search","limit":3}'const found = await fetch(`${api}/tools/discover`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ query: "web search", limit: 3 }),
}).then(response => response.json());
console.log(found.data.tools.map(tool => [tool.name, tool.price.description]));found = requests.post(f"{api}/tools/discover", headers=headers,
json={"query": "web search", "limit": 3}).json()
print([(tool["name"], tool["price"]["description"]) for tool in found["data"]["tools"]])実行するツールと引数そのもので、無料の見積もりを取ります。見積もりは何も実行しません。maximumChargeMicrosがその呼び出しの最大料金です。
curl "$RELVO_API_URL/tools/quote" \
-H "Authorization: Bearer $RELVO_API_KEY" \
-H "Content-Type: application/json" \
--data '{"tool":"web_search","arguments":{"query":"content marketing"}}'const request = { tool: "web_search", arguments: { query: "content marketing" } };
const { data: quote } = await fetch(`${api}/tools/quote`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify(request),
}).then(response => response.json());
console.log(quote.priceVersion, quote.maximumChargeMicros);request = {"tool": "web_search", "arguments": {"query": "content marketing"}}
quote = requests.post(f"{api}/tools/quote", headers=headers, json=request).json()["data"]
print(quote["priceVersion"], quote["maximumChargeMicros"])見積もりのpriceVersionとmaximumChargeMicrosを付けて実行します。終わった実行はHTTP 200、実行中ならHTTP 202を返します。
IDEMPOTENCY_KEY=$(uuidgen)
curl "$RELVO_API_URL/tools/web_search" \
-H "Authorization: Bearer $RELVO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-H "Prefer: wait=25" \
--data '{
"tool": "web_search",
"arguments": { "query": "content marketing" },
"priceVersion": "<見積もりのpriceVersion>",
"maximumChargeMicros": <見積もりのmaximumChargeMicros>
}'import { randomUUID } from "node:crypto";
const idempotencyKey = randomUUID();
const { data: execution } = await fetch(`${api}/tools/${request.tool}`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json", "Idempotency-Key": idempotencyKey, Prefer: "wait=25" },
body: JSON.stringify({ ...request, priceVersion: quote.priceVersion, maximumChargeMicros: quote.maximumChargeMicros }),
}).then(response => response.json());
console.log(execution.id, execution.status);import uuid
idempotency_key = str(uuid.uuid4())
execution = requests.post(
f"{api}/tools/{request['tool']}",
headers={**headers, "Idempotency-Key": idempotency_key, "Prefer": "wait=25"},
json={**request, "priceVersion": quote["priceVersion"], "maximumChargeMicros": quote["maximumChargeMicros"]},
).json()["data"]
print(execution["id"], execution["status"])ステータスがqueued・running・waitingでなくなるまで実行を読みます。outputに結果、chargedMicrosに確定した請求額が入ります。
curl "$RELVO_API_URL/tools/executions/$EXECUTION_ID" \
-H "Authorization: Bearer $RELVO_API_KEY" \
-H "Prefer: wait=25"const active = ["queued", "running", "waiting"];
let current = execution;
while (active.includes(current.status)) {
await new Promise(resolve => setTimeout(resolve, 5000));
({ data: current } = await fetch(`${api}/tools/executions/${current.id}`, {
headers: { ...headers, Prefer: "wait=25" },
}).then(response => response.json()));
}
console.log(current.status, current.chargedMicros, current.output);import time
current = execution
while current["status"] in ("queued", "running", "waiting"):
time.sleep(5)
current = requests.get(f"{api}/tools/executions/{current['id']}",
headers={**headers, "Prefer": "wait=25"}).json()["data"]
print(current["status"], current["chargedMicros"], current["output"])冪等性
送信には、英数字と.・_・:・-からなる8〜128文字のIdempotency-Keyヘッダーが必要です。購入ごとに1つ作り、送る前に保存してください。
- 同じキーで同じ本文を送ると元の実行が返るので、タイムアウト後に再試行しても二重に支払いません。
- 同じキーで別の本文を送ると
409platform_idempotency_key_used_for_another_requestで失敗します。 - 応答を受け取れなかった実行は、本文に
{ "idempotencyKey": "<キー>" }を入れてPOST /tools/executions/recoverに送ると見つかります。data.executionがその実行で、このAPIキーがその冪等キーで作った実行がなければnullです。
結果を待つ
送信は既定で最大10秒待ち、実行が終わった時点で返ります。Prefer: wait=Nで最大N秒(25秒まで)待ち、Prefer: respond-asyncですぐに返します。
実行中ならHTTP 202とRetry-After: 5を返します。同じPreferヘッダーを受け付けるGET /tools/executions/{id}を、5秒以上あけて読みます。同時に多くの待機があると、Relvoが今の状態をすぐに返すことがあります。
エンドポイント
GET /tools/project · project:read
キーのチームとプロジェクト
GET /tools/usage · usage:read
今月のリクエスト数と使用額
GET /tools · tools:read
カタログ全体、または50件までのページ(limit・offset)
POST /tools/discover · tools:read
1つの機能に合うツールの順位
GET /tools/definition/{name} · tools:read
1つのツールの定義
GET /tools/connections · tools:read
プロジェクトの接続
POST /tools/quote · tools:read
無料の見積もり。何も実行しません
POST /tools/{tool} · tools:execute
見積もり額を予約してツールを実行
POST /tools/executions/recover · tools:execute
冪等キーで実行を探す
GET /tools/executions · executions:read
最近の実行(新しい順。status・tool・limit・before)
GET /tools/executions/{id} · executions:read
出力付きの実行
GET /tools/executions/{id}/context · executions:read
結果の要約付きの実行
POST /tools/executions/{id}/result · executions:read
大きな結果の一部を読む
POST /tools/executions/{id}/cancel · tools:execute
進行中の実行に停止を求める
GET /tools/executions/{id}/artifacts/{artifactId}/download · executions:read
成果物の署名付きダウンロードURL
POST /tools/upload · tools:execute
入力ファイルのアップロード/tools/project・/tools/usage・/tools/quote・/tools/executions・/tools/connectionsは/v1以下でも使えます。ワークフロー・トリガー・監視はワークフローとトリガーにまとめています。
復旧できる作りにする
成功以外のレスポンスを処理し、実行IDを自分のジョブ記録に残します。送信済みのリクエストと、完了した結果は別の状態です。
タイムアウトで結果が分からないときは、既存の実行を確認します。そのアクションにもう一度試すのが適切だと確認できてから再試行してください。
結果の扱いはツールの実行を参照してください。