智能作业批改
更新时间:2025-12-05
接口描述
基于多模态大模型能力,实现K12阶段的全学科作业、试卷批改。支持用户拍照或上传图片,可输出对应每道题的批改结果;支持输出数学和理综学科的解析;支持结果原图渲染,图片清晰展示题目区域和对错标识,便于快速定位问题提升批改效率。
智能作业批改API服务为异步接口,需要先调用提交请求接口获取 task_id ,然后调用获取结果接口进行结果轮询,建议提交请求后 5~10 秒轮询。提交请求接口QPS为2,获取结果接口QPS为2。
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
提交请求接口
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task
URL参数:
| 参数 | 值 |
|---|---|
| access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
| 参数 | 值 |
|---|---|
| Content-Type | application/json |
Body中放置请求参数,参数详情如下:
请求参数
| 参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
|---|---|---|---|---|
| image | 和 url 二选一 | string | - | 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过10M,最短边至少512px,最长边最大8192px,支持jpg/jpeg/png/bmp格式优先级: image > url ,当image字段存在时,url字段失效 |
| url | 和 image 二选一 | string | - | 图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过10M,最短边至少512px,最长边最大8192px,支持jpg/jpeg/png/bmp格式优先级: image > url ,当image字段存在时,url字段失效请注意关闭URL防盗链 |
请求代码示例
提示:使用示例代码前,请记得替换其中的示例Token、文档地址或Base64信息。
1curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task?access_token=【调用鉴权接口获取的token】'
2 -H 'Content-Type: application/json'
3--data '{
4 "url": "https://data.wylkyj.com/AnswerSheet/168512/168512003英语/7091/7091243416A.png?x-oss-process=image/crop,x_84,y_1543,w_1505,h_673"
5}'
1# encoding:utf-8
2
3import requests
4import base64
5
6'''
7智能作业批改提交请求
8'''
9
10request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task"
11# 二进制方式打开图片文件
12f = open('[本地文件]', 'rb')
13img = base64.b64encode(f.read()).decode('utf-8')
14
15params = json.dumps({
16 "image": img
17})
18
19access_token = '[调用鉴权接口获取的token]'
20request_url = request_url + "?access_token=" + access_token
21headers = {'content-type': 'application/json'}
22response = requests.post(request_url, data=params, headers=headers)
23if response:
24 print (response.json())
1package com.baidu.ai.aip;
2
3import com.baidu.ai.aip.utils.Base64Util;
4import com.baidu.ai.aip.utils.FileUtil;
5import com.baidu.ai.aip.utils.HttpUtil;
6import com.google.gson.Gson;
7import java.util.HashMap;
8import java.util.Map;
9
10/**
11* 智能作业批改提交请求
12*/
13~~public class CorrectEduCreateTask~~{
14
15 /**
16 * 重要提示代码中所需工具类
17 * FileUtil,Base64Util,HttpUtil,GsonUtils请从
18 * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
19 * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
20 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
21 * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
22 * 下载
23 */
24 public static String correctEduCreateTask() {
25 // 请求url
26 String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task";
27 try {
28 // 本地文件路径
29 String filePath = "[本地文件路径]";
30 byte[] imgData = FileUtil.readFileByBytes(filePath);
31 String imgStr = Base64Util.encode(imgData);
32
33 // 构造请求体
34 Map<String, Object> map = new HashMap<>();
35 map.put("image", imgStr); // 或者使用 url 参数
36 String param = new Gson().toJson(map);
37
38 // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
39 String accessToken = "[调用鉴权接口获取的token]";
40
41 String result = HttpUtil.post(url, accessToken, "application/json", param);
42 System.out.println(result);
43 return result;
44 } catch (Exception e) {
45 e.printStackTrace();
46 }
47 return null;
48 }
49
50 public static void main(String[] args) {
51 ~~CorrectEduCreateTask.correctEduCreateTask()~~;
52 }
53}
返回说明
返回参数
| 字段 | 类型 | 说明 |
|---|---|---|
| log_id | uint64 | 唯一的log id,用于问题定位 |
| error_code | int | 错误码 |
| error_msg | string | 错误描述信息 |
| result | dict | 返回的结果列表 |
| + task_id | string | 该请求生成的任务ID,后续使用该task_id获取批改结果 |
返回示例
成功返回示例:
JSON
1{
2 "error_code": "0",
3 "error_msg": "",
4 "result": {
5 "task_id": "1996199501805445169"
6 },
7 "log_id": 1996199501805445169
8}
失败返回示例(详细的错误码说明见API文档-错误码):
JSON
1{
2 "log_id": 1965746008642488944,
3 "error_msg": "image format error",
4 "error_code": 216201
5}
获取结果接口
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edun/get_result
URL参数:
| 参数 | 值 |
|---|---|
| access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
| 参数 | 值 |
|---|---|
| Content-Type | application/json |
Body中放置请求参数,参数详情如下:
请求参数
| 参数 | 是否必选 | 类型 | 说明 |
|---|---|---|---|
| task_id | 是 | string | 发送提交请求时返回的task_id |
请求代码示例
提示:使用示例代码前,请记得替换其中的示例Token、task_id。
1curl --location 'https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result?access_token=【调用鉴权接口获取的token】' \
2--header 'Content-Type: application/json' \
3--data '{
4 "task_id": "1996150096223473645"
5}'
1# encoding:utf-8
2
3import requests
4import base64
5'''
6智能作业批改获取请求
7'''
8
9request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result"
10
11
12params = json.dumps({
13 "task_id": "1996150096223473645"
14})
15access_token = '[调用鉴权接口获取的token]'
16request_url = request_url + "?access_token=" + access_token
17headers = {'content-type': 'application/json'}
18response = requests.post(request_url, data=params, headers=headers)
19if response:
20 print (response.json())
1package com.baidu.ai.aip;
2
3import com.baidu.ai.aip.utils.HttpUtil;
4import com.google.gson.Gson;
5
6import java.util.HashMap;
7import java.util.Map;
8
9/**
10* 智能作业批改获取请求
11*/
12public class CorrectEduGetResult {
13
14 /**
15 * 重要提示代码中所需工具类
16 * HttpUtil,GsonUtils请从
17 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
18 * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
19 * 下载
20 */
21 public static String correctEduGetResult() {
22 // 请求url
23 String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result";
24 try {
25 // task_id 来自提交请求的返回结果
26 Map<String, Object> map = new HashMap<>();
27 map.put("task_id", "1996150096223473645");
28 String param = new Gson().toJson(map);
29
30 String accessToken = "[调用鉴权接口获取的token]";
31
32 String result = HttpUtil.post(url, accessToken, "application/json", param);
33 System.out.println(result);
34 return result;
35 } catch (Exception e) {
36 e.printStackTrace();
37 }
38 return null;
39 }
40
41 public static void main(String[] args) {
42 CorrectEduGetResult.correctEduGetResult();
43 }
44}
45
46
47#include <iostream>
48#include <curl/curl.h>
49#include <string>
50
51const static std::string get_request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting_composition/get_result";
52static std::string get_result_str;
53
54/**
55 * curl发送http请求调用的回调函数
56 */
57static size_t get_callback(void *ptr, size_t size, size_t nmemb, void *stream) {
58 get_result_str = std::string((char *) ptr, size * nmemb);
59 return size * nmemb;
60}
61
62/**
63 * 智能作业批改 - 获取任务结果
64 * @return 调用成功返回0,发生错误返回其他错误码
65 */
66int handwriting_composition_get_result(std::string &json_result, const std::string &access_token, const std::string &task_id) {
67 std::string url = get_request_url + "?access_token=" + access_token;
68
69 CURL *curl = NULL;
70 CURLcode result_code;
71 int is_success;
72
73 // 构造JSON请求体
74 std::string json_body = "{\"task_id\":\"" + task_id + "\"}";
75
76 curl = curl_easy_init();
77 if (curl) {
78 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
79 curl_easy_setopt(curl, CURLOPT_POST, 1L);
80
81 // 设置请求头 Content-Type: application/json
82 struct curl_slist *headers = NULL;
83 headers = curl_slist_append(headers, "Content-Type: application/json");
84 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
85
86 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_body.c_str());
87
88 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_callback);
89 result_code = curl_easy_perform(curl);
90
91 if (result_code != CURLE_OK) {
92 fprintf(stderr, "curl_easy_perform() failed: %s\n",
93 curl_easy_strerror(result_code));
94 is_success = 1;
95 } else {
96 json_result = get_result_str;
97 is_success = 0;
98 }
99
100 curl_slist_free_all(headers);
101 curl_easy_cleanup(curl);
102 } else {
103 fprintf(stderr, "curl_easy_init() failed.\n");
104 is_success = 1;
105 }
106 return is_success;
107}
返回说明
返回参数
| 字段 | 类型 | 说明 |
|---|---|---|
| log_id | uint64 | 唯一的log id,用于问题定位 |
| error_code | int | 错误码 |
| error_msg | string | 错误描述信息 |
| task_id | string | 任务ID |
| imageResults | array[] | 图片批改结果 |
| + imageId | string | 图片id |
| + imageUrl | string | 作业图片url |
| + paperSubject | string | 卷面学科,"chinese"语文;"math"数学;"english"英语;"physics"物理";chemistry"化学;"biology"生物;"history"历史;"geography"地理;"politics"政治 |
| + result | array[] | 批改结果 |
| ++ correctResult | int | 批改结果,0:未批;1:正确;2:错误;3:未作答 |
| ++ questionId | string | 题目ID |
| ++ question | string | 题目内容 |
| ++ questionArea | array[] | 题目坐标,left_x:左上角X坐标;left_y:左上角Y坐标;right_x:右下角X坐标;right_y:右下角Y坐标 |
| ++ isFinish | bool | 是否完成批改 -true:批改完成 -false:批改未完成 |
| ++ seqence | int | 题目序号,0:题目1;1:题目2;依此类推 |
| ++ type | int | 题目类型,0:默认;1:口算题;2:选择题;3:判断题;4:填空题;5:应用题;6:连线题;7:画画题;8:题干;9:其他;10:材料;11:圈选题;17:计算题;18:证明题;19:解答题;401:描述题;402:排序题;801:图表题;902:带过程填空 |
| ++ cropUrl | string | 批改后的题目图片url |
| ++ slot | array[] | 作答区信息 |
| +++ slotId | string | 作答区ID |
| +++ seqence | int | 作答区序号,1:作答区1;2:作答区2;依此类推 |
| +++ handwritingArea | string | 作答区坐标,left_x:左上角X坐标;left_y:左上角Y坐标;right_x:右下角X坐标;right_y:右下角Y坐标 |
| +++ correctResult | int | 作答区批改结果,0:未批,1:正确,2:错误,3:未作答 |
| +++ reason | string | 批改原因描述 |
| isAllFinished | bool | 是否完成批改 -true:批改完成 -false:批改未完成 |
| stat_result | object | 批改统计信息 |
| + all | int | 整体数量 |
| + corrected | int | 已批改总数 |
| + correcting | int | 批改中数量 |
返回示例
成功返回示例:
JSON
1{
2 "error_code": "0",
3 "error_msg": "",
4 "task_id": "1996199501805445169",
5 "imageResults": [
6 {
7 "result": [
8 {
9 "correctResult": 1,
10 "questionId": "e3dd5315e1726899f6e5b96dc68e399401",
11 "question": "",
12 "seqence": 0,
13 "questionArea": [
14 {
15 "right_y": 542,
16 "left_x": 56,
17 "right_x": 1378,
18 "left_y": 47
19 }
20 ],
21 "isFinish": true,
22 "slot": [
23 {
24 "correctResult": 1,
25 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: studied] 可见英文单词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
26 "handwritingArea": {
27 "right_y": 211,
28 "left_x": 312,
29 "right_x": 488,
30 "left_y": 129
31 },
32 "seqence": 1,
33 "slotId": "e3dd5315e1726899f6e5b96dc68e399400"
34 },
35 {
36 "correctResult": 1,
37 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: to publish] 可见英文不定式结构作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
38 "handwritingArea": {
39 "right_y": 223,
40 "left_x": 669,
41 "right_x": 905,
42 "left_y": 132
43 },
44 "seqence": 2,
45 "slotId": "e3dd5315e1726899f6e5b96dc68e399401"
46 },
47 {
48 "correctResult": 1,
49 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: for to] 可见英文短语作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
50 "handwritingArea": {
51 "right_y": 227,
52 "left_x": 1032,
53 "right_x": 1224,
54 "left_y": 145
55 },
56 "seqence": 3,
57 "slotId": "e3dd5315e1726899f6e5b96dc68e399402"
58 },
59 {
60 "correctResult": 1,
61 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: a] 可见英文冠词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
62 "handwritingArea": {
63 "right_y": 318,
64 "left_x": 332,
65 "right_x": 402,
66 "left_y": 257
67 },
68 "seqence": 4,
69 "slotId": "e3dd5315e1726899f6e5b96dc68e399403"
70 },
71 {
72 "correctResult": 1,
73 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: equally] 可见英文副词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
74 "handwritingArea": {
75 "right_y": 327,
76 "left_x": 691,
77 "right_x": 879,
78 "left_y": 234
79 },
80 "seqence": 5,
81 "slotId": "e3dd5315e1726899f6e5b96dc68e399404"
82 },
83 {
84 "correctResult": 1,
85 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: for] 可见英文介词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
86 "handwritingArea": {
87 "right_y": 336,
88 "left_x": 1036,
89 "right_x": 1151,
90 "left_y": 257
91 },
92 "seqence": 6,
93 "slotId": "e3dd5315e1726899f6e5b96dc68e399405"
94 },
95 {
96 "correctResult": 1,
97 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: cluing] 可见英文动名词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
98 "handwritingArea": {
99 "right_y": 439,
100 "left_x": 355,
101 "right_x": 500,
102 "left_y": 353
103 },
104 "seqence": 7,
105 "slotId": "e3dd5315e1726899f6e5b96dc68e399406"
106 },
107 {
108 "correctResult": 1,
109 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: that] 可见英文连词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
110 "handwritingArea": {
111 "right_y": 384,
112 "left_x": 790,
113 "right_x": 910,
114 "left_y": 326
115 },
116 "seqence": 8,
117 "slotId": "e3dd5315e1726899f6e5b96dc68e399407"
118 },
119 {
120 "correctResult": 1,
121 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: Far to] 可见英文短语作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
122 "handwritingArea": {
123 "right_y": 437,
124 "left_x": 1051,
125 "right_x": 1236,
126 "left_y": 354
127 },
128 "seqence": 9,
129 "slotId": "e3dd5315e1726899f6e5b96dc68e399408"
130 },
131 {
132 "correctResult": 1,
133 "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: helpful] 可见英文形容词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
134 "handwritingArea": {
135 "right_y": 542,
136 "left_x": 323,
137 "right_x": 501,
138 "left_y": 445
139 },
140 "seqence": 10,
141 "slotId": "e3dd5315e1726899f6e5b96dc68e399409"
142 }
143 ],
144 "type": 4,
145 "cropUrl": "http://tv-mis.bj.bcebos.com//correct_evaluate_data/e3dd5315e1726899f6e5b96dc68e399401/1996199501805445169/e3dd5315e1726899f6e5b96dc68e399401/5536d4e6-209f-49f6-ba9d-b96e2f2ce5f1.png?authorization=bce-auth-v1%2FALTAK5AGAcpDzr9LsTXvf4PbuU%2F2025-12-03T12%3A47%3A06Z%2F86400%2Fhost%2Fc38bfc775d7f3af84bd6f17740cf5b1aa3b10ccc1a66a7f8c8e485851ac876fe"
146 }
147 ],
148 "imageId": "e3dd5315e1726899f6e5b96dc68e3994",
149 "imageUrl": "http://tv-mis.bj.bcebos.com//correct_evaluate_data/fb65b14b0e8c3f1208fce7f82ec35943/1996199501805445169/fb65b14b0e8c3f1208fce7f82ec35943/1c43a203-35f9-4786-957b-e2a5eb1f7f79.png?authorization=bce-auth-v1%2FALTAK5AGAcpDzr9LsTXvf4PbuU%2F2025-12-03T12%3A47%3A05Z%2F86400%2Fhost%2F773ddd933dc54043d6fc5d61230646d02999652c33b2f96b7c98dc3d8f72e3f8",
150 "paperSubject": "english"
151 }
152 ],
153 "isAllFinished": true,
154 "stat_result": {
155 "all": 1,
156 "correcting": 0,
157 "corrected": 1
158 },
159 "log_id": 1996199590923431818
160}
失败返回示例(详细的错误码说明见API文档-错误码):
JSON
1{
2 "log_id": 1965712846932687146,
3 "error_msg": "recognize error",
4 "error_code": 216630
5}
