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

# AI コード指標 & 追跡

> AI コーディング統計、ランキング、リポジトリ、拡張子、コミット帰属、詳細・エクスポート API。

## このドキュメントについて

**AI コード指標**（集計統計）と **AI コード追跡**（詳細および CSV エクスポート）。セクションによりページネーション方式が異なります。事前に **[API キーの取得](/ja/account/teams/openapi/get-api-key)** を完了し、**[共通仕様](/ja/account/teams/openapi/conventions)** を参照してください。

### 前提条件

* 組織に紐づく有効な API キー（`Authorization: Bearer <api_key>`）。

## 概要

AI コード指標 API は、組織レベルの AI アシストコーディング統計を提供します。コード統計概要、日次トレンド、メンバーランキング、リポジトリ一覧、ファイル拡張子統計を含みます。

### 主な機能

* **統計概要**: コミットコードにおける AI 貢献の総量とシェア

* **日次トレンド**: AI コードシェアの日次推移、Agent コードの言語別統計、Tab 補完受入率

* **メンバーランキング**: AI コード貢献量によるメンバーランキング

* **リポジトリ一覧**: AI コードアクティビティのあるリポジトリの一覧

* **ファイル拡張子**: ファイルタイプ別の AI コード指標

* **コミット詳細**: コミットレベルの AI コード帰属詳細の取得（ファイルレベルの行範囲アノテーション）

***

## 共通クエリパラメータ

以下のパラメータはすべての AI Code エンドポイントに適用されます（必須状況は各エンドポイントを参照）：

| パラメータ                 | 型      | 説明                                  |
| --------------------- | ------ | ----------------------------------- |
| `start_date`          | string | 開始時間；RFC 3339 形式または Unix ミリ秒タイムスタンプ |
| `end_date`            | string | 終了時間；RFC 3339 形式または Unix ミリ秒タイムスタンプ |
| `repo_name`           | string | リポジトリ名でフィルタ                         |
| `primary_branch_only` | string | `true` に設定するとプライマリブランチのみを集計         |
| `user_id`             | string | ユーザー ID でフィルタ                       |
| `file_extensions`     | string | ファイル拡張子でフィルタ、カンマ区切り（例：`.go,.ts`）    |

***

## API 一覧

### 1. AI コード統計概要取得

`GET /v1/organizations/{organization_id}/ai-code/stats/overview`

組織の AI コード全体統計を取得します。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。特に：

| パラメータ        | 必須 | 説明   |
| ------------ | -- | ---- |
| `start_date` | はい | 開始時間 |
| `end_date`   | はい | 終了時間 |

> `start_date` と `end_date` は両方必須で、期間は 90 日以内である必要があります。

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "committedTotalLinesEdit": 50000,
  "committedAiLinesEdit": 15000,
  "acceptedLinesEdit": 18000,
  "aiShareRate": 30.0,
  "agentEditCount": 1200,
  "tabCompletionCount": 5600,
  "messageCount": 3400
}
```

#### レスポンスフィールド

| フィールド                     | 型       | 説明                           |
| ------------------------- | ------- | ---------------------------- |
| `committedTotalLinesEdit` | int64   | コミット済みコード総編集行数（追加 + 削除）      |
| `committedAiLinesEdit`    | int64   | コミット済みコード中の AI 編集行数（追加 + 削除） |
| `acceptedLinesEdit`       | int64   | 受け入れ済み AI 編集行数（追加 + 削除）      |
| `aiShareRate`             | float64 | AI コードシェア（パーセンテージ）           |
| `agentEditCount`          | int64   | Agent 編集回数                   |
| `tabCompletionCount`      | int64   | Tab 補完回数                     |
| `messageCount`            | int64   | チャットメッセージ数                   |

***

### 2. AI コード日次トレンド取得

`GET /v1/organizations/{organization_id}/ai-code/stats/daily-trend`

AI コードの日次トレンドデータを取得します。3 つのデータセット：AI コードシェアトレンド、言語分布トレンド、Tab 補完受入率トレンドを含みます。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。特に：

| パラメータ        | 必須 | 説明   |
| ------------ | -- | ---- |
| `start_date` | はい | 開始時間 |
| `end_date`   | はい | 終了時間 |

> `start_date` と `end_date` は両方必須で、期間は 90 日以内である必要があります。

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "items": [
    {
      "date": "2025-06-01T00:00:00Z",
      "aiLinesAdded": 500,
      "otherLinesAdded": 1500,
      "aiShareRate": 25.0,
      "commitCount": 30
    }
  ],
  "extItems": [
    {
      "date": "2025-06-01T00:00:00Z",
      "fileExtension": ".go",
      "totalLinesAdded": 800,
      "aiLinesAdded": 300
    }
  ],
  "nextItems": [
    {
      "date": "2025-06-01T00:00:00Z",
      "nextSuggestedCount": 200,
      "nextAcceptedCount": 120,
      "nextAcceptRate": 60.0
    }
  ]
}
```

