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

> 透過四次 REST 呼叫，讓 AI 語音智慧體接聽你的第一通來電。

本指南將帶你完成四個 REST 呼叫，讓 AI 語音智慧體接聽你的第一通電話。

<Info>
  你需要一個 [ThunderPhone 帳戶](https://app.thunderphone.com)。
  註冊免費，不到一分鐘即可完成。偏好點擊操作而非使用 curl？
  [控制台快速入門](/zh-Hant/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 金鑰](/zh-Hant/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 概覽](/zh-Hant/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="/zh-Hant/tools/overview">
    讓你的智慧體在通話期間呼叫你的 API。
  </Card>

  <Card title="撥打外撥電話" icon="arrow-up-right" href="/api-reference/outbound-calls">
    從自己的程式碼觸發通話。
  </Card>

  <Card title="處理 Webhook" icon="bolt" href="/zh-Hant/webhooks/overview">
    即時回應通話事件。
  </Card>

  <Card title="完整 API 參考文件" icon="book" href="/api-reference/introduction">
    記錄所有公開端點。
  </Card>
</CardGroup>
