---
title: 最初の API リクエストを送る
description: curl と Orchestor CLI で画像モデルの一覧を取得します。
canonical_url: https://orchestor.io/docs/rest-api/getting-started
markdown_url: https://orchestor.io/docs/rest-api/getting-started.md
related:
  - https://orchestor.io/docs/cli
  - https://orchestor.io/docs/rest-api/endpoint-reference/models/get-list-image-models
  - https://orchestor.io/docs/cli/installation
  - https://orchestor.io/docs/errors
  - https://orchestor.io/docs/concepts/rate-limits
contentType: guide
---

# 最初の API リクエストを送る

データの変更や残高の消費なしで Orchestor API から画像モデル一覧を curl で取得し、続けて CLI でも同じリクエストを送ります。

## 用意するもの

- API キーを作成できる Orchestor ワークスペース
- Bash または Zsh と、`--fail-with-body` に対応する curl 7.76.0 以降

## REST と CLI の使い分け

| 方法 | 使う場面 |
| --- | --- |
| REST API（curl） | HTTP リクエストを直接送り、ステータスとレスポンス本文を確認する。 |
| [Orchestor CLI](https://orchestor.io/docs/cli.md) | ターミナルやシェルスクリプトからコマンドで同じ操作を行う。 |

## ワークスペース用の API キーを作る

> **API キーは秘密情報です**
> 
> キーはサーバー側で管理し、ブラウザー向けのコード、ログ、ソース管理への混入を防いでください。

1. **API キーの作成画面を開く**
   使うワークスペースを選び、[API キー](https://platform.orchestor.io/api-keys)で新しいシークレットキーの作成画面を開きます。名前に `first-api-request` などを入力します。
2. **適用範囲と権限を選ぶ**
   適用範囲は「現在の Workspace」、キーの種別は「読み取り専用」を選び、キーを作成します。
3. **キーをシェルに読み込む**
   次のコマンドを実行し、作成時に表示されたキーを貼り付けて Enter を押します。入力は画面に表示されません。

   ```bash title="terminal"
   read -rs ORCHESTOR_API_KEY && export ORCHESTOR_API_KEY
   ```

## curl でリクエストを送る

同じシェルで画像モデルの一覧を取得します。curl は HTTP ステータスを表示し、レスポンス本文を `image-models.json`、ヘッダーを `image-models.headers` に保存します。

```bash title="terminal"
curl --fail-with-body --silent --show-error \
  --output image-models.json \
  --dump-header image-models.headers \
  --write-out "HTTP %{http_code}\n" \
  --header "Authorization: Bearer $ORCHESTOR_API_KEY" \
  https://api.orchestor.io/v1/image-router/models
```

成功すると、次のステータスが表示されます。

```text title="terminal"
HTTP 200
```

ファイルの `data.models` に、モデル ID、名前、対応機能、料金情報が入ります。各フィールドは [画像モデル一覧のレスポンス](https://orchestor.io/docs/rest-api/endpoint-reference/models/get-list-image-models.md)で確認できます。

## CLI で同じリクエストを送る

1. **Orchestor CLI をインストールする**
   macOS または Linux では次のコマンドを実行します。Windows での手順は [CLI のインストール](https://orchestor.io/docs/cli/installation.md)を参照してください。

   ```bash title="terminal"
   curl -fsSL https://orchestor.io/install | sh
   ```
2. **画像モデルの一覧を表示する**
   `ORCHESTOR_API_KEY` を設定したシェルで実行します。CLI は同じキーを使い、画像モデルの一覧を JSON で表示します。

   ```bash title="terminal"
   orc image models list --json
   ```

## API キーの適用範囲

| 項目 | このガイドで作成したキー |
| --- | --- |
| ワークスペース | 作成時に選んだワークスペースに紐づきます。 |
| 権限 | 公開 API の読み取りに使えます。画像の生成には書き込み権限が必要です。 |
| `X-Workspace-ID` | このリクエストでは省略できます。指定する場合はキーのワークスペース ID と一致させます。 |

## 401、403、429 が返ったとき

curl が保存したレスポンス本文の `error.code` を確認します。

| ステータス | 原因 | 確認すること |
| --- | --- | --- |
| `401` | キーが無効または未指定です（`auth_required`）。認証ヘッダーの併用でも発生します。 | `ORCHESTOR_API_KEY` を確認し、`Authorization: Bearer` または `x-api-key` のどちらか一方を送ります。 |
| `403` | `workspace_mismatch`。指定したワークスペースがキーの適用範囲と一致しません。 | `X-Workspace-ID` を外すか、対象ワークスペースのキーを使います。 |
| `429` | `rate_limit_exceeded`。API キーのリクエスト上限に達しました。 | `Retry-After` に示された秒数を待ってから再試行します。 |

ほかのエラーと再試行の条件は [エラーと再試行](https://orchestor.io/docs/errors.md)と [レート制限](https://orchestor.io/docs/concepts/rate-limits.md)を参照してください。

## 画像生成リクエストの形式

画像の生成には書き込み権限のある API キーが必要で、ワークスペースの残高を消費します。次は非同期の生成リクエストの形式です。

```http title="terminal"
POST /v1/image-router/generate
Authorization: Bearer <API_KEY>
Content-Type: application/json
Idempotency-Key: <UNIQUE_KEY>

{"model":"gpt-image-2","prompt":"朝の光が差す机の上の陶器","mode":"async"}
```

受付レスポンスから `data.job.id`、`data.status_url`、`data.result_url` を取得します。`GET /v1/jobs/{id}/status` を指定された間隔で取得し、`COMPLETED` かつ `result_ready` が `true` なら `GET /v1/jobs/{id}/result` で結果を取得します。失敗や取り消しの状態でもポーリングを終了します。

生成から結果取得までの手順は [クイックスタート](https://orchestor.io/docs/quickstart.md)を参照してください。再送と完了確認の設定は [冪等性キー](https://orchestor.io/docs/concepts/idempotency.md)、[ポーリング](https://orchestor.io/docs/concepts/polling.md)、[Webhook の設定](https://orchestor.io/docs/webhooks.md)で確認できます。

## このガイドで確認したこと

ワークスペースに紐づく読み取り専用キーで、curl と CLI のどちらからも画像モデルの一覧を取得できます。生成に進むときは、一覧のモデル ID と対応機能を使ってリクエストを組み立てます。

## リファレンスを読む

- [REST API の概要](https://orchestor.io/docs/rest-api.md)
- [ジョブの状態を取得](https://orchestor.io/docs/rest-api/requests/get-request-status.md)
- [Orchestor MCP](https://orchestor.io/docs/mcp.md)

---

- [Documentation index](https://orchestor.io/docs/llms.txt)
- [Documentation sitemap](https://orchestor.io/docs/sitemap.md)