#### レスポンスフィールド

**items\[]** — AI コードシェアトレンド（Chart 1）

| フィールド             | 型       | 説明                 |
| ----------------- | ------- | ------------------ |
| `date`            | string  | 日付（ISO 8601）       |
| `aiLinesAdded`    | int64   | AI 追加行数            |
| `otherLinesAdded` | int64   | 非 AI 追加行数          |
| `aiShareRate`     | float64 | AI コードシェア（パーセンテージ） |
| `commitCount`     | int64   | コミット数              |

**extItems\[]** — Agent コード言語別分布トレンド（Chart 2）

| フィールド             | 型      | 説明           |
| ----------------- | ------ | ------------ |
| `date`            | string | 日付（ISO 8601） |
| `fileExtension`   | string | ファイル拡張子      |
| `totalLinesAdded` | int64  | 総追加行数        |
| `aiLinesAdded`    | int64  | AI 追加行数      |

**nextItems\[]** — Tab 補完受入率トレンド（Chart 3）

| フィールド                | 型       | 説明           |
| -------------------- | ------- | ------------ |
| `date`               | string  | 日付（ISO 8601） |
| `nextSuggestedCount` | int64   | 提案回数         |
| `nextAcceptedCount`  | int64   | 受入回数         |
| `nextAcceptRate`     | float64 | 受入率（パーセンテージ） |

***

### 3. メンバー AI コードランキング取得

`GET /v1/organizations/{organization_id}/ai-code/stats/member-ranking`

AI コード貢献量による組織メンバーのランキングを取得します。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。特に：

| パラメータ        | 必須 | 説明   |
| ------------ | -- | ---- |
| `start_date` | はい | 開始時間 |
| `end_date`   | はい | 終了時間 |

> `start_date` と `end_date` は両方必須で、期間は 90 日以内である必要があります。

追加サポート：

| パラメータ   | 型       | 必須  | デフォルト | 説明        |
| ------- | ------- | --- | ----- | --------- |
| `limit` | integer | いいえ | 10    | 返す最大メンバー数 |

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "items": [
    {
      "userId": "user_abc123",
      "email": "alice@example.com",
      "displayName": "Alice",
      "totalLinesAdded": 5000,
      "aiLinesAdded": 2000,
      "aiShareRate": 40.0,
      "commitCount": 50
    }
  ]
}
```

#### レスポンスフィールド

| フィールド                     | 型       | 説明                 |
| ------------------------- | ------- | ------------------ |
| `items`                   | array   | メンバーランキングリスト       |
| `items[].userId`          | string  | ユーザー ID            |
| `items[].email`           | string  | メンバーメール（空の場合あり）    |
| `items[].displayName`     | string  | 表示名（空の場合あり）        |
| `items[].totalLinesAdded` | int64   | 総追加行数              |
| `items[].aiLinesAdded`    | int64   | AI 追加行数            |
| `items[].aiShareRate`     | float64 | AI コードシェア（パーセンテージ） |
| `items[].commitCount`     | int64   | コミット数              |

***

### 4. リポジトリ一覧

`GET /v1/organizations/{organization_id}/ai-code/repos`

組織内の AI コードアクティビティのあるリポジトリを一覧表示します。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

| パラメータ        | 型       | 必須  | デフォルト | 説明                |
| ------------ | ------- | --- | ----- | ----------------- |
| `start_date` | string  | いいえ | —     | 開始時間              |
| `end_date`   | string  | いいえ | —     | 終了時間              |
| `query`      | string  | いいえ | —     | リポジトリ名で検索         |
| `page`       | integer | いいえ | 1     | ページ番号（1 から開始）     |
| `per_page`   | integer | いいえ | 30    | 1ページあたりの件数、最大 100 |

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "repos": [
    {
      "repoName": "my-project",
      "commitCount": 120,
      "totalLinesAdded": 8000
    }
  ],
  "totalCount": 42,
  "page": 1,
  "perPage": 30
}
```

