REST · CLI · OpenAPI

SingleFax API 文件與 CLI

API 金鑰搭配預付餘額。可使用 npm 官方 CLI,或直接採用 curl、Node、Python、Go、PHP 的 REST 範例。聊天應用程式請改用 MCP。

CLI

npx @singlefax/cli send FILE --to +E164,請傳原始 Word、Excel、PDF 或圖片,不要先轉 PDF。

REST

POST /api/v1/faxes,搭配 Bearer sf_live_… 及 Idempotency-Key。

聊天 MCP

Cursor、Claude、Codex、ChatGPT。使用 OAuth,不是 API 金鑰。安裝 MCP。

快速開始

  1. 於 API 金鑰 建立限定權限金鑰(fax:send、fax:read、inbox:read、credits:read)。
  2. 在控制台預付儲值,或使用 npx @singlefax/cli credits buy。
  3. 使用下方 CLI 或 POST /api/v1/faxes 傳送。

基底 URL:https://api.singlefax.com(https://singlefax.com 使用相同路徑)。sf_test_ 金鑰無法正式傳送。勿將金鑰放入瀏覽器。

CLI

Node 20+。設定:SINGLEFAX_API_KEY 或 ~/.config/singlefax/config.json。傳入原始檔(Word、Excel、PowerPoint、PDF、文字或圖片),不要先轉 PDF。不適用 MCP OAuth 或 Stripe MPP。

terminal
export SINGLEFAX_API_KEY=sf_live_…

npx @singlefax/cli send ./document.docx --to +14155552671
npx @singlefax/cli send ./document.pdf --to +14155552671 --wait --json
quote, status, credits
npx @singlefax/cli quote --to +14155552671 --pages 12
npx @singlefax/cli status <id>
npx @singlefax/cli list
npx @singlefax/cli numbers
npx @singlefax/cli numbers buy
npx @singlefax/cli credits
npx @singlefax/cli credits buy --dollars 20

傳送傳真

一次請求:base64 文件加目的地。支援 PDF、Word、Excel、PowerPoint、文字或圖片,必須提供 Idempotency-Key。相同金鑰配不同主體會回傳 409。

terminal
PDF_B64="$(base64 < document.pdf | tr -d '\n')"

curl -sS https://api.singlefax.com/api/v1/faxes \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "{\"to\":\"+14155552671\",\"base64\":\"$PDF_B64\"}"

大型檔案:先上傳再傳送

CLI 會建立上傳權杖、以 PUT 上傳位元組,再用 uploadToken 傳送。PUT 也須 Bearer 權杖。大型檔案宜用此方式,不要塞進 JSON。不要先轉 PDF。

terminal
UPLOAD=$(curl -sS https://api.singlefax.com/api/v1/uploads \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contentType":"application/pdf"}')

UPLOAD_URL=$(printf '%s' "$UPLOAD" | python3 -c "import json,sys; print(json.load(sys.stdin)['uploadUrl'])")
TOKEN=$(printf '%s' "$UPLOAD" | python3 -c "import json,sys; print(json.load(sys.stdin)['uploadToken'])")

curl -sS -X PUT "$UPLOAD_URL" \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/pdf" \
  --data-binary @document.pdf

curl -sS https://api.singlefax.com/api/v1/faxes \
  -H "Authorization: Bearer $SINGLEFAX_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d "{\"to\":\"+14155552671\",\"uploadToken\":\"$TOKEN\"}"

REST 參考文件

方法路徑驗證備註
POST/api/v1/faxesfax:sendIdempotency-Key required. JSON { to, base64 | uploadToken } or multipart file.
GET/api/v1/faxesfax:readList. Query limit, offset.
GET/api/v1/faxes/{id}fax:readStatus including latest delivery attempt.
POST/api/v1/faxes/quotefax:read{ to, pages? | base64? }, quote without charging.
POST/api/v1/uploadsfax:sendReturns uploadToken + uploadUrl. PUT the bytes, then send with uploadToken.
GET/api/v1/creditscredits:readPrepaid balance.
POST/api/v1/credits/checkoutcredits:checkout{ amountCents }. Stripe Checkout for a credit pack.
GET/api/v1/received-faxesinbox:readInbound inbox list. Query limit, cursor. No transcripts in list.
GET/api/v1/received-faxes/{id}inbox:readInbound detail with bounded transcript slice. HIPAA Secure content is omitted.
GET/api/v1/numbersfax:readActive fax numbers.
POST/api/v1/numberscredits:checkout{ sku?, country?, state? }, default inbound_30day. Returns checkoutUrl + reserved phoneNumber.
GET/api/v1/skuspublicCatalog. Same shape as MCP list_skus.
POST/api/v1/checkoutcredits:checkout{ sku }, credit_pack, inbound, subscriptions, lifetime.

完整結構:openapi.json。不相容變更:版本政策(90 天 Sunset 期)。此額度 API 的 HTTP 402 是餘額不足,MPP 402 僅適用 POST /api/v1/machine/faxes。

Webhook

已簽章的 fax.queued、fax.delivered、fax.failed、credits.low_balance 事件。請針對原始主體驗證 SingleFax-Signature(t=,v1=),採 timestamp.payload 的 HMAC-SHA256。於 控制台 Webhook 新增端點。

verify.mjs
import { createHmac, timingSafeEqual } from 'node:crypto'

export function verifySingleFaxSignature(rawBody, signatureHeader, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(signatureHeader.split(',').map((kv) => kv.split('=')))
  const timestamp = Number(parts.t)
  if (!Number.isFinite(timestamp) || !parts.v1) return false
  if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > toleranceSeconds) return false
  const expected = createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex')
  const a = Buffer.from(parts.v1)
  const b = Buffer.from(expected)
  return a.length === b.length && timingSafeEqual(a, b)
}

限制

  • API 金鑰保留在伺服器,不要在網頁嵌入 sf_live_。
  • 勿傳 PHI。適用機構使用網站 HIPAA Secure 模式及電子 BAA。
  • 目的地須為有效 E.164。支援 PDF、Word、Excel、PowerPoint、RTF、純文字與圖片,MIME 類型見 OpenAPI。不要先轉 PDF,傳送前由我們轉換。
  • 聊天 MCP 與 Stripe MPP:/agents、mpp.md、MPP 與 Instant Checkout 比較。

常見問題

機器可讀文件

提供爬蟲與程式代理使用的純 Markdown 及 OpenAPI,內容事實與本頁相同。