> ## 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.

# Deployment の作成

> Agent を cron スケジュールまたは手動で実行する新しい Deployment を作成します。

`POST /api/v1/cloud/deployments`

新しい Deployment を作成します。Deployment は Agent を cron スケジュール（または手動トリガーのみ）、Environment、各実行時に配信される初期イベントセットにバインドします。新規作成された Deployment は `active` ステータスとなり、スケジュールに従って即座に実行を開始します。

## ヘッダー

| 名称              | 必須 | 値                   |
| --------------- | -- | ------------------- |
| `Authorization` | はい | `Bearer $QODER_PAT` |
| `Content-Type`  | はい | `application/json`  |

## リクエストボディ

| フィールド                   | 型                | 必須  | 説明                                                                                                                                                             |
| ----------------------- | ---------------- | --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`                  | string           | はい  | Deployment 名(最大 256 文字)                                                                                                                                        |
| `description`           | string           | いいえ | 人間が読める説明                                                                                                                                                       |
| `agent`                 | string or object | はい  | Agent 参照。プレーンな文字列 `"agent_xxx"`(最新バージョンを使用) またはオブジェクト `{"id": "agent_xxx", "type": "agent", "version": 2}` で特定バージョンを固定。オブジェクト形式には `type: "agent"` を含める必要があります。 |
| `environment_id`        | string           | はい  | Environment ID(`env_` プレフィックス)                                                                                                                                 |
| `schedule`              | object           | いいえ | Cron スケジュール設定。省略時は手動トリガーのみとなります(レスポンスでは schedule が `null`)。下記 **Schedule オブジェクト** を参照。                                                                         |
| `initial_events`        | array            | はい  | 各実行時に Agent に配信されるイベントの配列(1-50 個)。各イベントには `type` フィールドが必要です。許容タイプ: `user.message`、`user.define_outcome`、`system.message`。                                      |
| `resources`             | array            | いいえ | 各 Session に付加するリソース(例: `github_repository`、`file`、`memory_store`)。デフォルトは `[]`。                                                                                 |
| `vault_ids`             | array            | いいえ | 認証情報を注入する Vault ID リスト。デフォルトは `[]`、最大 50 個。                                                                                                                    |
| `metadata`              | object           | いいえ | カスタムの文字列キーバリューメタデータ(最大 16 キー、キー ≤64 文字、値 ≤512 文字)。値は文字列である必要があります。                                                                                             |
| `environment_variables` | string           | いいえ | この Deployment が作成する Session に注入する Deployment レベルの環境変数。`;` または改行で区切られた `KEY=VALUE` ペア形式。セルフホスト環境ではサポートされません。                                                    |

### Schedule オブジェクト

| フィールド        | 型      | 必須 | 説明                                   |
| ------------ | ------ | -- | ------------------------------------ |
| `type`       | string | はい | `"cron"` である必要があります                  |
| `expression` | string | はい | 標準 5 フィールドの cron 式(例: `"0 9 * * *"`) |
| `timezone`   | string | はい | IANA タイムゾーン(例: `"Asia/Shanghai"`)    |

### 環境変数

`environment_variables` は Session 作成時と同じバリデーションを使用します。変数名は `[A-Za-z_][A-Za-z0-9_]*` に一致する必要があり、予約名/プレフィックスは拒否され、重複キーは拒否され、ペイロード全体のサイズには上限があります。レスポンスはキーでソートされ改行で連結された正規化済みの文字列を返します。

## リクエスト例

```bash theme={null}
curl -X POST "https://api.qoder.com/api/v1/cloud/deployments" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "api-doc-verification-deployment",
    "description": "Deployment created for API documentation verification",
    "agent": "agent_019eb4d4a06d747c865d5800b9c57ae2",
    "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
    "schedule": {
      "type": "cron",
      "expression": "0 9 * * *",
      "timezone": "Asia/Shanghai"
    },
    "initial_events": [
      {
        "type": "user.message",
        "content": [
          {
            "type": "text",
            "text": "Generate today'\''s status report"
          }
        ]
      }
    ],
    "resources": [],
    "vault_ids": [],
    "metadata": {
      "team": "platform"
    },
    "environment_variables": "FEATURE_FLAG=on;LOG_LEVEL=info"
  }'