#### レスポンスフィールド

| フィールド                     | 型      | 説明         |
| ------------------------- | ------ | ---------- |
| `repos`                   | array  | リポジトリリスト   |
| `repos[].repoName`        | string | リポジトリ名     |
| `repos[].commitCount`     | int64  | コミット数      |
| `repos[].totalLinesAdded` | int64  | 総追加行数      |
| `totalCount`              | int32  | 総リポジトリ数    |
| `page`                    | int32  | 現在のページ番号   |
| `perPage`                 | int32  | 1ページあたりの件数 |

***

### 5. ファイル拡張子一覧

`GET /v1/organizations/{organization_id}/ai-code/file-extensions`

組織内の AI コードアクティビティのファイル拡張子統計を一覧表示します。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

| パラメータ        | 型      | 必須  | 説明   |
| ------------ | ------ | --- | ---- |
| `start_date` | string | いいえ | 開始時間 |
| `end_date`   | string | いいえ | 終了時間 |

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "fileExtensions": [
    {
      "extension": ".go",
      "changeCount": 500,
      "totalLinesAdded": 12000,
      "aiShareRate": 35.5
    }
  ]
}
```

#### レスポンスフィールド

| フィールド                              | 型       | 説明                 |
| ---------------------------------- | ------- | ------------------ |
| `fileExtensions`                   | array   | ファイル拡張子リスト         |
| `fileExtensions[].extension`       | string  | ファイル拡張子            |
| `fileExtensions[].changeCount`     | int64   | 変更回数               |
| `fileExtensions[].totalLinesAdded` | int64   | 総追加行数              |
| `fileExtensions[].aiShareRate`     | float64 | AI コードシェア（パーセンテージ） |

***

### 6. コミット AI 帰属詳細取得

`POST /v1/organizations/{organization_id}/ai-code-tracking/commits/detail`

コミットレベルの AI コード帰属詳細を一括取得します。ファイルレベルの行範囲アノテーションを含みます。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### リクエストボディ（JSON）

| フィールド          | 型         | 必須  | 説明                 |
| -------------- | --------- | --- | ------------------ |
| `commitHashes` | string\[] | はい  | コミットハッシュリスト（最大 50） |
| `branch`       | string    | いいえ | ブランチ名（クエリ範囲の制限用）   |

#### リクエスト例

```json theme={null}
{
  "commitHashes": ["abc123def456", "789ghi012jkl"],
  "branch": "main"
}
```

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "success": true,
  "data": {
    "commits": [
      {
        "commitHash": "abc123def456",
        "rangeAnnotations": [
          {
            "filePath": "src/main.go",
            "groups": [
              {
                "conversationId": "session-001",
                "source": "AGENT",
                "productType": "ide",
                "type": "added",
                "ranges": [
                  { "start": 47, "end": 48 },
                  { "start": 55, "end": 60 }
                ]
              }
            ]
          }
        ]
      },
      {
        "commitHash": "789ghi012jkl",

        "rangeAnnotations": [ ]

      }
    ]
  }
}
```

#### レスポンスフィールド

