ThunderPhone 2.0 正式上线。全程自助,2 美分/分钟起。查看发布公告

Getting Started

快速入门(API)

通过 REST API 接听您的第一通由 AI 智能体处理的电话:获取 API 密钥、创建智能体、配置电话号码,并发起实时测试通话。

本指南将带您完成接听第一个由 AI 智能体处理的电话所需的四个 REST 调用。

第 1 步:获取 API 密钥

  1. 登录
  2. 前往密钥

    在控制台中前往 组织 → 密钥

  3. 创建密钥

    点击 创建密钥,为其命名,然后复制 sk_live_... 值。原始密钥仅显示一次——请立即将其存入您的密钥管理器。

在本指南中,请将 sk_live_YOUR_API_KEY 替换为您刚复制的值。该密钥会自动识别您的组织,因此您无需在 URL 中填写组织 ID。

第 2 步:创建智能体

智能体定义 AI 如何处理对话——提示词、语音、产品层级、工具以及小组件资格。

cURL
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
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"])
Node.js
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);

第 3 步:配置电话号码

此调用会向 ThunderPhone 的演示号码池请求一个号码,并将您的新智能体指定为入站处理程序。(如需从 VoIP 提供商接入您自己的号码,请参阅VoIP 连接。)

cURL
# 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
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"])

您的新号码初始状态为 status="provisioning",几秒钟内会变为 active;您关闭浏览器时,该号码通常已可接听来电。

第 4 步(可选):设置 webhook

如需接收实时事件(动态通话路由、通话后处理),请添加一个 webhook 端点。 仅订阅您需要的事件。

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 标头(请参阅 Webhooks 概览)。

第 5 步:测试您的智能体

拨打您刚刚配置的号码。智能体会接听、自我介绍,并遵循您的提示。

通话结束后检查通话:

curl https://api.thunderphone.com/v1/calls \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY"

查看特定通话的详细信息,以获取转录文本和录音 URL:

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"

后续步骤