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

# クイックスタート（API）

> 4つのREST呼び出しで、AIエージェントが最初の電話に応答します。

このガイドでは、AIエージェントで最初の電話に応答するまでに必要な4つのREST呼び出しを説明します。

<Info>
  [ThunderPhoneアカウント](https://app.thunderphone.com)が必要です。
  登録は無料で、1分もかかりません。curlよりクリック操作が好みの場合は、
  [ダッシュボードのクイックスタート](/ja/quickstart-dashboard)でコードを書かずに
  同じ最初の通話まで進めます。
</Info>

## ステップ1: APIキーを取得する

<Steps>
  <Step title="ログイン">
    [app.thunderphone.com](https://app.thunderphone.com)を開きます。
  </Step>

  <Step title="キーに移動">
    ダッシュボードで**組織 → キー**に移動します。
  </Step>

  <Step title="キーを作成">
    **キーを作成**をクリックし、名前を付けて
    `sk_live_...`の値をコピーします。キーの生の値は**一度だけ**表示されるため、すぐに
    シークレットマネージャーへ保存してください。
  </Step>
</Steps>

<Tip>
  困った場合は、[サーバーAPIキーを作成する](/ja/guides/api-keys)で
  この手順をステップごとに詳しく確認できます。また、アプリ内コパイロットが
  各コントロールをリアルタイムでハイライト表示します。
</Tip>

このガイド全体で、`sk_live_YOUR_API_KEY`を先ほどコピーした値に置き換えます。
キーにより組織が自動的に識別されるため、URLに組織IDを指定する必要はありません。

## ステップ2: エージェントを作成する

エージェントは、AIが会話を処理する方法を定義します。これには、プロンプト、音声、
製品ティア、ツール、ウィジェットの利用可否が含まれます。

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.thunderphone.com/v1/agents \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name":   "Customer Support",
      "prompt": "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
      "voice":  "john",
      "product": "spark"
    }'
  ```

  ```python Python theme={null}
  import os, requests

  agent = requests.post(
      "https://api.thunderphone.com/v1/agents",
      headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
      json={
          "name":   "Customer Support",
          "prompt": "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
          "voice":  "john",
          "product": "spark",
      },
  ).json()
  print("Agent id:", agent["id"])
  ```

  ```javascript Node.js theme={null}
  const agent = await fetch("https://api.thunderphone.com/v1/agents", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.THUNDERPHONE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name:    "Customer Support",
      prompt:  "You are a friendly support agent for Acme Corp. Help with orders, returns, and product info. Be concise and helpful.",
      voice:   "john",
      product: "spark",
    }),
  }).then((r) => r.json());
  console.log("Agent id:", agent.id);
  ```
</CodeGroup>

<Tip>
  製品ティア: `spark`はコスト向けに最適化され、`bolt`は速度向け、
  `storm-base` / `storm-extra`は複雑なプロンプトに対する高度な知能向けです。完全な
  比較は[エージェント](/api-reference/agents#product-tiers-at-a-glance)を参照してください。
</Tip>

## ステップ3: 電話番号をプロビジョニングする

この呼び出しは、ThunderPhone のデモプールに番号をリクエストし、新しいエージェントを着信ハンドラーとして割り当てます。（VoIP プロバイダーから独自の番号を持ち込む場合は、[VoIP 接続](/api-reference/voip-connections)を参照してください。）

<CodeGroup>
  ```bash cURL theme={null}
  # First provision
  curl -X POST https://api.thunderphone.com/v1/phone-numbers \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"area_code": "415"}'

  # Then assign the agent you created in Step 2
  curl -X PATCH https://api.thunderphone.com/v1/phone-numbers/<id-from-previous> \
    -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"inbound_agent_id": 12}'
  ```

  ```python Python theme={null}
  number = requests.post(
      "https://api.thunderphone.com/v1/phone-numbers",
      headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
      json={"area_code": "415"},
  ).json()
  requests.patch(
      f"https://api.thunderphone.com/v1/phone-numbers/{number['id']}",
      headers={"Authorization": f"Bearer {os.environ['THUNDERPHONE_API_KEY']}"},
      json={"inbound_agent_id": agent["id"]},
  )
  print("Your ThunderPhone number:", number["number"])
  ```
</CodeGroup>

新しい番号は `status="provisioning"` で開始され、数秒以内に
`active` に移行します。ブラウザを閉じる頃には、その番号で着信を受けられる状態になります。

## ステップ4（任意）: Webhook を設定する

リアルタイムイベント（動的な通話ルーティング、通話後処理）には、
Webhook エンドポイントを追加します。必要なイベントのみを購読してください。

```bash theme={null}
curl -X POST https://api.thunderphone.com/v1/developer/webhook-endpoints \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "label":  "Prod webhook",
    "url":    "https://your-server.com/thunderphone-webhook",
    "events": ["telephony.incoming", "telephony.complete"]
  }'
```

レスポンスには一度だけ表示される `secret` が含まれます。シークレットマネージャーにコピーしてください。
そのシークレットを使用して、受信リクエストの `X-ThunderPhone-Signature`
ヘッダーを検証します（[Webhook の概要](/ja/webhooks/overview)を参照）。

## ステップ5: エージェントをテストする

プロビジョニングした番号に電話をかけます。エージェントが応答して自己紹介し、プロンプトに従います。

通話終了後に通話を確認します。

```bash theme={null}
curl https://api.thunderphone.com/v1/calls \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"
```

特定の通話を詳しく確認し、文字起こしと録音 URL を取得します。

```bash theme={null}
curl https://api.thunderphone.com/v1/calls/{call_id}/transcript \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"
curl https://api.thunderphone.com/v1/calls/{call_id}/audio \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"
```

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="関数ツールを追加する" icon="screwdriver-wrench" href="/ja/tools/overview">
    会話中にエージェントから API を呼び出せるようにします。
  </Card>

  <Card title="発信する" icon="arrow-up-right" href="/api-reference/outbound-calls">
    独自のコードから通話をトリガーします。
  </Card>

  <Card title="Webhook を処理する" icon="bolt" href="/ja/webhooks/overview">
    通話イベントにリアルタイムで対応します。
  </Card>

  <Card title="API リファレンス全文" icon="book" href="/api-reference/introduction">
    すべての公開エンドポイントを文書化しています。
  </Card>
</CardGroup>