| フィールド                                                       | 型       | 説明                                      |
| ----------------------------------------------------------- | ------- | --------------------------------------- |
| `success`                                                   | boolean | リクエストが成功したかどうか                          |
| `data.commits`                                              | array   | コミット詳細リスト（リクエスト順序を保持）                   |
| `data.commits[].commitHash`                                 | string  | コミットハッシュ                                |
| `data.commits[].rangeAnnotations`                           | array   | ファイルレベル AI 帰属アノテーション                    |
| `data.commits[].rangeAnnotations[].filePath`                | string  | ファイルパス                                  |
| `data.commits[].rangeAnnotations[].groups`                  | array   | AI セッション貢献グループ                          |
| `data.commits[].rangeAnnotations[].groups[].conversationId` | string  | AI セッション ID                             |
| `data.commits[].rangeAnnotations[].groups[].source`         | string  | ソース：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |
| `data.commits[].rangeAnnotations[].groups[].productType`    | string  | プロダクトタイプ（小文字、例：`ide`）                   |
| `data.commits[].rangeAnnotations[].groups[].type`           | string  | タイプ：`added`（追加）、`deleted`（削除）           |
| `data.commits[].rangeAnnotations[].groups[].ranges`         | array   | 行範囲リスト                                  |
| `data.commits[].rangeAnnotations[].groups[].ranges[].start` | int32   | 開始行番号                                   |
| `data.commits[].rangeAnnotations[].groups[].ranges[].end`   | int32   | 終了行番号                                   |

***

## 使用例

### 統計概要取得

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/stats/overview?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z" \
  -H "Authorization: Bearer <api_key>"
```

### 日次トレンド取得（リポジトリ指定、プライマリブランチ）

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/stats/daily-trend?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z&repo_name=my-project&primary_branch_only=true" \
  -H "Authorization: Bearer <api_key>"
```

### メンバーランキング取得（上位 20）

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/stats/member-ranking?start_date=2025-06-01T00:00:00Z&end_date=2025-06-30T23:59:59Z&limit=20" \
  -H "Authorization: Bearer <api_key>"
```

### リポジトリ検索

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/repos?query=my-project" \
  -H "Authorization: Bearer <api_key>"
```

### ファイル拡張子統計取得

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code/file-extensions?start_date=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>"
```

### コミット AI 帰属詳細取得

```bash theme={null}
curl -X POST "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/commits/detail" \
  -H "Authorization: Bearer <api_key>" \
  -H "Content-Type: application/json" \
  -d '{"commitHashes": ["abc123def456", "789ghi012jkl"], "branch": "main"}'
