スコープ契約に関する注意: Public routes enforce API key scopes。必要な grants は スコープリファレンス を参照してください。

ページネーション

list endpoints は opaque cursor pagination を使用します。

Request

page size を制御するには limit を、次の page を取得するには cursor を渡します。cursors は opaque です。parse、edit、construct しないでください。

GET /api/v1/agents?limit=50
GET /api/v1/agents?cursor=opaque_cursor_value&limit=50

Response

list responses は次の envelope を使用します。

{
  "items": [
    {}
  ],
  "pagination": {
    "nextCursor": "opaque_cursor_value"
  }
}

これ以上 page がない場合、pagination.nextCursornull です。 totals は共通の list envelope には含まれません。

Load more loop

async function listAllAgents() {
  const agents = [];
  let cursor;

  do {
    const url = new URL("https://api.voiceagent.example/api/v1/agents");
    url.searchParams.set("limit", "50");

    if (cursor) {
      url.searchParams.set("cursor", cursor);
    }

    const response = await fetch(url, {
      headers: {
        Authorization: `Bearer ${process.env.VOICEAGENT_API_KEY}`,
      },
    });

    const body = await response.json();

    if (!response.ok) {
      throw new Error(`${response.status} ${body.error?.code}: ${body.error?.message}`);
    }

    agents.push(...body.items);
    cursor = body.pagination.nextCursor;
  } while (cursor);

  return agents;
}

cursors は次の page を取得するために必要な期間だけ保存してください。安定した resource IDs ではなく、 data の変化に伴って変わることがあります。