```

## レスポンス例

**HTTP 200 OK**

```json theme={null}
{
  "agent": {
    "id": "agent_019eb4d4a06d747c865d5800b9c57ae2",
    "type": "agent",
    "version": 1
  },
  "archived_at": null,
  "created_at": "2026-06-14T08:53:32Z",
  "description": "Deployment created for API documentation verification",
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "environment_variables": "FEATURE_FLAG=on\nLOG_LEVEL=info",
  "id": "dep_019ec556114c78f8b60ee34fcb98bf59",
  "initial_events": [
    {
      "content": [
        {
          "type": "text",
          "text": "Generate today's status report"
        }
      ],
      "type": "user.message"
    }
  ],
  "metadata": {
    "team": "platform"
  },
  "name": "api-doc-verification-deployment",
  "paused_reason": null,
  "resources": [],
  "schedule": {
    "expression": "0 9 * * *",
    "timezone": "Asia/Shanghai",
    "type": "cron",
    "upcoming_runs_at": [
      "2026-06-15T01:00:00Z",
      "2026-06-16T01:00:00Z",
      "2026-06-17T01:00:00Z",
      "2026-06-18T01:00:00Z",
      "2026-06-19T01:00:00Z"
    ]
  },
  "status": "active",
  "type": "deployment",
  "updated_at": "2026-06-14T08:53:32Z",
  "vault_ids": []
}
```

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

| フィールド                       | 型              | 説明                                                     |
| --------------------------- | -------------- | ------------------------------------------------------ |
| `id`                        | string         | Deployment の一意識別子(`dep_` プレフィックス)                      |
| `type`                      | string         | 固定値 `"deployment"`                                     |
| `name`                      | string         | Deployment 名                                           |
| `description`               | string or null | 説明                                                     |
| `agent`                     | object         | Agent 参照: `{id, type, version}`                        |
| `environment_id`            | string         | 関連付けられた Environment ID                                 |
| `schedule`                  | object or null | `upcoming_runs_at` を含むスケジュール設定(手動トリガーのみの場合は null)      |
| `schedule.expression`       | string         | Cron 式                                                 |
| `schedule.timezone`         | string         | IANA タイムゾーン                                            |
| `schedule.type`             | string         | 固定値 `"cron"`                                           |
| `schedule.upcoming_runs_at` | array          | 次の 5 回のスケジュール時刻(UTC、ISO 8601)                          |
| `schedule.last_run_at`      | string         | 最終実行時刻(初回実行後に出現)                                       |
| `initial_events`            | array          | 各実行時に配信されるイベント                                         |
| `resources`                 | array          | 付加されたリソース                                              |
| `vault_ids`                 | array          | 関連付けられた Vault ID                                       |
| `metadata`                  | object         | カスタムの文字列キーバリューメタデータ                                    |
| `environment_variables`     | string         | この Deployment が作成する Session に注入される正規化済みの `KEY=VALUE` 行 |
| `status`                    | string         | `"active"` または `"paused"`                              |
| `paused_reason`             | object or null | 構造化された一時停止理由(例: `{"type":"manual"}`)                   |
| `archived_at`               | string or null | アーカイブタイムスタンプ(ISO 8601) または null                        |
| `created_at`                | string         | 作成時刻(ISO 8601)                                         |
| `updated_at`                | string         | 最終更新時刻(ISO 8601)                                       |

## CMA との整合

本エンドポイントは Anthropic CMA の `POST /v1/deployments` 仕様に整合しています。主な差分:

* `agent` フィールドは文字列とオブジェクトの両形式を受け付けます(CMA はオブジェクトのみ)。
* `environment_variables` は Deployment に対する Qoder 拡張です。Deployment テンプレートに保存され、Deployment Run が作成する Session にコピーされます。
* レスポンスの schedule オブジェクトに `upcoming_runs_at`(最大 5 回の将来トリガー時刻) を含みます。

## エラー

| HTTP | type                    | 説明                                                                                                                            |
| ---- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| 400  | `invalid_request_error` | 必須フィールド欠落、`type: "agent"` を含まないオブジェクト形式の `agent`、無効な cron 式、無効な metadata または環境変数、未知のイベントタイプ、または参照先 Agent/Environment がアーカイブ済み |
| 401  | `authentication_error`  | PAT が無効または期限切れ                                                                                                                |
| 404  | `not_found_error`       | Agent または Environment が存在しない                                                                                                  |

完全なエラーエンベロープについては [エラー](/ja/cloud-agents/api/conventions/errors) を参照してください。

## 関連項目

<CardGroup cols={2}>
  <Card title="Deployment 一覧" icon="list" href="/ja/cloud-agents/api/deployments/list">
    アカウント配下のすべての Deployment をページ単位で取得します。
  </Card>

  <Card title="Deployment の更新" icon="code" href="/ja/cloud-agents/api/deployments/update">
    マージパッチで Deployment のフィールドを部分更新します。
  </Card>

  <Card title="Deployment の実行" icon="play" href="/ja/cloud-agents/api/deployments/run">
    手動トリガーで Deployment Run を即座に開始します。
  </Card>

  <Card title="エラー" icon="circle-exclamation" href="/ja/cloud-agents/api/conventions/errors">
    共通のエラーエンベロープ仕様を参照します。
  </Card>
</CardGroup>