```

***

## エラーコード

| エラーコード          | HTTP ステータス | 説明                                                                                   |
| --------------- | ---------- | ------------------------------------------------------------------------------------ |
| `BadRequest`    | 400        | リクエストパラメータが無効（例：`start_date` / `end_date` 欠落、期間が 90 日超過、`commitHashes` が空または 50 件超過） |
| `Unauthorized`  | 401        | API キーが欠落または無効                                                                       |
| `Forbidden`     | 403        | この組織へのアクセス権限なし                                                                       |
| `InternalError` | 500        | サーバー内部エラー                                                                            |

エラーレスポンスの形式は [共通仕様](/ja/account/teams/openapi/conventions) の **エラーレスポンス** を参照してください。

***

## AI コード追跡 API

**AI コード指標**（集計統計）に加え、このセクションでは **コミット / チェンジ** レベルの詳細クエリと **CSV エクスポート** を提供します。認証は同じ：`Authorization: Bearer <api_key>`。

使用前に、組織がコンソールと同じ **AI コードデータ分析** 機能を有効にしていることを確認してください。未有効化またはアクセス権限がない場合、API は 403 等のエラーを返す可能性があります。実際のレスポンスを参照してください。フィールドと列挙値は **ライブ API と OpenAPI 定義** に基づきます。本ドキュメントは参考用です。

## 追跡機能

AI コード追跡 API は、コミットレベルとチェンジレベルの明細クエリおよび CSV エクスポート機能を提供し、上記の **AI コード指標**（集計統計）を補完します。

### 2 層データモデル

| レイヤー       | 意味                  | ソース                                 | 利用可能なフィルタディメンション |
| ---------- | ------------------- | ----------------------------------- | ---------------- |
| **Commit** | Git コミット            | コードリポジトリ（リモートにプッシュ済み）               | 時間、ユーザー、リポジトリ    |
| **Change** | IDE 内の AI コード編集イベント | IDE クライアントからの報告（まだ Git コミットになっていない） | 時間、ユーザー、ソース      |

> Change は**まだ Git コミットされていない IDE 内イベント**であるため、`repoName` / `branchName` ディメンションを持ちません。

### プロダクト × シナリオ分解（コミットレベル）

各コミットレコードには **12 ペア** の `linesAdded / linesDeleted` カラムが含まれ、「プロダクト × シナリオ」で分解されます：

| フィールドプレフィックス    | プロダクト           | シナリオ         |
| --------------- | --------------- | ------------ |
| `ideNext`       | IDE（VS Code）    | Tab 補完（next） |
| `pluginNext`    | JetBrains プラグイン | Tab 補完（next） |
| `ideAgent`      | IDE（VS Code）    | Agent        |
| `pluginAgent`   | JetBrains プラグイン | Agent        |
| `cliAgent`      | CLI             | Agent        |
| `ideQuest`      | IDE（VS Code）    | Quest        |
| `ideInlineChat` | IDE（VS Code）    | Inline Chat  |
| `jbInlineChat`  | JetBrains プラグイン | Inline Chat  |
| `nonAi`         | —               | 非 AI 行（帰属不可） |

### 主な機能

* **コミット明細クエリ**: コミットレベルの AI コード統計を一覧表示（プロダクト × シナリオ分解付き）

* **コミット CSV エクスポート**: 全コミットデータをストリーミングエクスポート

* **チェンジ明細クエリ**: IDE 内 AI コード編集イベントを一覧表示（`source` でフィルタ可能）

* **チェンジ CSV エクスポート**: 全チェンジデータをストリーミングエクスポート

* **ユーザーメール**: リストとエクスポートでは利用可能な場合 `userEmail` を付加

* **メールでフィルタ**: `userEmail` クエリパラメータでユーザーを特定可能

### ページネーション

追跡 API は**オフセットベースのページネーション**（`page` + `pageSize`）を使用し、他のエンドポイントで一般的なカーソルベースのページネーションとは異なります。レスポンスには `totalItems` / `totalPages` が含まれ、ページネーション表示に便利です。

***

## 共通クエリパラメータ

以下のパラメータはすべての Tracking エンドポイントに適用されます：

| パラメータ       | 型       | 必須  | デフォルト | 説明                                                                                       |
| ----------- | ------- | --- | ----- | ---------------------------------------------------------------------------------------- |
| `startDate` | string  | いいえ | —     | 開始時間；RFC 3339 形式または Unix ミリ秒タイムスタンプ。未指定時はサーバーがプロダクトポリシーにより照会可能範囲を制約（例：最大約 90 日）。実際の動作に準拠 |
| `endDate`   | string  | いいえ | 現在時刻  | 終了時間；RFC 3339 形式または Unix ミリ秒タイムスタンプ                                                      |
| `userId`    | string  | いいえ | —     | ユーザー UUID でフィルタ                                                                          |
| `userEmail` | string  | いいえ | —     | ユーザーメールでフィルタ（サーバーが対応するユーザー識別子に解決）                                                        |
| `page`      | integer | いいえ | 1     | ページ番号（1 から開始）                                                                            |
| `pageSize`  | integer | いいえ | 100   | 1ページあたりの件数、最大 200                                                                        |

> `userId` と `userEmail` の両方が指定された場合、`userId` が優先されます。

***

## API 一覧

### 1. コミット明細一覧

`GET /v1/organizations/{organization_id}/ai-code-tracking/commits`

コミットレベルの AI コード統計をレコードごとに一覧表示し、コミット時間の降順で並べます。各レコードにはプロダクト × シナリオの分解が含まれます。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。追加：

| パラメータ      | 型      | 必須  | 説明          |
| ---------- | ------ | --- | ----------- |
| `repoName` | string | いいえ | リポジトリ名でフィルタ |

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "success": true,
  "data": {
    "items": [
      {
        "commitHash": "a1b2c3d4e5f6",
        "userId": "550e8400-e29b-41d4-a716-446655440000",
        "userEmail": "alice@example.com",
        "repoName": "my-project",
        "branchName": "main",
        "isPrimaryBranch": true,
        "totalLinesAdded": 120,
        "totalLinesDeleted": 30,
        "ideNextLinesAdded": 40,
        "ideNextLinesDeleted": 10,
        "pluginNextLinesAdded": 0,
        "pluginNextLinesDeleted": 0,
        "ideAgentLinesAdded": 50,
        "ideAgentLinesDeleted": 15,
        "pluginAgentLinesAdded": 0,
        "pluginAgentLinesDeleted": 0,
        "cliAgentLinesAdded": 0,
        "cliAgentLinesDeleted": 0,
        "ideQuestLinesAdded": 10,
        "ideQuestLinesDeleted": 0,
        "ideInlineChatLinesAdded": 5,
        "ideInlineChatLinesDeleted": 2,
        "jbInlineChatLinesAdded": 0,
        "jbInlineChatLinesDeleted": 0,
        "nonAiLinesAdded": 15,
        "nonAiLinesDeleted": 3,
        "message": "feat: add user login",
        "commitTs": "2025-06-15T10:30:00Z",
        "createdAt": "2025-06-15T10:35:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "pageSize": 100,
      "totalItems": 256,
      "totalPages": 3
    }
  }
}
```

