开发者

SpeakNotes API 快速入门

创建密钥,在沙盒中进行首次调用,然后切换到正式环境。只需四个步骤,全部使用 curl 完成。

1. 创建密钥

打开“设置”中的“API 密钥”并创建一个。在开发过程中请选择沙盒模式:沙盒密钥返回固定输出,不消耗额度,且写入到可以随时丢弃的独立库中。

2. 在沙盒中进行摘要处理

每个路由都支持沙盒密钥。响应结构与正式环境完全一致,因此您可以放心地基于此进行开发。

curl -X POST https://api.speaknotes.io/v1/summaries \
  -H "Authorization: Bearer sn_test_YOUR_SANDBOX_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "We agreed to ship the billing fix on Friday. Sam owns the migration.",
    "styleId": "meeting-notes"
  }'

# {
#   "title": "Sandbox meeting notes",
#   "summary": "## Decisions\n- Sandbox mode confirmed working ...",
#   "styleId": "meeting-notes",
#   "creditsCharged": 0,
#   "notice": "Sandbox response: fixed output, no credits charged."
# }

3. 切换到正式密钥

相同的请求,不同的密钥。此密钥会运行真实模型并扣除额度,响应中会告知您已使用的额度以及剩余额度。

curl -X POST https://api.speaknotes.io/v1/summaries \
  -H "Authorization: Bearer sn_live_YOUR_LIVE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "...", "styleId": "meeting-notes"}'

# Response headers include:
#   X-Credits-Remaining: 1998
# Response body includes:
#   "creditsCharged": 2

4. 上传文件

较长的媒体文件会在后台运行。创建上传任务,将文件 PUT 到签名 URL,标记为完成,然后轮询笔记直到其状态变为 Done。

# 1. create the note and get a signed upload URL
curl -X POST https://api.speaknotes.io/v1/uploads \
  -H "Authorization: Bearer $SPEAKNOTES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fileName": "standup.m4a", "contentType": "audio/mp4", "styleId": "meeting-notes"}'

# 2. upload the file straight to the signed URL
curl -X PUT "$UPLOAD_URL" -H "Content-Type: audio/mp4" --data-binary @standup.m4a

# 3. tell SpeakNotes the upload finished (this is where credits are charged)
curl -X POST https://api.speaknotes.io/v1/uploads/$NOTE_ID/complete \
  -H "Authorization: Bearer $SPEAKNOTES_API_KEY"

# 4. poll until status is Done, then read the note
curl https://api.speaknotes.io/v1/notes/$NOTE_ID/status \
  -H "Authorization: Bearer $SPEAKNOTES_API_KEY"

curl https://api.speaknotes.io/v1/notes/$NOTE_ID \
  -H "Authorization: Bearer $SPEAKNOTES_API_KEY"

探索 API

GET /v1 不需要凭据,它会返回资源、作用域、速率限制、额度成本以及如何进行身份验证的信息。这是代理程序进行自我定位的最快方式。

curl https://api.speaknotes.io/v1

# Returns the resources, scopes, rate limits, credit costs,
# and how to authenticate. No credential required.

下一步:身份验证与作用域、错误代码以及每项操作的成本。