> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Call のクエリするとエクスポート

> Python SDK、REST API、または Weights & Biases UI を使用して Weave call データをフィルター、ソート、エクスポートし、カスタム分析を行います。

このページでは、Weave の外部でトレースデータを分析できるように、Weave Call をクエリするおよびエクスポートする方法を説明します。たとえば、カスタムダッシュボードの構築、共同作業者との結果共有、オフライン分析の実行などが可能です。Weights & Biases UI から Call をエクスポートしたり、Python または TypeScript SDK を使用してプログラムで取得したり、サービス API を使用して直接クエリするしたりできます。

<h2 id="export-calls-from-the-weights-biases-ui">
  Weights & Biases UI から Call をエクスポートする
</h2>

Weights & Biases UI では、データを複数の形式でエクスポートできます。UI には、行をプログラムでエクスポートするために使用できる Python および cURL コードも表示されます。

Call をエクスポートするには:

1. [Forge](https://forge.coreweave.com/wandb) にアクセスし、project を選択します。
2. Weave プロジェクトのサイドバーで、**トレース** をクリックします。
3. エクスポートする複数の Call を、行をチェックして選択します。
4. **トレース** 表のツールバーで、エクスポートまたはダウンロードボタンをクリックします。
5. **Export** モーダルで、**Selected rows** または **All rows** を選択します。
6. **Export** をクリックします。

<Frame>
  <img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/trace_export_modal.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=a3c901c90f54705ac87785acb9c5984e" alt="選択した Call が Export モーダルでエクスポート可能になった状態の トレース ページ。" width="1514" height="440" data-path="products/wandb/weave/_media/trace_export_modal.png" />
</Frame>

<h2 id="fetch-calls-programmatically">
  Call をプログラムで取得する
</h2>

UI の外で Call をフィルター、ソート、または処理するには、Weave SDK または サービス API のいずれかを使用して取得します。ワークフローに最も適したインターフェースを選択してください。

<Tabs>
  <Tab title="Python">
    Python API を使用して Call を取得するには、[`client.get_calls`](/ja/products/wandb/weave/reference/python-sdk/trace/weave_client#method-get_calls) メソッドを使用します：

    ```python lines theme={"system"}
    import weave

    # クライアントを初期化します
    client = weave.init("your-project-name")

    # Call を取得します
    calls = client.get_calls(filter=...)
    ```
  </Tab>

  <Tab title="TypeScript">
    TypeScript API を使用して Call を取得するには、[`client.getCalls`](/ja/products/wandb/weave/reference/typescript-sdk/interfaces/weaveclient#getcalls) メソッドを使用します：

    ```typescript lines theme={"system"}
    import * as weave from 'weave'

    // クライアントを初期化します
    const client = await weave.init('intro-example')

    // Call を取得します
    const calls = await client.getCalls(filter=...)
    ```
  </Tab>

  <Tab title="HTTP API">
    サービス API は完全なクエリレイヤーを公開します。サービス API を使用して Call を取得するには、[`/calls/stream_query`](/ja/products/wandb/weave/reference/service-api/calls/calls-query-stream) エンドポイントにリクエストを送信します：

    ```bash theme={"system"}
    curl -L 'https://trace.wandb.ai/calls/stream_query' \
    -H 'Content-Type: application/json' \
    -H 'Accept: application/json' \
    -d '{
    "project_id": "string",
    "filter": {
        "op_names": [
            "string"
        ],
        "input_refs": [
            "string"
        ],
        "output_refs": [
            "string"
        ],
        "parent_ids": [
            "string"
        ],
        "trace_ids": [
            "string"
        ],
        "call_ids": [
            "string"
        ],
        "trace_roots_only": true,
        "wb_user_ids": [
            "string"
        ],
        "wb_run_ids": [
            "string"
        ]
    },
    "limit": 100,
    "offset": 0,
    "sort_by": [
        {
        "field": "string",
        "direction": "asc"
        }
    ],
    "query": {
        "$expr": {}
    },
    "include_costs": true,
    "include_feedback": true,
    "columns": [
        "string"
    ],
    "expand_columns": [
        "string"
    ]
    }'
    ```
  </Tab>
</Tabs>

Call のプロパティとフィールドの完全な詳細については、[Call スキーマリファレンス](/ja/products/wandb/weave/guides/tracking/call-schema-reference) を参照してください。

<h2 id="export-call-metrics">
  Call メトリクスのエクスポート
</h2>

集約されたインサイト (コストやレイテンシーの傾向など) が必要で、基盤となる Call レコード自体は不要な場合は、このセクションで説明するメトリクスエンドポイントを使用してください。

Weave サービス API の [POST `/calls/stats` エンドポイント](/ja/products/wandb/weave/reference/service-api/calls/call-stats) を使用して、Call データ自体を取得せずに Call に関するメトリクスを取得することもできます。レイテンシーやコストなどの Call に関する情報を取得し、合計、平均、最小、最大、件数で集約できます。たとえば、次の情報を取得できます。

* トークン使用量の合計
* 平均レイテンシー
* 使用されたトークンの最大値
* コストの合計
* 入力トークンの最小値

このエンドポイントには複数のフィルターオプションが用意されており、指定した時間内やその他のプロパティ (以下など) で作成された Call を対象にできます。

* Op 名
* Trace ID
* Thread ID
* User ID

次の例では、`web_app` という名前の Op から 2 日間に生成された Call を取得する方法を示します。`[YOUR-TEAM-NAME/YOUR-PROJECT-NAME]` をご自身のチーム名と project 名に置き換えてください。

<CodeGroup>
  ```python Python lines {10-11,16-24} theme={"system"}
  import requests
  import json
  import os

  url = "https://trace.wandb.ai/calls/stats"

  payload = {
      "project_id": "[YOUR-TEAM-NAME/YOUR-PROJECT-NAME]",
      "start": "2026-03-01T00:00:00Z",
  # バケットのサイズを秒単位で指定します。
      "granularity": 86400,
      "filter": {
          "trace_roots_only": True,
          "op_names": ["web_app"]
      },
  # メトリクスとその集約関数を指定します
      "usage_metrics": [
          {"metric": "total_tokens", "aggregations": ["sum"]},
          {"metric": "total_cost", "aggregations": ["sum"]}
      ],
      "call_metrics": [
          {"metric": "call_count", "aggregations": ["sum"]},
          {"metric": "error_count", "aggregations": ["sum"]},
          {"metric": "latency_ms", "aggregations": ["avg", "min", "max"], "percentiles": [50, 95, 99]}
      ]
  }

  API_KEY = os.getenv("WANDB_API_KEY")

  response = requests.post(url, json=payload, auth=("api", API_KEY))

  print(json.dumps(response.json(), indent=2))
  ```

  ```typescript TypeScript lines {6-7,13-20} theme={"system"}
  const url = "https://trace.wandb.ai/calls/stats";

  const payload = {
    project_id: "[YOUR-TEAM-NAME/YOUR-PROJECT-NAME]",
    start: "2026-03-01T00:00:00Z",
  // バケットのサイズを秒単位で指定します。
    granularity: 86400,
    filter: {
      trace_roots_only: true,
      op_names: ["web_app"],
    },
  // メトリクスとその集約関数を指定します
    usage_metrics: [
      { metric: "total_tokens", aggregations: ["sum"] },
      { metric: "total_cost", aggregations: ["sum"] },
    ],
    call_metrics: [
      { metric: "call_count", aggregations: ["sum"] },
      { metric: "error_count", aggregations: ["sum"] },
      { metric: "latency_ms", aggregations: ["avg", "min", "max"], percentiles: [50, 95, 99] },
    ],
  };

  const API_KEY = process.env.WANDB_API_KEY!;

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Basic " + btoa(`api:${API_KEY}`),
    },
    body: JSON.stringify(payload),
  });

  const data = await response.json();
  console.log(JSON.stringify(data, null, 2));
  ```
</CodeGroup>

リクエストでは、メトリクスの集約方法も指定します。メトリクスは `sum`, `count`, `avg`, `min`, `max`, `count` で集約できます。

このエンドポイントは JSON オブジェクトを返します。次のレスポンス例では、2 日分のメトリクスを示しています。各日 (バケット) は `usage_buckets` 配列と `call_buckets` 配列内でそれぞれ独自のオブジェクトとして表示されます。各配列はメトリクスを異なる方法で分解します。

* `usage_buckets`: 各日の Call メトリクスを、使用されたモデルごとにグループ化します。
* `call_buckets`: 各日の Call メトリクスを、モデルに関係なくグループ化します。

リクエスト内の granularity フィールド (秒単位) を設定すると、バケットサイズを変更できます。

```json lines theme={"system"}
{
  "start": "2026-03-03T00:00:00Z",
  "end": "2026-03-04T21:34:39.746539Z",
  "granularity": 86400,
  "timezone": "UTC",
  "usage_buckets": [
    {
      "timestamp": "2026-03-03T00:00:00",
      "model": "gpt-4o-2024-08-06",
      "sum_total_tokens": 498.0,
      "sum_input_tokens": 219.0,
      "sum_output_tokens": 279.0,
      "count": 5,
      "sum_total_cost": 0.0033374999156876584
    },
    {
      "timestamp": "2026-03-03T00:00:00",
      "model": "gpt-5-2025-08-07",
      "sum_total_tokens": 0.0,
      "sum_input_tokens": 0.0,
      "sum_output_tokens": 0.0,
      "count": 0,
      "sum_total_cost": 0.0
    },
    {
      "timestamp": "2026-03-04T00:00:00",
      "model": "gpt-4o-2024-08-06",
      "sum_total_tokens": 58.0,
      "sum_input_tokens": 27.0,
      "sum_output_tokens": 31.0,
      "count": 1,
      "sum_total_cost": 0.0003774999904635479
    },
    {
      "timestamp": "2026-03-04T00:00:00",
      "model": "gpt-5-2025-08-07",
      "sum_total_tokens": 427.0,
      "sum_input_tokens": 26.0,
      "sum_output_tokens": 401.0,
      "count": 1,
      "sum_total_cost": 0.00404249989787786
    }
  ],
  "call_buckets": [
    {
      "timestamp": "2026-03-03T00:00:00",
      "sum_call_count": 6,
      "sum_error_count": 1,
      "avg_latency_ms": 1505.6666666666667,
      "min_latency_ms": 525,
      "max_latency_ms": 2524,
      "p50_latency_ms": 1534.0,
      "p95_latency_ms": 2328.5,
      "p99_latency_ms": 2484.9000000000005,
      "count": 6
    },
    {
      "timestamp": "2026-03-04T00:00:00",
      "sum_call_count": 2,
      "sum_error_count": 0,
      "avg_latency_ms": 3645.0,
      "min_latency_ms": 1739,
      "max_latency_ms": 5551,
      "p50_latency_ms": 3645.0,
      "p95_latency_ms": 5360.4,
      "p99_latency_ms": 5512.88,
      "count": 2
    }
  ]
}
```

メトリクスを最大31日間の期間でクエリすることができます。利用可能なオプションの詳細については、[サービス API リファレンス](/ja/products/wandb/weave/reference/service-api/calls/call-stats) を参照してください。