#### レスポンスフィールド

**success** — `true` はリクエスト成功を示す

**data.items\[]** — コミット明細リスト

| フィールド                       | 型       | 説明                         |
| --------------------------- | ------- | -------------------------- |
| `commitHash`                | string  | Git コミット SHA               |
| `userId`                    | string  | ユーザー UUID                  |
| `userEmail`                 | string  | ユーザーメール（空の場合あり）            |
| `repoName`                  | string  | リポジトリ名                     |
| `branchName`                | string  | ブランチ名                      |
| `isPrimaryBranch`           | boolean | プライマリブランチかどうか              |
| `totalLinesAdded`           | integer | 総追加行数                      |
| `totalLinesDeleted`         | integer | 総削除行数                      |
| `ideNextLinesAdded`         | integer | IDE Tab 補完追加行数             |
| `ideNextLinesDeleted`       | integer | IDE Tab 補完削除行数             |
| `pluginNextLinesAdded`      | integer | JetBrains プラグイン Tab 補完追加行数 |
| `pluginNextLinesDeleted`    | integer | JetBrains プラグイン Tab 補完削除行数 |
| `ideAgentLinesAdded`        | integer | IDE Agent 追加行数             |
| `ideAgentLinesDeleted`      | integer | IDE Agent 削除行数             |
| `pluginAgentLinesAdded`     | integer | JetBrains プラグイン Agent 追加行数 |
| `pluginAgentLinesDeleted`   | integer | JetBrains プラグイン Agent 削除行数 |
| `cliAgentLinesAdded`        | integer | CLI Agent 追加行数             |
| `cliAgentLinesDeleted`      | integer | CLI Agent 削除行数             |
| `ideQuestLinesAdded`        | integer | IDE Quest 追加行数             |
| `ideQuestLinesDeleted`      | integer | IDE Quest 削除行数             |
| `ideInlineChatLinesAdded`   | integer | IDE Inline Chat 追加行数       |
| `ideInlineChatLinesDeleted` | integer | IDE Inline Chat 削除行数       |
| `jbInlineChatLinesAdded`    | integer | JetBrains Inline Chat 追加行数 |
| `jbInlineChatLinesDeleted`  | integer | JetBrains Inline Chat 削除行数 |
| `nonAiLinesAdded`           | integer | 非 AI 追加行数                  |
| `nonAiLinesDeleted`         | integer | 非 AI 削除行数                  |
| `message`                   | string  | コミットメッセージ（空の場合あり）          |
| `commitTs`                  | string  | コミット時間（ISO 8601）           |
| `createdAt`                 | string  | レコード作成時間（ISO 8601）         |

