ReWords.AI API

快速入门

用三个 curl 请求完成第一张图片的文字替换:OCR 识别、提交编辑、获取结果。

你需要一个 API 密钥:先购买 API 套餐,然后在你的 API 密钥页面创建密钥(见身份验证)。 在终端里设置它:

export REWORDS_API_KEY=rw_live_your_key

1. 找到文字

curl https://api.rewords.ai/v1/ocr \
  -H "Authorization: Bearer $REWORDS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image_url": "https://example.com/banner.png", "language": "en"}'
{
  "image_id": "img_abc123",
  "width": 1080,
  "height": 1350,
  "texts": [
    { "id": "t1", "text": "SALE", "box": [120, 80, 300, 60] },
    { "id": "t2", "text": "50% OFF", "box": [140, 160, 260, 50] }
  ],
  "charged_ocr": 1
}

文字框的格式是 [x, y, 宽, 高],按图片的 0–1000 比例计算,所以和图片的像素尺寸无关。 image_id 在 24 小时内可以重复使用,不需要再次上传图片。 language 请设为图片中文字的语言,例如韩文用 ko、日文用 ja。我们不会自动判断语言, 不传时 OCR 只能准确识别中文和英文(见常见问题)。

2. 提交编辑

可以带上 OCR 结果里的 box,也可以只传 from 和 to,由我们帮你定位文字。

curl https://api.rewords.ai/v1/edits \
  -H "Authorization: Bearer $REWORDS_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "image_id": "img_abc123",
    "replacements": [
      { "from": "SALE", "to": "HOT DEAL", "box": [120, 80, 300, 60] },
      { "from": "50% OFF", "to": "70% OFF" }
    ]
  }'
{
  "id": "edit_9f8e7d",
  "status": "queued",
  "queue_position": 0,
  "estimated_seconds": 120,
  "replacements": [
    { "from": "SALE", "to": "HOT DEAL", "box": [120, 80, 300, 60] },
    { "from": "50% OFF", "to": "70% OFF", "box": [140, 160, 260, 50] }
  ],
  "balance": 4,
  "created_at": "2026-11-04T13:55:33.240Z"
}

replacements 里显示了我们为 50% OFF 找到的位置,并且 balance 中已经预留了一次编辑。 每个新任务都要用新的 Idempotency-Key,只有重发同一个任务时才用同一个。重复使用的 key 会返回之前的任务,而不是新的编辑。

3. 获取结果

一直轮询,直到 status 变成 succeeded 或 failed:任务处于 processing,或者处于 queued 且 queue_position 为 0 时,每 5 秒查一次; 排在队列更后面时,每 30 秒查一次,见队列与限制。也可以传入 callback_url,改为接收 Webhook。

curl https://api.rewords.ai/v1/edits/edit_9f8e7d \
  -H "Authorization: Bearer $REWORDS_API_KEY"
{
  "id": "edit_9f8e7d",
  "status": "succeeded",
  "results": {
    "A": { "status": "succeeded", "url": "https://img.rewords.ai/api/edit_9f8e7d_a.jpg" },
    "B": { "status": "succeeded", "url": "https://img.rewords.ai/api/edit_9f8e7d_b.jpg" },
    "C": { "status": "succeeded", "url": "https://img.rewords.ai/api/edit_9f8e7d_c.jpg" }
  },
  "replacements": [
    { "from": "SALE", "to": "HOT DEAL", "box": [120, 80, 300, 60] },
    { "from": "50% OFF", "to": "70% OFF", "box": [140, 160, 260, 50] }
  ],
  "charged": 1,
  "balance": 4,
  "created_at": "2026-11-04T13:55:33.240Z",
  "completed_at": "2026-11-04T13:56:21.808Z"
}

完整的 Node.js 和 Python 客户端以及其他所有响应,见示例。

请下载你需要的图片。结果是 JPEG 文件,公开链接至少保留 7 天。 A、B、C 分别是什么,见结果与退款;如何上传本地文件而不是 URL,见图片。

本页内容