资讯 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

智能作业批改

接口描述

基于多模态大模型能力,实现K12阶段的全学科作业、试卷批改。支持用户拍照或上传图片,可输出对应每道题的批改结果;支持输出数学和理综学科的解析;支持结果原图渲染,图片清晰展示题目区域和对错标识,便于快速定位问题提升批改效率。智能作业批改API服务提供以下两种调用方式:

端到端批改异步接口,需要先调用提交请求接口获取 task_id ,然后调用获取结果接口进行结果轮询,建议提交请求后 5~10 秒轮询。提交请求接口QPS为2,获取结果接口QPS为2,需将请求参数only_split设置为false

仅题目切分同步接口,提交后同步返回切题结果,需将请求参数only_split设置为true

在线调试

您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。

提交请求接口

请求说明

请求示例

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防盗链
only_split bool true/false 是否仅进行题目切分,默认不打开,即:false。可选值包括:
- true :开启;
- false:不开启
开启时按照同步接口进行返回,且仅扣除智能作业批改-题目切分的额度

请求代码示例

提示:使用示例代码前,请记得替换其中的示例Token、文档地址或Base64信息。

curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task?access_token=【调用鉴权接口获取的token】' 
 -H 'Content-Type: application/json'
--data '{
    "url": "https://ai.bdstatic.com/file/088749BAB26D4809B8A0B96FE100E7F0"
}'
# encoding:utf-8

import requests
import base64