**data.pagination** — ページネーション情報

| フィールド         | 型       | 説明         |
| ------------- | ------- | ---------- |
| `currentPage` | integer | 現在のページ番号   |
| `pageSize`    | integer | 1ページあたりの件数 |
| `totalItems`  | integer | 総レコード数     |
| `totalPages`  | integer | 総ページ数      |

***

### 2. コミット CSV エクスポート

`GET /v1/organizations/{organization_id}/ai-code-tracking/commits/export`

コミットデータをストリーミング CSV 形式でエクスポートします。サーバーがページネーション集計を自動処理するため、**呼び出し側でのページネーションは不要**です。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。追加：

| パラメータ      | 型      | 必須  | 説明          |
| ---------- | ------ | --- | ----------- |
| `repoName` | string | いいえ | リポジトリ名でフィルタ |

#### 成功レスポンス（200 OK）

* **Content-Type**: `text/csv; charset=utf-8`

* **Content-Disposition**: `attachment; filename="ai-code-commits.csv"`

CSV カラムヘッダー（注：CSV は `userName` を保持、JSON レスポンスでは削除済み）：

```plaintext theme={null}
commitHash,userId,userEmail,userName,repoName,branchName,isPrimaryBranch,
totalLinesAdded,totalLinesDeleted,
ideNextLinesAdded,ideNextLinesDeleted,pluginNextLinesAdded,pluginNextLinesDeleted,
ideAgentLinesAdded,ideAgentLinesDeleted,pluginAgentLinesAdded,pluginAgentLinesDeleted,
cliAgentLinesAdded,cliAgentLinesDeleted,ideQuestLinesAdded,ideQuestLinesDeleted,
ideInlineChatLinesAdded,ideInlineChatLinesDeleted,jbInlineChatLinesAdded,jbInlineChatLinesDeleted,
nonAiLinesAdded,nonAiLinesDeleted,message,commitTs,createdAt
```

***

### 3. チェンジ明細一覧

`GET /v1/organizations/{organization_id}/ai-code-tracking/changes`

IDE 内の AI コード編集イベント（`action=suggested` レコードのみ）をイベント時間降順で一覧表示します。

> Change はまだ Git コミットされていない IDE 内イベントであるため、`repoName` フィルタは**サポートされません**。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。追加：

| パラメータ    | 型      | 必須  | 説明                                                |
| -------- | ------ | --- | ------------------------------------------------- |
| `source` | string | いいえ | 利用シナリオでフィルタ。値：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |

#### 成功レスポンス（200 OK）

```json theme={null}
{
  "success": true,
  "data": {
    "items": [
      {
        "changeId": "chg_abc123",
        "userId": "550e8400-e29b-41d4-a716-446655440000",
        "userEmail": "alice@example.com",
        "source": "AGENT",
        "model": "efficient",
        "totalLinesAdded": 45,
        "totalLinesDeleted": 12,
        "metadata": [
          {
            "fileName": "main.go",
            "fileExtension": ".go",
            "linesAdded": 30,
            "linesDeleted": 8
          },
          {
            "fileName": "utils.go",
            "fileExtension": ".go",
            "linesAdded": 15,
            "linesDeleted": 4
          }
        ],
        "createdAt": "2025-06-15T10:28:00Z"
      }
    ],
    "pagination": {
      "currentPage": 1,
      "pageSize": 100,
      "totalItems": 1024,
      "totalPages": 11
    }
  }
}
```

#### レスポンスフィールド

**success** — `true` はリクエスト成功を示す

**data.items\[]** — チェンジ明細リスト

