接口
POST
https://api.404wl.com/v1/ocr
请求参数
| 字段 | 类型 | 说明 |
|---|---|---|
file |
file |
必填。支持 JPEG、PNG、WEBP、BMP、TIFF,单文件最大 10 MiB。 |
调用示例
cURL
curl --request POST 'https://api.404wl.com/v1/ocr' \
--header 'Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--form 'file=@./example.png'
JavaScript
const form = new FormData();
form.append('file', file);
const response = await fetch('https://api.404wl.com/v1/ocr', {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
},
body: form,
});
const result = await response.json();
PHP
$handle = curl_init('https://api.404wl.com/v1/ocr');
curl_setopt_array($handle, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile(__DIR__.'/example.png'),
],
CURLOPT_RETURNTRANSFER => true,
]);
$result = curl_exec($handle);
curl_close($handle);
响应格式
成功响应的 items 会列出每个识别到的文字区域,box 是原图尺寸上的四点坐标。
{
"success": true,
"request_id": "provider-request-id",
"data": {
"text": "你好",
"items": [
{
"text": "你好",
"score": 0.99,
"box": [[1, 2], [30, 2], [30, 20], [1, 20]]
}
],
"image": {
"width": 1280,
"height": 720
}
},
"error": null
}
错误码
通用错误见 错误格式。本接口还可能返回:
| HTTP | code | 说明 |
|---|---|---|
415 |
UNSUPPORTED_IMAGE |
文件不是受支持的图片格式。 |
422 |
INVALID_REQUEST |
缺少文件或请求参数无效。 |
502 |
PROVIDER_ERRORINVALID_PROVIDER_RESPONSE |
OCR 服务内部错误,请稍后重试。 |
503 |
PROVIDER_UNAVAILABLE |
OCR 服务暂时不可用,请稍后重试。 |