'''
智能作业批改提交请求
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task"
# 二进制方式打开图片文件
f = open('[本地文件]', 'rb')
img = base64.b64encode(f.read()).decode('utf-8')

params = json.dumps({
  "image": img
})

access_token = '[调用鉴权接口获取的token]'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/json'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())
package com.baidu.ai.aip;

import com.baidu.ai.aip.utils.Base64Util;
import com.baidu.ai.aip.utils.FileUtil;
import com.baidu.ai.aip.utils.HttpUtil;
import com.google.gson.Gson;
import java.util.HashMap;
import java.util.Map;

/**
* 智能作业批改提交请求
*/
~~public class CorrectEduCreateTask~~{

    /**
    * 重要提示代码中所需工具类
    * FileUtil,Base64Util,HttpUtil,GsonUtils请从
    * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
    * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
    * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
    * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
    * 下载
    */
    public static String correctEduCreateTask() {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/create_task";
        try {
            // 本地文件路径
            String filePath = "[本地文件路径]";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);

            // 构造请求体
            Map<String, Object> map = new HashMap<>();
            map.put("image", imgStr); // 或者使用 url 参数
            String param = new Gson().toJson(map);

            // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
            String accessToken = "[调用鉴权接口获取的token]";

            String result = HttpUtil.post(url, accessToken, "application/json", param);
            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        ~~CorrectEduCreateTask.correctEduCreateTask()~~;
    }
}

返回说明

返回参数

字段 类型 说明
log_id uint64 唯一的log id,用于问题定位
error_code int 错误码
error_msg string 错误描述信息
result dict 返回的结果列表
+ task_id string 该请求生成的任务ID,后续使用该task_id获取批改结果

返回示例

成功返回示例:

{
    "error_code": "0",
    "error_msg": "",
    "result": {
        "task_id": "1996199501805445169"
    },
    "log_id": 1996199501805445169
}

失败返回示例(详细的错误码说明见API文档-错误码):

{
    "log_id": 1965746008642488944,
    "error_msg": "image format error",
    "error_code": 216201
}

获取结果接口

请求说明

请求示例

HTTP 方法:POST

请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/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。

curl --location 'https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result?access_token=【调用鉴权接口获取的token】' \
--header 'Content-Type: application/json' \
--data '{
    "task_id": "1996150096223473645"
}'
# encoding:utf-8

import requests
import base64
'''
智能作业批改获取请求
'''

request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result"


params = json.dumps({
  "task_id": "1996150096223473645"
})
access_token = '[调用鉴权接口获取的token]'
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/json'}
response = requests.post(request_url, data=params, headers=headers)
if response:
    print (response.json())
package com.baidu.ai.aip;

import com.baidu.ai.aip.utils.HttpUtil;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

/**
* 智能作业批改获取请求
*/
public class CorrectEduGetResult {

    /**
    * 重要提示代码中所需工具类
    * HttpUtil,GsonUtils请从
    * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
    * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
    * 下载
    */
    public static String correctEduGetResult() {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/correct_edu/get_result";
        try {
            // task_id 来自提交请求的返回结果
            Map<String, Object> map = new HashMap<>();
            map.put("task_id", "1996150096223473645");
            String param = new Gson().toJson(map);

            String accessToken = "[调用鉴权接口获取的token]";

            String result = HttpUtil.post(url, accessToken, "application/json", param);
            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        CorrectEduGetResult.correctEduGetResult();
    }
}


#include <iostream>
#include <curl/curl.h>
#include <string>

const static std::string get_request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting_composition/get_result";
static std::string get_result_str;

/**
 * curl发送http请求调用的回调函数
 */
static size_t get_callback(void *ptr, size_t size, size_t nmemb, void *stream) {
    get_result_str = std::string((char *) ptr, size * nmemb);
    return size * nmemb;
}

/**
 * 智能作业批改 - 获取任务结果
 * @return 调用成功返回0,发生错误返回其他错误码
 */
int handwriting_composition_get_result(std::string &json_result, const std::string &access_token, const std::string &task_id) {
    std::string url = get_request_url + "?access_token=" + access_token;

    CURL *curl = NULL;
    CURLcode result_code;
    int is_success;

    // 构造JSON请求体
    std::string json_body = "{\"task_id\":\"" + task_id + "\"}";

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_POST, 1L);

        // 设置请求头 Content-Type: application/json
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_body.c_str());

        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_callback);
        result_code = curl_easy_perform(curl);

        if (result_code != CURLE_OK) {
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(result_code));
            is_success = 1;
        } else {
            json_result = get_result_str;
            is_success = 0;
        }

        curl_slist_free_all(headers);
        curl_easy_cleanup(curl);
    } else {
        fprintf(stderr, "curl_easy_init() failed.\n");
        is_success = 1;
    }
    return is_success;
}

返回说明

返回参数

字段 类型 说明
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 批改中数量

返回示例

成功返回示例:

{
    "error_code": "0",
    "error_msg": "",
    "task_id": "1996199501805445169",
    "imageResults": [
        {
            "result": [
                {
                    "correctResult": 1,
                    "questionId": "e3dd5315e1726899f6e5b96dc68e399401",
                    "question": "",
                    "seqence": 0,
                    "questionArea": [
                        {
                            "right_y": 542,
                            "left_x": 56,
                            "right_x": 1378,
                            "left_y": 47
                        }
                    ],
                    "isFinish": true,
                    "slot": [
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: studied] 可见英文单词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 211,
                                "left_x": 312,
                                "right_x": 488,
                                "left_y": 129
                            },
                            "seqence": 1,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399400"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: to publish] 可见英文不定式结构作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 223,
                                "left_x": 669,
                                "right_x": 905,
                                "left_y": 132
                            },
                            "seqence": 2,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399401"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: for to] 可见英文短语作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 227,
                                "left_x": 1032,
                                "right_x": 1224,
                                "left_y": 145
                            },
                            "seqence": 3,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399402"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: a] 可见英文冠词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 318,
                                "left_x": 332,
                                "right_x": 402,
                                "left_y": 257
                            },
                            "seqence": 4,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399403"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: equally] 可见英文副词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 327,
                                "left_x": 691,
                                "right_x": 879,
                                "left_y": 234
                            },
                            "seqence": 5,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399404"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: for] 可见英文介词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 336,
                                "left_x": 1036,
                                "right_x": 1151,
                                "left_y": 257
                            },
                            "seqence": 6,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399405"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: cluing] 可见英文动名词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 439,
                                "left_x": 355,
                                "right_x": 500,
                                "left_y": 353
                            },
                            "seqence": 7,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399406"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: that] 可见英文连词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 384,
                                "left_x": 790,
                                "right_x": 910,
                                "left_y": 326
                            },
                            "seqence": 8,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399407"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: Far to] 可见英文短语作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 437,
                                "left_x": 1051,
                                "right_x": 1236,
                                "left_y": 354
                            },
                            "seqence": 9,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399408"
                        },
                        {
                            "correctResult": 1,
                            "reason": "[PRESENCE: YES][TYPE: FILL_BLANK][NORM: helpful] 可见英文形容词作答,存在有效笔迹,因无题干无法判断具体语法或语义要求,按从宽处理为正确",
                            "handwritingArea": {
                                "right_y": 542,
                                "left_x": 323,
                                "right_x": 501,
                                "left_y": 445
                            },
                            "seqence": 10,
                            "slotId": "e3dd5315e1726899f6e5b96dc68e399409"
                        }
                    ],
                    "type": 4,
                    "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"
                }
            ],
            "imageId": "e3dd5315e1726899f6e5b96dc68e3994",
            "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",
            "paperSubject": "english"
        }
    ],
    "isAllFinished": true,
    "stat_result": {
        "all": 1,
        "correcting": 0,
        "corrected": 1
    },
    "log_id": 1996199590923431818
}

失败返回示例(详细的错误码说明见API文档-错误码):

{
    "log_id": 1965712846932687146,
    "error_msg": "recognize error",
    "error_code": 216630
}
上一篇
英语答题卡识别(多模态)
下一篇
其他场景文字识别