| フィールド                      | 型       | 説明                                              |
| -------------------------- | ------- | ----------------------------------------------- |
| `changeId`                 | string  | 変更イベント一意識別子                                     |
| `userId`                   | string  | ユーザー UUID                                       |
| `userEmail`                | string  | ユーザーメール（空の場合あり）                                 |
| `source`                   | string  | 利用シナリオ（大文字）：`NEXT`、`AGENT`、`QUEST`、`INLINECHAT` |
| `model`                    | string  | モデルティア：`lite`、`efficient`、`auto`（空の場合あり）        |
| `totalLinesAdded`          | integer | 総追加行数                                           |
| `totalLinesDeleted`        | integer | 総削除行数                                           |
| `metadata`                 | array   | ファイルレベル変更明細（空の場合あり）                             |
| `metadata[].fileName`      | string  | ファイル名                                           |
| `metadata[].fileExtension` | string  | ファイル拡張子                                         |
| `metadata[].linesAdded`    | integer | ファイル追加行数                                        |
| `metadata[].linesDeleted`  | integer | ファイル削除行数                                        |
| `createdAt`                | string  | イベント時間（ISO 8601）                                |

**data.pagination** — ページネーション情報

| フィールド         | 型       | 説明         |
| ------------- | ------- | ---------- |
| `currentPage` | integer | 現在のページ番号   |
| `pageSize`    | integer | 1ページあたりの件数 |
| `totalItems`  | integer | 総レコード数     |
| `totalPages`  | integer | 総ページ数      |

***

### 4. チェンジ CSV エクスポート

`GET /v1/organizations/{organization_id}/ai-code-tracking/changes/export`

チェンジデータをストリーミング CSV 形式でエクスポートします。サーバーがページネーション集計を自動処理するため、**呼び出し側でのページネーションは不要**です。

> CSV エクスポートはフラット形式で、`metadata`（ファイルレベル明細）は含みません。

#### パスパラメータ

| パラメータ             | 型      | 必須 | 説明    |
| ----------------- | ------ | -- | ----- |
| `organization_id` | string | はい | 組織 ID |

#### クエリパラメータ

「共通クエリパラメータ」を参照。追加：

| パラメータ    | 型      | 必須  | 説明                                                |
| -------- | ------ | --- | ------------------------------------------------- |
| `source` | string | いいえ | 利用シナリオでフィルタ。値：`AGENT`、`NEXT`、`QUEST`、`INLINECHAT` |

#### 成功レスポンス（200 OK）

* **Content-Type**: `text/csv; charset=utf-8`

* **Content-Disposition**: `attachment; filename="ai-code-changes.csv"`

CSV カラムヘッダー：

```plaintext theme={null}
changeId,userId,userEmail,source,model,totalLinesAdded,totalLinesDeleted,createdAt
```

***

## 使用例

### コミット明細クエリ（リポジトリでフィルタ）

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/commits?startDate=2025-06-01T00:00:00Z&endDate=2025-06-30T23:59:59Z&repoName=my-project&pageSize=50" \
  -H "Authorization: Bearer <api_key>"
```

### メールでユーザーのコミットをクエリ

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/commits?startDate=2025-06-01T00:00:00Z&userEmail=alice@example.com" \
  -H "Authorization: Bearer <api_key>"
```

### コミット CSV エクスポート

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/commits/export?startDate=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>" \
  -o ai-code-commits.csv
```

### チェンジ明細クエリ（ソースでフィルタ）

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/changes?startDate=2025-06-01T00:00:00Z&source=QUEST&pageSize=50" \
  -H "Authorization: Bearer <api_key>"
```

### チェンジ CSV エクスポート

```bash theme={null}
curl -X GET "https://api.qoder.com/v1/organizations/org_xxx/ai-code-tracking/changes/export?startDate=2025-06-01T00:00:00Z" \
  -H "Authorization: Bearer <api_key>" \
  -o ai-code-changes.csv
```

***

## エラーコード

| エラーコード          | HTTP ステータス | 説明                                                          |
| --------------- | ---------- | ----------------------------------------------------------- |
| `Unauthorized`  | 401        | API キーが欠落または無効                                              |
| `Forbidden`     | 403        | この組織へのアクセス権限なし                                              |
| `BadRequest`    | 400        | リクエストパラメータが無効（例：`organization_id` / `userId` が有効な UUID でない） |
| `InternalError` | 500        | サーバー内部エラー                                                   |

エラーレスポンスの形式は [共通仕様](/ja/account/teams/openapi/conventions) の **エラーレスポンス** を参照してください。
