UNLOCK API
图片转文字

图片转文字

如何通过 createTask 或 in.php 向 UNLOCK API 发送 图片转文字 任务:任务类型名称、全部参数、solution 对象、代理字段,以及 7 种语言的代码示例。
价格
$0.25 每个任务 $0.00025
你发送
base64 格式的图片,最大 100 KB
你得到
图片上的文字

简介和价格

任务类型名称

此类型只有一个名称。
ImageToTextTask

task 对象

type
String必填
任务类型名称。不区分大小写。 ImageToTextTask
body
String必填
base64 格式的图片(JPG、PNG 或 GIF),最大约 100 KB。可以带 data: 前缀。
phrase
Boolean可选
答案包含两个或更多单词时为 true。
case
Boolean可选
区分大小写时为 true。
numeric
Integer可选
0 任意字符,1 仅数字,2 仅字母,3 数字或字母,4 数字和字母。
math
Boolean可选
图片中是需要计算的算式时为 true。
minLength
Integer可选
答案最短长度。0 表示不限。
maxLength
Integer可选
答案最长长度。0 表示不限。
comment
String可选
给识别方的说明,例如图片上方显示的问题。
languagePool
String可选
答案的语言,例如 en 或 ru。

此处未列出的字段会原样传给识别方。

请求

POST /createTask
{
  "clientKey": "YOUR_API_KEY",
  "task": {
    "type": "ImageToTextTask",
    "body": "/9j/4AAQSkZJRgABAQ...",
    "case": true
  }
}

solution 对象

status 为 ready 时在 solution 中返回。
text
String
文本形式的答案。
POST /getTaskResult
{
  "errorId": 0,
  "taskId": 1001,
  "status": "ready",
  "solution": {
    "text": "w93bx"
  },
  "cost": "0.00025",
  "createTime": 1791640000,
  "endTime": 1791640014,
  "solveCount": 1
}

代码示例

import time, requests

API = "https://unlock-api.com"
KEY = "YOUR_API_KEY"

task = requests.post(f"{API}/createTask", json={
    "clientKey": KEY,
    "task": {
      "type": "ImageToTextTask",
      "body": "/9j/4AAQSkZJRgABAQ...",
      "case": true
    }
}).json()
if task["errorId"]:
    raise SystemExit(task["errorCode"])

for _ in range(60):   # 60 x 5 s = the 5 minute task limit
    time.sleep(5)
    r = requests.post(f"{API}/getTaskResult", json={"clientKey": KEY, "taskId": task["taskId"]}).json()
    if r["errorId"]:
        raise SystemExit(f"{r['errorCode']}: {r.get('errorDescription', '')}")   # failed tasks are refunded
    if r["status"] == "ready":
        print(r["solution"]["text"])
        break
else:
    raise SystemExit("timed out")

in.php 表单方法

用传统表单请求发送同一任务。res.php 以文本形式返回答案。
in.php, res.php
curl -s "https://unlock-api.com/in.php" -d "key=YOUR_API_KEY&method=base64&body=BASE64_IMAGE&json=1"
# {"status":1,"request":"1001"}

curl -s "https://unlock-api.com/res.php?key=YOUR_API_KEY&action=get&id=1001&json=1"
# {"status":0,"request":"CAPCHA_NOT_READY"}  then  {"status":1,"request":"ANSWER"}

表单 API:in.php 和 res.php