AI Gateway logs.list() filters parameter is silently ignored due to qs serialization with arrayFormat: 'repeat'

オープン
#2,723 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
api, tooling

調査の方向性

src/index.ts:480 から始め、stringifyQuery override を読み、その qs 出力を issue に示されている JSON エンコードされたフィルターと比較します。client.aiGateway.logs.list()、logs.delete()、datasets.list() を追跡して、どのメソッドがこのパラメーターを使用するかを特定します。完了の条件は、フィルター配列が API リクエスト内でオブジェクト構造を保持し、すべての logs ではなく一致する logs が返されることです。

索引モデルが issue の本文から書いたものです。

説明

Description

The client.aiGateway.logs.list() method accepts a typed filters parameter (Array<LogListParams.Filter>), but the filters are silently ignored by the API because stringifyQuery serializes them in a format the API doesn't understand.

Root cause

The Cloudflare SDK overrides stringifyQuery in src/index.ts:480:

protected override stringifyQuery(query: Record<string, unknown>): string {
    return qs.stringify(query, { allowDots: true, arrayFormat: 'repeat' });
}

With arrayFormat: 'repeat' and allowDots: true, an array of filter objects like:

filters: [
  { key: "metadata.key", operator: "eq", value: ["requestId"] },
  { key: "metadata.value", operator: "eq", value: ["abc-123"] },
]

Gets serialized as:

filters.key=metadata.key&filters.operator=eq&filters.value=requestId&filters.key=metadata.value&filters.operator=eq&filters.value=abc-123

This flat serialization loses the array structure — the API can't determine which key belongs to which operator/value. The result is the API ignoring the filters entirely and returning all logs.

The correct format (which works when using fetch directly) is JSON-encoded:

filters=%5B%7B%22key%22%3A%22metadata.key%22%2C%22operator%22%3A%22eq%22%2C%22value%22%3A%5B%22requestId%22%5D%7D%2C...%5D

i.e. filters=[{"key":"metadata.key","operator":"eq","value":["requestId"]},...]

Reproduction

import Cloudflare from "cloudflare";

const client = new Cloudflare({ apiToken: "..." });

const logs = [];
for await (const log of client.aiGateway.logs.list("my-gateway", {
  account_id: "...",
  filters: [
    { key: "metadata.key", operator: "eq", value: ["requestId"] },
    { key: "metadata.value", operator: "eq", value: ["some-uuid"] },
  ],
})) {
  logs.push(log);
}

console.log(logs.length);
// Expected: 1 (only matching logs)
// Actual: ALL logs in the gateway (filters ignored)

Workaround

Use fetch directly with JSON-encoded filters:

const filters = JSON.stringify([
  { key: "metadata.key", operator: "eq", value: ["requestId"] },
  { key: "metadata.value", operator: "eq", value: [requestId] },
]);
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai-gateway/gateways/${gatewayId}/logs?filters=${encodeURIComponent(filters)}`;

const res = await fetch(url, {
  headers: { Authorization: `Bearer ${apiToken}` },
});

Affected methods

This likely affects any method using the filters query parameter with arrays of objects:

  • client.aiGateway.logs.list()
  • client.aiGateway.logs.delete()
  • client.aiGateway.datasets.list() (if it uses the same filter format)

Environment

  • SDK version: [email protected]
  • Runtime: Cloudflare Workers (also reproducible in Node.js)
主要言語
TypeScript
スター
835
フォーク
201
平均マージ
41分
マージ済み PR(30日)
1

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudflare/cloudflare-typescript のほかの issue

cloudflare/cloudflare-typescript の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。