提交图片转文字任务
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v3/text/img2txt/async
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization(用户授权) | string | 是 | 客户授权Token |
Content-Type(传递内容) | string | 是 | 使用json传参 |
X-accept-language | string | 否 | 语言偏好,支持['en', 'zh'],en:英文,zh:中文,默认为"zh" |
API-User-ID | string | 否 | 用户唯一标识 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | string | 是 | 待翻译成文字的图片,支持传入图片的base64值/URL地址 |
lang | string | 否 | 生成的文字语言,默认为"en",可选范围为zh |
version | string | 否 | 模型版本,默认为"v1",可选范围为{"v1"} |
notify_url | string | 否 | 任务完成回调通知接口(需公网能访问),请求参数与task result 一致 |
request_id | string | 否 | 请求的ID,默认为"" |
说明:
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"image": "https://storage-cdn.hidreamai.com/image/p_012a65cc-3a95-11ef-859f-f295bfc5fd51_wm.png",
"lang": "zh",
"version": "v1",
}' \
-v 'https://www.hidreamai.com/api-pub/gw/v3/text/img2txt/async'
Python示例
import requests
import json
import uuid
USER_Authorization = <token>
# 请求头
headers = {
'Authorization': f'Bearer {USER_Authorization}',
'Content-Type': 'application/json',
'API-User-ID': '' # 可选的用户唯一标识
}
# 请求体参数
data = {
"image": "https://storage-cdn.hidreamai.com/image/p_012a65cc-3a95-11ef-859f-f295bfc5fd51_wm.png",
"lang": "zh",
"version": "v1",
}
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/text/img2txt/async'
response = requests.post(url, headers=headers, data=json.dumps(data))
# 处理响应
if response.status_code == 200:
if response.json()['code'] == 0:
task_id = response.json()['result']['task_id']
print(task_id)
else:
print(response.json()['message'])
else:
print(response.status_code)
4. 返回参数
参数 | 类型 | 说明 |
---|---|---|
code | int | 返回状态码 |
message | string | 返回状态信息 |
request_id | string | 本次请求的ID |
result | dict | 返回结果 |
其中返回结果 result字段具体为:
参数 | 类型 | 说明 |
---|---|---|
task_id | string | 返回任务ID |
sub_task_ids | list | 返回子任务ID的列表,子任务定义为生成单张图片的任务 |
示例:
{
"code":0,
"message":"Success",
"request_id":"ccfc092e-8430-11ee-97ff-f60f825045d5",
"result":{
"sub_task_ids": [
"2fa58fbb-18d5-445c-bb49-fea88479b06a"
],
"task_id": "9af30d22-3aa3-11ef-b9c0-a28d6ca60ecd"
}
}