Text Correction
This API performs spelling correction and light rewriting on text in search and recommendation scenarios. Common uses include normalizing non-standard search queries from buyers and fixing obvious spelling errors in machine-translated results. This API supports 14 languages and is a synchronous API.
Use cases
This API acts as a pre-processor within search and recommendation pipelines. It is not a general-purpose grammar or style checker. It specializes in the following scenarios:
Search query normalization: Corrects user inputs like
"Hellw World"to"Hello World"to improve recall.Post-translation processing: Corrects spelling mistakes in the output of a Text Translation call.
UGC cleaning: Corrects user-generated content, such as product titles or reviews, before indexing to prevent dirty data from polluting the index.
To identify the input language, call the Language Detection API or set the SourceLanguage parameter to auto. Auto-detection is limited to the 14 supported languages.
API
POST /ai/text/correctionQuick start
import json
data = json.dumps({
"SourceText": "Hellw World",
"SourceLanguage": "en"
})
result = make_signed_request("/ai/text/correction", data)
print(result["Data"]["CorrectedText"]) # "Hello World"For complete instructions on request signing, SDK examples for Java, Python, Go, and other languages, and online debugging, see the Text Correction API (OpenAPI Portal) on the Alibaba Cloud OpenAPI Developer Portal.
Request parameters
Parameter | Type | Required | Description |
| String | Yes | The source text to correct. |
| String | Yes | The source language. The value must be one of the 14 supported language codes. You can also set this to |
Response fields
Field | Type | Description |
| String | The status code. A value of |
| Boolean | Indicates whether the API call was successful. |
| String | The request ID. |
| String | The error message (returned only when the call fails). |
| String | The corrected text. If no errors are found, the original text is returned. |
| Number | The number of characters in the input for this request. This value is used for billing. |
Full example
Request example
{
"SourceText": "Hellw World",
"SourceLanguage": "en"
}Response example
{
"Code": "Success",
"Message": "Success",
"Success": true,
"RequestId": "2157065A-D6C8-1F3E-A4D0-B1234567890",
"Data": {
"CorrectedText": "Hello World",
"UsageMap": { "InputCharacterCount": 11 }
}
}Supported languages (14)
Text Correction supports 14 languages. For a complete list of languages and their codes, see the "Text Correction supported language directions (14)" section in Language Direction Mapping.
Recommendations
Use only in search and recommendation pipelines: This API is designed for search and recommendation scenarios and is not suitable for correcting spelling in general documents, long-form text, or code snippets.
Check for changes: If
CorrectedText == SourceText, no correction was made, and you can skip downstream processing on the client.Handle unsupported languages: Text in languages other than the 14 supported ones will not be corrected. We recommend calling the Language Detection API first to determine whether to use this service.
Combine with translation: For best results, chain the APIs in the following order:
Language Detection → Text Correction → Text Translation. This three-step process can significantly improve the readability of machine-translated output.
Error codes
Error code | Trigger |
|
|
| The input text triggers content moderation. |
| The trial quota is exhausted. |
| An internal server error occurred. If this error persists, contact technical support with the |
For a complete list of error codes, see Error Codes.
Limitations
Call mode: Synchronous. For details on QPS and timeout limits, see our rate limit documentation.
Supported languages: 14 languages.
Billing: ¥18 per million characters, based on the
InputCharacterCount. For more details, see the billing documentation.
Next steps
Language Detection – Identify the language of your text before correction.
Text Translation – Translate your corrected text into other languages.